Visitar URL original
Designing lean operators · Issue #5382 · operator-framework/operator-sdk · GitHub
Skip to content

Designing lean operators #5382

Open
Open

Description

@fgiloux

What is the URL of the document?

https://sdk.operatorframework.io/docs/best-practices/common-recommendation/

Which section(s) is the issue in?

This is about adding a new section

What needs fixing?

One of the pitfalls that many operators are failing into is that they watch resources with high cardinality like secrets possibly in all namespaces. Besides the security aspect, which may be worth mentioning this has a massive impact on the memory used by the controller on big clusters. Such resources should either be filtered by label or possibly avoided by for instance using a custom resource instead.

Also it may be worth mentioning ResyncPeriod. Setting it to low would also cause the unnecessary consumption of CPU cycles.

Additional context

This is a follow up of: https://github.com/operator-framework/operator-sdk/pull/5353/files#r753112161

Activity

  1. jberkhahn commented on Nov 22, 2021

    @jberkhahn
    Contributor

    This sounds like a great idea to add to the best practices section in the docs. Would you be interested in contributing this?

  2. tlwu2013 commented on Nov 22, 2021

    @tlwu2013
    Contributor
  3. varshaprasad96 commented on Nov 29, 2021

    @varshaprasad96
    Member

    @fgiloux just wanted to follow up on this issue. Would you like to contribute on this, or have any suggestions/tips which we could add in the documentation.

  4. added this to the Backlog milestone on Nov 29, 2021
  5. added
    priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.
    on Nov 29, 2021
  6. fgiloux commented on Nov 29, 2021

    @fgiloux
    ContributorAuthor

    @varshaprasad96 yes I would like to contribute. I have however a couple of things higher on my priority list right now, so that I am also ok with another person taking the lead on the subject if someone happens to have more free cycles.
    For providing good guidance I would need to experiment, which requires time.

    The link shared by @tlwu2013 is really to the point.

  7. openshift-bot commented on Feb 27, 2022

    @openshift-bot

    Issues go stale after 90d of inactivity.

    Mark the issue as fresh by commenting /remove-lifecycle stale.
    Stale issues rot after an additional 30d of inactivity and eventually close.
    Exclude this issue from closing by commenting /lifecycle frozen.

    If this issue is safe to close now please do so with /close.

    /lifecycle stale

  8. added
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Feb 27, 2022
  9. openshift-bot commented on Mar 29, 2022

    @openshift-bot

    Stale issues rot after 30d of inactivity.

    Mark the issue as fresh by commenting /remove-lifecycle rotten.
    Rotten issues close after an additional 30d of inactivity.
    Exclude this issue from closing by commenting /lifecycle frozen.

    If this issue is safe to close now please do so with /close.

    /lifecycle rotten
    /remove-lifecycle stale

  10. added
    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.
    and removed
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Mar 29, 2022
  11. fgiloux commented on Mar 30, 2022

    @fgiloux
    ContributorAuthor

    /remove-lifecycle rotten

  12. camilamacedo86 commented on Mar 30, 2022

    @camilamacedo86
    Contributor

    /remove-lifecycle stale

  13. fgiloux commented on Mar 31, 2022

    @fgiloux
    ContributorAuthor

    /remove-lifecycle rotten

  14. 16 remaining items

  15. removed this from the v1.26.0 milestone on Oct 12, 2022
  16. varshaprasad96 commented on Oct 12, 2022

    @varshaprasad96
    Member

    Based on the discussion, the required task for this issue to include docs on how to filter caches using labels in controller-runtime. The original design doc is here: https://github.com/kubernetes-sigs/controller-runtime/blob/master/designs/use-selectors-at-cache.md

  17. added
    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
    and removed
    priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.
    on Oct 17, 2022
  18. added this to the Backlog milestone on Oct 17, 2022
  19. asmacdo commented on Oct 31, 2022

    @asmacdo
    Member

    This slide from Kubecon may be helpful

    image

  20. self-assigned this
    on Nov 2, 2022
  21. asmacdo commented on Nov 2, 2022

    @asmacdo
    Member

    I've taken this as assigned on behalf of @rocrisp who's not yet a member of the org.

  22. removed their assignment
    on Dec 20, 2022
  23. blkperl commented on Jan 20, 2023

    @blkperl

    Hey @rocrisp,

    We are experiencing high memory usage and are hoping that this guide helps resolve that. I've read https://sdk.operatorframework.io/docs/best-practices/designing-lean-operators/ and I'm bit unclear on a few points.

    My use case is an operator with multiple controllers for several Custom Resources (Environments and Sites) that are in multiple namespaces across the cluster.

    • Controller A is configured For(Environments) with Owns(Secrets) and Owns(ConfigMaps)
    • Controller B is configured For(Sites) with Owns(Secrets) and Owns(ConfigMaps)

    The guide says we can override the default cache with NewCache and the example shows &corev1.Secret{}

    • Does the new cache behave like the default cache but with an override for secrets or does it only cache secrets and the developer must add every resource the controller watches?
    • The Secrets and Configmaps mentioned in my example above have ownerReferences but it looks like only Labels and Fields are supported. Is the recommendation to add a label to all Secrets and Configmaps owned by the operator or is there a way to use the ownerReference with cache.SelectorsByObject?

    And thanks for the guide! It's very helpful ⭐

  24. rocrisp commented on Jan 20, 2023

    @rocrisp
    Contributor

    @blkperl Yes, the new cache behaves like the default cache but with an override for secrets per labels you create. The watch is in the controller code so not the same as the filter code in main.go when you setup a newManager.
    In essence, the controller and the filter filters are two different things. no?
    In theory, you should be able to add ownerRefence to the secret label.
    Thank you for your feedback on the doc and with your help we can update the doc to make it more clear.

  25. rocrisp commented on Jan 20, 2023

    @rocrisp
    Contributor

    @asmacdo Can you shed more light on the question above? Thank you.

  26. blkperl commented on Jan 20, 2023

    @blkperl

    I meant utilizing the existing ownerReference as a field rather than copying it to a label. It's tricky though because it doesn't seem queryable in golang.

    k get secret env-config -o json | jq '.metadata.ownerReferences[0].kind'
    "Environment"
    

    The approach that I think we might take is using labels.NewRequirement since we have an existing label with an internal id and we don't care about the value.

    	envIdReq, err := labels.NewRequirement("environment-id", selection.Exists, []string{})
    	if err != nil {
    		// handle error
    	}
    	envIdSelector := labels.NewSelector()
    	envIdSelector = envIdSelector.Add(*envIdReq)
    mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
            // other options ....
    	NewCache: cache.BuilderWithOptions(cache.Options{
    			SelectorsByObject: cache.SelectorsByObject{
    				&corev1.ConfigMap{}: {
    					Label: envIdSelector,
    				},
    			},
    	}),
    })
  27. asmacdo commented on Jan 21, 2023

    @asmacdo
    Member

    @blkperl this approach looks right to me.
    If it doesn't work come by the channel and someone will help.

    If it works, please consider adding anything to the docs that would have helped you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/documentationCategorizes issue or PR as related to documentation.lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions