没有通过 operator-sdk 自动删除 API 的方法。
有几种方法可以做到这一点。如果您的操作员相当简单,您可以只搭建一个新的操作员并将您想要的代码复制到其中。
否则,您必须手动将其移除。我创建了一个虚拟运算符,提交了它,然后添加了一个新的 API 来获取这个差异,它可以用来查看你需要删除的内容。(这是使用master
分支,可能会因您使用的版本而异。)
diff --git a/PROJECT b/PROJECT
index 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.go
index 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 = *in
diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml
index 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.yaml
index 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:manifestskustomizesamples
diff --git a/controllers/suite_test.go b/controllers/suite_test.go
index 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.go
index 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 {
我不确定这是否是我们现在可以添加到 operator-sdk 的东西,但值得提出一个问题,我们将在分诊会议上讨论。https://github.com/operator-framework/operator-sdk/issues/new?assignees=&labels=&template=feature-request.md&title=