From 400f8f1a16ddf30359880675c601050c1a65771a Mon Sep 17 00:00:00 2001 From: Erik Godding Boye Date: Sun, 23 Feb 2025 18:05:35 +0100 Subject: [PATCH] feat!: unserve long-time deprecated SubNamespace API versions --- api/accurate/v1/subnamespace_types.go | 2 +- api/accurate/v2alpha1/subnamespace_types.go | 2 +- charts/accurate/templates/generated/crds.yaml | 12 +-- .../accurate.cybozu.com_subnamespaces.yaml | 14 +-- e2e/e2e_test.go | 8 -- hooks/subnamespace_deprecated_test.go | 100 ------------------ 6 files changed, 10 insertions(+), 128 deletions(-) delete mode 100644 hooks/subnamespace_deprecated_test.go diff --git a/api/accurate/v1/subnamespace_types.go b/api/accurate/v1/subnamespace_types.go index 18edbc9..9d55c63 100644 --- a/api/accurate/v1/subnamespace_types.go +++ b/api/accurate/v1/subnamespace_types.go @@ -28,7 +28,7 @@ type SubNamespaceSpec struct { } //+kubebuilder:object:root=true -//+kubebuilder:deprecatedversion:warning="The v1 version of SubNamespace has been deprecated and will be removed in a future release of the API. Please upgrade." +//+kubebuilder:unservedversion // SubNamespace is the Schema for the subnamespaces API // Deprecated: This type will be removed in one of the next releases. diff --git a/api/accurate/v2alpha1/subnamespace_types.go b/api/accurate/v2alpha1/subnamespace_types.go index 176e255..45fd2be 100644 --- a/api/accurate/v2alpha1/subnamespace_types.go +++ b/api/accurate/v2alpha1/subnamespace_types.go @@ -32,7 +32,7 @@ type SubNamespaceSpec struct { } //+kubebuilder:object:root=true -//+kubebuilder:deprecatedversion:warning="The v2alpha1 version of SubNamespace has been deprecated and will be removed in a future release of the API. Please upgrade." +//+kubebuilder:unservedversion //+kubebuilder:subresource:status //+genclient diff --git a/charts/accurate/templates/generated/crds.yaml b/charts/accurate/templates/generated/crds.yaml index d5f16ba..a75bd7a 100644 --- a/charts/accurate/templates/generated/crds.yaml +++ b/charts/accurate/templates/generated/crds.yaml @@ -32,9 +32,7 @@ spec: singular: subnamespace scope: Namespaced versions: - - deprecated: true - deprecationWarning: The v1 version of SubNamespace has been deprecated and will be removed in a future release of the API. Please upgrade. - name: v1 + - name: v1 schema: openAPIV3Schema: description: |- @@ -79,7 +77,7 @@ spec: - conflict type: string type: object - served: true + served: false storage: false - name: v2 schema: @@ -190,9 +188,7 @@ spec: storage: true subresources: status: {} - - deprecated: true - deprecationWarning: The v2alpha1 version of SubNamespace has been deprecated and will be removed in a future release of the API. Please upgrade. - name: v2alpha1 + - name: v2alpha1 schema: openAPIV3Schema: description: |- @@ -299,7 +295,7 @@ spec: type: integer type: object type: object - served: true + served: false storage: false subresources: status: {} diff --git a/config/crd/bases/accurate.cybozu.com_subnamespaces.yaml b/config/crd/bases/accurate.cybozu.com_subnamespaces.yaml index 4080643..e667c07 100644 --- a/config/crd/bases/accurate.cybozu.com_subnamespaces.yaml +++ b/config/crd/bases/accurate.cybozu.com_subnamespaces.yaml @@ -14,10 +14,7 @@ spec: singular: subnamespace scope: Namespaced versions: - - deprecated: true - deprecationWarning: The v1 version of SubNamespace has been deprecated and will - be removed in a future release of the API. Please upgrade. - name: v1 + - name: v1 schema: openAPIV3Schema: description: |- @@ -63,7 +60,7 @@ spec: - conflict type: string type: object - served: true + served: false storage: false - name: v2 schema: @@ -177,10 +174,7 @@ spec: storage: true subresources: status: {} - - deprecated: true - deprecationWarning: The v2alpha1 version of SubNamespace has been deprecated and - will be removed in a future release of the API. Please upgrade. - name: v2alpha1 + - name: v2alpha1 schema: openAPIV3Schema: description: |- @@ -290,7 +284,7 @@ spec: type: integer type: object type: object - served: true + served: false storage: false subresources: status: {} diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index bffed73..c8cc0db 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -362,14 +362,6 @@ var _ = Describe("kubectl accurate", func() { }).Should(Succeed()) }) - It("should convert SubNamespace to older version", func() { - kubectlSafe(nil, "create", "ns", "rootv2") - kubectlSafe(nil, "accurate", "ns", "set-type", "rootv2", "root") - kubectlSafe(nil, "accurate", "sub", "create", "subv2", "rootv2") - kubectlSafe(nil, "get", "subnamespaces", "-n", "rootv2", "subv2") - kubectlSafe(nil, "get", "subnamespaces.v1.accurate.cybozu.com", "-n", "rootv2", "subv2") - }) - It("should run other commands", func() { kubectlSafe(nil, "accurate", "list") kubectlSafe(nil, "accurate", "sub", "list") diff --git a/hooks/subnamespace_deprecated_test.go b/hooks/subnamespace_deprecated_test.go deleted file mode 100644 index dcfaad5..0000000 --- a/hooks/subnamespace_deprecated_test.go +++ /dev/null @@ -1,100 +0,0 @@ -package hooks - -import ( - "context" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" - accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1" - "github.com/cybozu-go/accurate/pkg/constants" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" -) - -// This is just simple smoke tests ensuring our webhooks are handling additional versions of the SubNamespace API. -var _ = Describe("SubNamespace webhook", func() { - ctx := context.Background() - - Context("v2alpha1", func() { - It("should deny creation of SubNamespace in a namespace that is neither root nor subnamespace", func() { - ns := &corev1.Namespace{} - ns.Name = "v2alpha1-ns1" - Expect(k8sClient.Create(ctx, ns)).To(Succeed()) - - sn := &accuratev2alpha1.SubNamespace{} - sn.Namespace = ns.Name - sn.Name = "v2alpha1-foo" - err := k8sClient.Create(ctx, sn) - Expect(err).To(HaveOccurred()) - Expect(errors.ReasonForError(err)).Should(Equal(metav1.StatusReasonForbidden)) - }) - - It("should allow creation of SubNamespace in a root namespace", func() { - ns := &corev1.Namespace{} - ns.Name = "v2alpha1-ns2" - ns.Labels = map[string]string{constants.LabelType: constants.NSTypeRoot} - Expect(k8sClient.Create(ctx, ns)).To(Succeed()) - - sn := &accuratev2alpha1.SubNamespace{} - sn.Namespace = ns.Name - sn.Name = "v2alpha1-foo" - sn.Spec.Labels = map[string]string{"foo": "bar"} - sn.Spec.Annotations = map[string]string{"foo": "bar"} - Expect(k8sClient.Create(ctx, sn)).To(Succeed()) - - Expect(controllerutil.ContainsFinalizer(sn, constants.Finalizer)).To(BeTrue()) - - // deleting finalizer should succeed - sn.Finalizers = nil - Expect(k8sClient.Update(ctx, sn)).To(Succeed()) - - sn = &accuratev2alpha1.SubNamespace{} - Expect(k8sClient.Get(ctx, client.ObjectKey{Namespace: "v2alpha1-ns2", Name: "v2alpha1-foo"}, sn)).To(Succeed()) - Expect(sn.Finalizers).To(BeEmpty()) - }) - }) - - Context("v1", func() { - It("should deny creation of SubNamespace in a namespace that is neither root nor subnamespace", func() { - ns := &corev1.Namespace{} - ns.Name = "v1-ns1" - Expect(k8sClient.Create(ctx, ns)).To(Succeed()) - - sn := &accuratev1.SubNamespace{} - sn.Namespace = ns.Name - sn.Name = "v1-foo" - err := k8sClient.Create(ctx, sn) - Expect(err).To(HaveOccurred()) - Expect(errors.ReasonForError(err)).Should(Equal(metav1.StatusReasonForbidden)) - }) - - It("should allow creation of SubNamespace in a root namespace", func() { - ns := &corev1.Namespace{} - ns.Name = "v1-ns2" - ns.Labels = map[string]string{constants.LabelType: constants.NSTypeRoot} - Expect(k8sClient.Create(ctx, ns)).To(Succeed()) - - sn := &accuratev1.SubNamespace{} - sn.Namespace = ns.Name - sn.Name = "v1-foo" - sn.Spec.Labels = map[string]string{"foo": "bar"} - sn.Spec.Annotations = map[string]string{"foo": "bar"} - Expect(k8sClient.Create(ctx, sn)).To(Succeed()) - - Expect(controllerutil.ContainsFinalizer(sn, constants.Finalizer)).To(BeTrue()) - - // deleting finalizer should succeed - sn.Finalizers = nil - Expect(k8sClient.Update(ctx, sn)).To(Succeed()) - - sn = &accuratev1.SubNamespace{} - Expect(k8sClient.Get(ctx, client.ObjectKey{Namespace: "v1-ns2", Name: "v1-foo"}, sn)).To(Succeed()) - Expect(sn.Finalizers).To(BeEmpty()) - }) - }) -})