From fbe9a9ca30a8a5dca985a2d9601c31cea9450842 Mon Sep 17 00:00:00 2001 From: Rory Z <16801068+Rory-Z@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:52:27 +0800 Subject: [PATCH] chore: delete valiedate webhook and default webhook for emqx --- PROJECT | 2 - apis/apps/v2beta1/emqx_webhook.go | 70 ------------------- apis/apps/v2beta1/emqx_webhook_test.go | 33 --------- apis/apps/v2beta1/webhook_suite_test.go | 3 - config/webhook/manifests.yaml | 42 ----------- .../apps/v2beta1/add_emqx_core_test.go | 2 - .../apps/v2beta1/add_emqx_repl_suite_test.go | 1 - controllers/apps/v2beta1/suite_test.go | 1 - .../webhook-mutating-configuration.yaml | 21 ------ .../webhook-validating-configuration.yaml | 21 ------ e2e/v2beta1/e2e_rebalance_test.go | 5 -- e2e/v2beta1/e2e_test.go | 3 - e2e/v2beta1/suite_test.go | 1 - main.go | 5 -- 14 files changed, 210 deletions(-) delete mode 100644 apis/apps/v2beta1/emqx_webhook.go delete mode 100644 apis/apps/v2beta1/emqx_webhook_test.go diff --git a/PROJECT b/PROJECT index 3c999f84d..2af6f8f41 100644 --- a/PROJECT +++ b/PROJECT @@ -126,8 +126,6 @@ resources: version: v2beta1 webhooks: conversion: true - defaulting: true - validation: true webhookVersion: v1 - api: crdVersion: v1 diff --git a/apis/apps/v2beta1/emqx_webhook.go b/apis/apps/v2beta1/emqx_webhook.go deleted file mode 100644 index 41a651c99..000000000 --- a/apis/apps/v2beta1/emqx_webhook.go +++ /dev/null @@ -1,70 +0,0 @@ -/* -Copyright 2021. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v2beta1 - -import ( - - // "github.com/gurkankaymak/hocon" - - "k8s.io/apimachinery/pkg/runtime" - ctrl "sigs.k8s.io/controller-runtime" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/webhook" -) - -// log is for logging in this package. -var emqxlog = logf.Log.WithName("emqx-resource") - -func (r *EMQX) SetupWebhookWithManager(mgr ctrl.Manager) error { - return ctrl.NewWebhookManagedBy(mgr). - For(r). - Complete() -} - -//+kubebuilder:webhook:path=/mutate-apps-emqx-io-v2beta1-emqx,mutating=true,failurePolicy=fail,sideEffects=None,groups=apps.emqx.io,resources=emqxes,verbs=create;update,versions=v2beta1,name=mutating.apps.emqx.io,admissionReviewVersions={v1,v1beta1} - -var _ webhook.Defaulter = &EMQX{} - -// Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *EMQX) Default() { - emqxlog.Info("default", "name", r.Name) -} - -// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. -//+kubebuilder:webhook:path=/validate-apps-emqx-io-v2beta1-emqx,mutating=false,failurePolicy=fail,sideEffects=None,groups=apps.emqx.io,resources=emqxes,verbs=create;update,versions=v2beta1,name=validator.apps.emqx.io,admissionReviewVersions={v1,v1beta1} - -var _ webhook.Validator = &EMQX{} - -// ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *EMQX) ValidateCreate() error { - return nil -} - -// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *EMQX) ValidateUpdate(old runtime.Object) error { - emqxlog.Info("validate update", "name", r.Name) - - return nil -} - -// ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *EMQX) ValidateDelete() error { - emqxlog.Info("validate delete", "name", r.Name) - - // TODO(user): fill in your validation logic upon object deletion. - return nil -} diff --git a/apis/apps/v2beta1/emqx_webhook_test.go b/apis/apps/v2beta1/emqx_webhook_test.go deleted file mode 100644 index f1a694f68..000000000 --- a/apis/apps/v2beta1/emqx_webhook_test.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2021. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v2beta1 - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestDefault(t *testing.T) { - instance := &EMQX{} - instance.Default() -} - -func TestValidateDelete(t *testing.T) { - instance := &EMQX{} - assert.Nil(t, instance.ValidateDelete()) -} diff --git a/apis/apps/v2beta1/webhook_suite_test.go b/apis/apps/v2beta1/webhook_suite_test.go index da970c1c1..ccca3871b 100644 --- a/apis/apps/v2beta1/webhook_suite_test.go +++ b/apis/apps/v2beta1/webhook_suite_test.go @@ -99,9 +99,6 @@ var _ = BeforeSuite(func() { }) Expect(err).NotTo(HaveOccurred()) - err = (&EMQX{}).SetupWebhookWithManager(mgr) - Expect(err).NotTo(HaveOccurred()) - err = (&Rebalance{}).SetupWebhookWithManager(mgr) Expect(err).NotTo(HaveOccurred()) diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 787bf69fb..f908ba199 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -5,27 +5,6 @@ metadata: creationTimestamp: null name: mutating-webhook-configuration webhooks: -- admissionReviewVersions: - - v1 - - v1beta1 - clientConfig: - service: - name: webhook-service - namespace: system - path: /mutate-apps-emqx-io-v2beta1-emqx - failurePolicy: Fail - name: mutating.apps.emqx.io - rules: - - apiGroups: - - apps.emqx.io - apiVersions: - - v2beta1 - operations: - - CREATE - - UPDATE - resources: - - emqxes - sideEffects: None - admissionReviewVersions: - v1 - v1beta1 @@ -96,27 +75,6 @@ metadata: creationTimestamp: null name: validating-webhook-configuration webhooks: -- admissionReviewVersions: - - v1 - - v1beta1 - clientConfig: - service: - name: webhook-service - namespace: system - path: /validate-apps-emqx-io-v2beta1-emqx - failurePolicy: Fail - name: validator.apps.emqx.io - rules: - - apiGroups: - - apps.emqx.io - apiVersions: - - v2beta1 - operations: - - CREATE - - UPDATE - resources: - - emqxes - sideEffects: None - admissionReviewVersions: - v1 - v1beta1 diff --git a/controllers/apps/v2beta1/add_emqx_core_test.go b/controllers/apps/v2beta1/add_emqx_core_test.go index 905a42a3f..1868925e1 100644 --- a/controllers/apps/v2beta1/add_emqx_core_test.go +++ b/controllers/apps/v2beta1/add_emqx_core_test.go @@ -25,8 +25,6 @@ func TestGenerateStatefulSet(t *testing.T) { }, } instance.Spec.CoreTemplate.Spec.Replicas = pointer.Int32(3) - instance.Default() - assert.Nil(t, instance.ValidateCreate()) t.Run("check metadata", func(t *testing.T) { emqx := instance.DeepCopy() diff --git a/controllers/apps/v2beta1/add_emqx_repl_suite_test.go b/controllers/apps/v2beta1/add_emqx_repl_suite_test.go index cc3c06b85..7735ba1bc 100644 --- a/controllers/apps/v2beta1/add_emqx_repl_suite_test.go +++ b/controllers/apps/v2beta1/add_emqx_repl_suite_test.go @@ -56,7 +56,6 @@ var _ = Describe("Check add repl controller", Ordered, Label("repl"), func() { }, }, } - instance.Default() }) It("create namespace", func() { diff --git a/controllers/apps/v2beta1/suite_test.go b/controllers/apps/v2beta1/suite_test.go index 7740cb1bc..94a0a1744 100644 --- a/controllers/apps/v2beta1/suite_test.go +++ b/controllers/apps/v2beta1/suite_test.go @@ -79,7 +79,6 @@ var _ = BeforeSuite(func() { timeout = time.Second * 5 interval = time.Millisecond * 500 ctx = context.TODO() - emqx.Default() Expect(os.Setenv("USE_EXISTING_CLUSTER", "false")).To(Succeed()) diff --git a/deploy/charts/emqx-operator/templates/webhook-mutating-configuration.yaml b/deploy/charts/emqx-operator/templates/webhook-mutating-configuration.yaml index a3179dbd6..5d3d8815d 100644 --- a/deploy/charts/emqx-operator/templates/webhook-mutating-configuration.yaml +++ b/deploy/charts/emqx-operator/templates/webhook-mutating-configuration.yaml @@ -6,27 +6,6 @@ metadata: cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "emqx-operator.fullname" . }}-serving-cert name: {{ include "emqx-operator.fullname" . }}-mutating-webhook-configuration webhooks: -- admissionReviewVersions: - - v1 - - v1beta1 - clientConfig: - service: - name: {{ include "emqx-operator.fullname" . }}-webhook-service - namespace: {{ .Release.Namespace }} - path: /mutate-apps-emqx-io-v2beta1-emqx - failurePolicy: Fail - name: mutating.apps.emqx.io - rules: - - apiGroups: - - apps.emqx.io - apiVersions: - - v2beta1 - operations: - - CREATE - - UPDATE - resources: - - emqxes - sideEffects: None - admissionReviewVersions: - v1 - v1beta1 diff --git a/deploy/charts/emqx-operator/templates/webhook-validating-configuration.yaml b/deploy/charts/emqx-operator/templates/webhook-validating-configuration.yaml index caaf6d834..a3204a80c 100644 --- a/deploy/charts/emqx-operator/templates/webhook-validating-configuration.yaml +++ b/deploy/charts/emqx-operator/templates/webhook-validating-configuration.yaml @@ -6,27 +6,6 @@ metadata: cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "emqx-operator.fullname" . }}-serving-cert name: {{ include "emqx-operator.fullname" . }}-validating-webhook-configuration webhooks: -- admissionReviewVersions: - - v1 - - v1beta1 - clientConfig: - service: - name: {{ include "emqx-operator.fullname" . }}-webhook-service - namespace: {{ .Release.Namespace }} - path: /validate-apps-emqx-io-v2beta1-emqx - failurePolicy: Fail - name: validator.apps.emqx.io - rules: - - apiGroups: - - apps.emqx.io - apiVersions: - - v2beta1 - operations: - - CREATE - - UPDATE - resources: - - emqxes - sideEffects: None - admissionReviewVersions: - v1 - v1beta1 diff --git a/e2e/v2beta1/e2e_rebalance_test.go b/e2e/v2beta1/e2e_rebalance_test.go index eef702e67..6990af7d4 100644 --- a/e2e/v2beta1/e2e_rebalance_test.go +++ b/e2e/v2beta1/e2e_rebalance_test.go @@ -47,7 +47,6 @@ var _ = Describe("EMQX 5 Rebalance Test", Label("rebalance"), func() { BeforeEach(func() { instance = genEMQX().DeepCopy() instance.Spec.Image = "emqx/emqx-enterprise:5.1" - instance.Default() }) Context("EMQX is not found", func() { @@ -135,8 +134,6 @@ var _ = Describe("EMQX 5 Rebalance Test", Label("rebalance"), func() { // create EMQX CR instance.Spec.ReplicantTemplate = nil instance.Spec.CoreTemplate.Spec.Replicas = pointer.Int32Ptr(2) - instance.Default() - Expect(instance.ValidateCreate()).Should(Succeed()) Expect(k8sClient.Create(context.TODO(), instance)).Should(Succeed()) // check EMQX CR if created successfully @@ -209,8 +206,6 @@ var _ = Describe("EMQX 5 Rebalance Test", Label("rebalance"), func() { // create EMQX CR instance.Spec.ReplicantTemplate = nil instance.Spec.CoreTemplate.Spec.Replicas = pointer.Int32Ptr(2) - instance.Default() - Expect(instance.ValidateCreate()).Should(Succeed()) Expect(k8sClient.Create(context.TODO(), instance)).Should(Succeed()) // check EMQX CR if created successfully diff --git a/e2e/v2beta1/e2e_test.go b/e2e/v2beta1/e2e_test.go index f64a3e676..f12c8951d 100644 --- a/e2e/v2beta1/e2e_test.go +++ b/e2e/v2beta1/e2e_test.go @@ -42,8 +42,6 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { JustBeforeEach(func() { instance.Spec.ReplicantTemplate = nil instance.Spec.CoreTemplate.Spec.Replicas = pointer.Int32Ptr(2) - instance.Default() - Expect(instance.ValidateCreate()).Should(Succeed()) }) It("should create namespace and EMQX CR", func() { @@ -286,7 +284,6 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { Replicas: pointer.Int32Ptr(2), }, } - instance.Default() Expect(k8sClient.Update(context.TODO(), instance)).Should(Succeed()) }) diff --git a/e2e/v2beta1/suite_test.go b/e2e/v2beta1/suite_test.go index 01c590ed2..25a1e1f8e 100644 --- a/e2e/v2beta1/suite_test.go +++ b/e2e/v2beta1/suite_test.go @@ -178,6 +178,5 @@ func genEMQX() *appsv2beta1.EMQX { }, }, } - emqx.Default() return emqx } diff --git a/main.go b/main.go index bfdce0378..9355de5e2 100644 --- a/main.go +++ b/main.go @@ -150,11 +150,6 @@ func main() { os.Exit(1) } - if err = (&appsv2beta1.EMQX{}).SetupWebhookWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create webhook", "webhook", "EMQX") - os.Exit(1) - } - if err = (&appsv2beta1.Rebalance{}).SetupWebhookWithManager(mgr); err != nil { setupLog.Error(err, "unable to create webhook", "webhook", "Rebalance") os.Exit(1)