Kubernetes operator-sdk : How to delete controller? Kubernetes operator-sdk : How to delete controller? kubernetes kubernetes

Kubernetes operator-sdk : How to delete controller?


There is not an automated way to remove APIs via the operator-sdk.

There are a couple ways to do it. If you're operator is fairly simple, you could just scaffold a new operator and copy the code you want into it.

Otherwise, you'll have to remove it by hand. I created a dummy operator, commited it, and then added a new API to get this diff which can be used to see what you'll need to delete. (This is using the master branch, it may be different depending on the version you are using.)

diff --git a/PROJECT b/PROJECTindex ca36be5..0bb71be 100644--- a/PROJECT+++ b/PROJECT@@ -16,4 +16,13 @@ resources:   kind: Memcached   path: github.com/example/memcached-operator/api/v1alpha1   version: v1alpha1+- api:+    crdVersion: v1+    namespaced: true+  controller: true+  domain: example.com+  group: cache+  kind: Memcached2+  path: github.com/example/memcached-operator/api/v1alpha1+  version: v1alpha1 version: "3"diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.goindex 7730cf5..8211ded 100644--- a/api/v1alpha1/zz_generated.deepcopy.go+++ b/api/v1alpha1/zz_generated.deepcopy.go@@ -51,6 +51,95 @@ func (in *Memcached) DeepCopyObject() runtime.Object {    return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.+func (in *Memcached2) DeepCopyInto(out *Memcached2) {+   *out = *in+   out.TypeMeta = in.TypeMeta+   in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)+   out.Spec = in.Spec+   out.Status = in.Status+}++// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Memcached2.+func (in *Memcached2) DeepCopy() *Memcached2 {+   if in == nil {+       return nil+   }+   out := new(Memcached2)+   in.DeepCopyInto(out)+   return out+}++// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.+func (in *Memcached2) DeepCopyObject() runtime.Object {+   if c := in.DeepCopy(); c != nil {+       return c+   }+   return nil+}++// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.+func (in *Memcached2List) DeepCopyInto(out *Memcached2List) {+   *out = *in+   out.TypeMeta = in.TypeMeta+   in.ListMeta.DeepCopyInto(&out.ListMeta)+   if in.Items != nil {+       in, out := &in.Items, &out.Items+       *out = make([]Memcached2, len(*in))+       for i := range *in {+           (*in)[i].DeepCopyInto(&(*out)[i])+       }+   }+}++// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Memcached2List.+func (in *Memcached2List) DeepCopy() *Memcached2List {+   if in == nil {+       return nil+   }+   out := new(Memcached2List)+   in.DeepCopyInto(out)+   return out+}++// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.+func (in *Memcached2List) DeepCopyObject() runtime.Object {+   if c := in.DeepCopy(); c != nil {+       return c+   }+   return nil+}++// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.+func (in *Memcached2Spec) DeepCopyInto(out *Memcached2Spec) {+   *out = *in+}++// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Memcached2Spec.+func (in *Memcached2Spec) DeepCopy() *Memcached2Spec {+   if in == nil {+       return nil+   }+   out := new(Memcached2Spec)+   in.DeepCopyInto(out)+   return out+}++// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.+func (in *Memcached2Status) DeepCopyInto(out *Memcached2Status) {+   *out = *in+}++// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Memcached2Status.+func (in *Memcached2Status) DeepCopy() *Memcached2Status {+   if in == nil {+       return nil+   }+   out := new(Memcached2Status)+   in.DeepCopyInto(out)+   return out+}+ // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MemcachedList) DeepCopyInto(out *MemcachedList) {    *out = *indiff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yamlindex 8b7bb5b..5d83219 100644--- a/config/crd/kustomization.yaml+++ b/config/crd/kustomization.yaml@@ -3,17 +3,20 @@ # It should be run by config/default resources: - bases/cache.example.com_memcacheds.yaml+- bases/cache.example.com_memcached2s.yaml #+kubebuilder:scaffold:crdkustomizeresource  patchesStrategicMerge: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD #- patches/webhook_in_memcacheds.yaml+#- patches/webhook_in_memcached2s.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch  # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD #- patches/cainjection_in_memcacheds.yaml+#- patches/cainjection_in_memcached2s.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch  # the following config is for teaching kustomize how to do kustomization for CRDs.diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yamlindex 42654aa..9c62d32 100644--- a/config/samples/kustomization.yaml+++ b/config/samples/kustomization.yaml@@ -1,4 +1,5 @@ ## Append samples you want in your CSV to this file as resources ## resources: - cache_v1alpha1_memcached.yaml+- cache_v1alpha1_memcached2.yaml #+kubebuilder:scaffold:manifestskustomizesamplesdiff --git a/controllers/suite_test.go b/controllers/suite_test.goindex 97d4bfb..ffce919 100644--- a/controllers/suite_test.go+++ b/controllers/suite_test.go@@ -65,6 +65,9 @@ var _ = BeforeSuite(func() {    err = cachev1alpha1.AddToScheme(scheme.Scheme)    Expect(err).NotTo(HaveOccurred()) +   err = cachev1alpha1.AddToScheme(scheme.Scheme)+   Expect(err).NotTo(HaveOccurred())+    //+kubebuilder:scaffold:scheme     k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})diff --git a/main.go b/main.goindex b2bedfd..443397e 100644--- a/main.go+++ b/main.go@@ -85,6 +85,13 @@ func main() {        setupLog.Error(err, "unable to create controller", "controller", "Memcached")        os.Exit(1)    }+   if err = (&controllers.Memcached2Reconciler{+       Client: mgr.GetClient(),+       Scheme: mgr.GetScheme(),+   }).SetupWithManager(mgr); err != nil {+       setupLog.Error(err, "unable to create controller", "controller", "Memcached2")+       os.Exit(1)+   }    //+kubebuilder:scaffold:builder     if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {

I'm not sure if this is something that we could add to the operator-sdk right now, but it would be worth filing an issue, which we will discuss at our triage meeting. https://github.com/operator-framework/operator-sdk/issues/new?assignees=&labels=&template=feature-request.md&title=