Skip to content

Helm Operator missing ownerReferences for ClusterRole and ClusterRoleBinding #2727

Closed

Description

@mikeshng

Type of question

For Helm Operator install, why is the ownerReferences set properly for deployments and services but not for clusterrole and clusterrolebinding? Is this the expected behavior? If I wish to, how do I add the ownerReferences to those resources?

Question

What did you do?
I created a helm operator which deploys clusterrole and clusterrolebinding.

$ operator-sdk new nginx-ingress-operator \
    --api-version=example.com/v1alpha1 \
    --kind=NginxIngress \
    --type=helm \
	--helm-chart stable/nginx-ingress
$ cd nginx-ingress-operator/
$ kubectl apply -f deploy/crds/example.com_nginxingresses_crd.yaml 
$ kubectl apply -f deploy/crds/example.com_v1alpha1_nginxingress_cr.yaml 
$ operator-sdk run --local

What did you expect to see?
When I looked at the clusterrole, it doesn't have the ownerReferences

$ kubectl get clusterrole/example-nginxingress-nginx-ingress -o yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  creationTimestamp: "2020-03-26T19:48:02Z"
  labels:
    app: nginx-ingress
    chart: nginx-ingress-1.29.5
    heritage: Helm
    release: example-nginxingress
  name: example-nginxingress-nginx-ingress
  resourceVersion: "529"
  selfLink: /apis/rbac.authorization.k8s.io/v1/clusterroles/example-nginxingress-nginx-ingress
  uid: f0e53286-59d0-4eff-92c3-49af9325eeb7
rules:
- apiGroups:
  - ""

What did you see instead? Under which circumstances?
When I looked at deployment, I see the ownerReferences

$ kubectl get deployments/example-nginxingress-nginx-ingress-controller -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  ...
  ownerReferences:
  - apiVersion: example.com/v1alpha1
    blockOwnerDeletion: true
    controller: true
    kind: NginxIngress
    name: example-nginxingress
    uid: 6f4fd985-9f61-43db-a5b6-75de20bfec11
  resourceVersion: "708"
  selfLink: /apis/apps/v1/namespaces/default/deployments/example-nginxingress-nginx-ingress-controller
  uid: 053e56ba-0b95-4dac-bf66-1c615c5199ef

Environment

  • operator-sdk version:
$ operator-sdk version
operator-sdk version: "v0.16.0-dirty", commit: "55f1446c5f472e7d8e308dcdf36d0d7fc44fc4fd", go version: "go1.13.8 linux/amd64"
  • Kubernetes version information:
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.4", GitCommit:"224be7bdce5a9dd0c2fd0d46b83865648e2fe0ba", GitTreeState:"clean", BuildDate:"2020-01-14T01:25:43Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
  • Kubernetes cluster kind:
    KIND
$ kind version
kind v0.7.0 go1.13.6 linux/amd64

Additional context
Many thanks.

Activity

  1. joelanford commented on Mar 26, 2020

    @joelanford
    Member

    Kubernetes does not allow namespace-scoped resources to own cluster-scoped resources, so the helm operator has a check that prevents adding those invalid owner references.

    Is the lack of owner references on those cluster-scoped resources causing a problem?

  2. added
    language/helm
    triage/needs-information
    on Mar 26, 2020
  3. self-assigned this
    on Mar 26, 2020
  4. mikeshng commented on Mar 26, 2020

    @mikeshng
    ContributorAuthor

    Thanks Joe for the quick reply.

    In some cases, removing the finalizer then deleting the helm operator resource might leave behind some orphans like clusterrole because it doesn't have the ownerReferences so it doesn't get garbage collected.

    I guess this is the expected behavior. Manually removing the finalizer means some manual cleanup operations should be done afterwards.

    Thanks again, please feel free to close the issue if there is nothing that needs to be done here.

  5. joelanford commented on Mar 26, 2020

    @joelanford
    Member

    I guess this is the expected behavior. Manually removing the finalizer means some manual cleanup operations should be done afterwards.

    That's correct. From a cleanup perspective, the finalizer will ensure that all release resources are removed. Manually removing the finalizer effectively means that helm uninstall won't happen, and you are then relying on garbage collection.

    Right now, I'm pretty sure the release secret ALSO does not have an owner reference, so that would be orphaned as well.


    One other thing I'm curious about though: the helm-operator sets up watches for the resources that are created in a release. So for example, if the nginx-ingress deployment is manually edited, the operator will detect the change and reconcile it so that it is re-aligned with the release manifest.

    Thinking about this, I'm now questioning if the same reconciliation works for release resources that are cluster scoped. Would you mind verifying what happens when you manually edit both a namespace-scoped and cluster-scoped resource that has been deployed by the operator? My hunch is that the namespace-scoped resource will be reset but the cluster-scoped resource won't.

  6. added this to the v0.18.0 milestone on Mar 30, 2020
  7. mikeshng commented on Mar 31, 2020

    @mikeshng
    ContributorAuthor

    Thinking about this, I'm now questioning if the same reconciliation works for release resources that are cluster scoped. Would you mind verifying what happens when you manually edit both a namespace-scoped and cluster-scoped resource that has been deployed by the operator? My hunch is that the namespace-scoped resource will be reset but the cluster-scoped resource won't.

    The namespace-scoped resource did reset.
    When I edit the deployment and change the port to 8080 it reverted back to 80
    In

              name: nginx-ingress-controller
              ports:
              - containerPort: 80
    

    The cluster-scoped resource did not reset as you predicted.
    When I edit the clusterrole,

      verbs:
      - list
      - watch
    

    Added a get and it persisted.

      verbs:
      - get
      - list
      - watch
    
  8. mikeshng commented on Mar 31, 2020

    @mikeshng
    ContributorAuthor
  9. joelanford commented on Apr 20, 2020

    @joelanford
    Member

    It is, but since we already have a finalizer that runs helm uninstall I think we should theoretically be able to remove that constraint and setup watches on the cluster-scoped resources without relying on owner references.

    For example, we may be able to use the EnqueueRequestForAnnotation handler in these cases.

  10. bharathi-tenneti commented on Apr 20, 2020

    @bharathi-tenneti
    Contributor

    /assign

  11. bharathi-tenneti commented on Apr 27, 2020

    @bharathi-tenneti
    Contributor

    @mikeshng
    Trying to reproduce the issue, to confirm you used kubectl edit to manually edit the resources(deployment, and ClusterRole) ?

  12. mikeshng commented on Apr 27, 2020

    @mikeshng
    ContributorAuthor

    @mikeshng
    Trying to reproduce the issue, to confirm you used kubectl edit to manually edit the resources(deployment, and ClusterRole) ?

    It was a while ago, but I am sure it was either kubectl edit or oc edit

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

Metadata

Metadata

Labels

language/helmtriage/needs-information

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions