Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no way to delete the Lease programatically #6677

Closed
MathieuCesbron opened this issue Feb 11, 2024 · 4 comments
Closed

There is no way to delete the Lease programatically #6677

MathieuCesbron opened this issue Feb 11, 2024 · 4 comments
Labels
triage/needs-information Indicates an issue needs more information in order to work on it.

Comments

@MathieuCesbron
Copy link

Bug Report

With this config, a Lease is created and a leader is chosen. I installed my operator and all is working well. The issue is that everytime I undeploy the operator the Lease is not deleted. Is there a way to add a owner ownerReferences to the Lease in the code ? Or something that will clean the Lease on undeploy.

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
    Scheme:                  scheme,
    MetricsBindAddress:      metricsAddr,
    Port:                    9443,
    HealthProbeBindAddress:  probeAddr,
    LeaderElection:          true,
    LeaderElectionID:        "operator-lock",
    LeaderElectionNamespace: "default",
})

Thanks,

@jberkhahn jberkhahn added the triage/needs-information Indicates an issue needs more information in order to work on it. label Feb 12, 2024
@jberkhahn
Copy link
Contributor

What exactly do you mean by 'undeploying' your operator? Specifically, are you running the controller inside or outside the cluster?

@MathieuCesbron
Copy link
Author

I am running the controller inside the cluster. By "undeploying" the operator I mean to use the make undeploy of the Makefile.

Adding a LeaderElection: true will create a Lease object on deployment of the cluster. I am looking for a way to garbage collect this Lease when the pods it references are deleted.

@acornett21
Copy link
Contributor

acornett21 commented Feb 26, 2024

Hi @MathieuCesbron I had a chance to test this, and the Lease object is cleaned up by K8s after the reference is gone.

This was tested on the below:

oc version
Client Version: 4.14.11
Kustomize Version: v5.0.1
Server Version: 4.14.1
Kubernetes Version: v1.27.6+f67aeb3
$ make deploy 
...
...
deployment.apps/certification-operator-controller-manager created


$ oc get lease
NAME                  HOLDER                                                                                           AGE
ef59679f.redhat.com   certification-operator-controller-manager-8cc6589ff-2rjv7_55c951d2-c54f-45db-896a-8d01e87af0f7   3m44s

$ make undeploy
...
...
deployment.apps "certification-operator-controller-manager" deleted

$ oc get lease
No resources found in certification-operator-system namespace.

The value for LeaderElectionID is autogenerated via kubebuilder based on how the operator is scaffolded, so the only thing I can think of is that there is a conflict in your cluster with the name operator-lock. Can you try replacing with the autogenerated value?

@MathieuCesbron
Copy link
Author

Thanks for testing it. There must be something I am doing wrong then, I will close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/needs-information Indicates an issue needs more information in order to work on it.
Projects
None yet
Development

No branches or pull requests

3 participants