diff --git a/.github/workflows/test-e2e-samples.yml b/.github/workflows/test-e2e-samples.yml index fd58dae46c7..41b54f871bb 100644 --- a/.github/workflows/test-e2e-samples.yml +++ b/.github/workflows/test-e2e-samples.yml @@ -59,9 +59,7 @@ jobs: make generate make manifests -# Fixme: The e2e tests for deploy image are failing and we -# need to fix in a follow up -# - name: Testing make test-e2e for project-v4-with-deploy-image -# working-directory: testdata/project-v4-with-deploy-image -# run: | -# make test-e2e + - name: Testing make test-e2e for project-v4-with-deploy-image + working-directory: testdata/project-v4-with-deploy-image + run: | + make test-e2e diff --git a/test/testdata/generate.sh b/test/testdata/generate.sh index 5a517bdf9b7..1781bc6de62 100755 --- a/test/testdata/generate.sh +++ b/test/testdata/generate.sh @@ -92,7 +92,7 @@ function scaffold_test_project { $kb create api --group example.com --version v1alpha1 --kind Memcached --image=memcached:memcached:1.6.26-alpine3.19 --image-container-command="memcached,-m=64,-o,modern,-v" --image-container-port="11211" --run-as-user="1001" --plugins="deploy-image/v1-alpha" --make=false $kb create api --group example.com --version v1alpha1 --kind Busybox --image=busybox:1.36.1 --plugins="deploy-image/v1-alpha" --make=false header_text 'Creating Memcached webhook ...' - $kb create webhook --group example.com --version v1alpha1 --kind Memcached --programmatic-validation + $kb create webhook --group example.com --version v1alpha1 --kind Memcached --defaulting --programmatic-validation fi if [[ $project == project-v4-with-grafana ]]; then diff --git a/testdata/project-v4-with-deploy-image/PROJECT b/testdata/project-v4-with-deploy-image/PROJECT index 1b2ee48a339..beed2814c3f 100644 --- a/testdata/project-v4-with-deploy-image/PROJECT +++ b/testdata/project-v4-with-deploy-image/PROJECT @@ -36,6 +36,7 @@ resources: path: sigs.k8s.io/kubebuilder/testdata/project-v4-with-deploy-image/api/v1alpha1 version: v1alpha1 webhooks: + defaulting: true validation: true webhookVersion: v1 - api: diff --git a/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook.go b/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook.go index 89819d050f5..f631533d639 100644 --- a/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook.go +++ b/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook.go @@ -37,6 +37,17 @@ func (r *Memcached) SetupWebhookWithManager(mgr ctrl.Manager) error { // TODO(user): EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// +kubebuilder:webhook:path=/mutate-example-com-testproject-org-v1alpha1-memcached,mutating=true,failurePolicy=fail,sideEffects=None,groups=example.com.testproject.org,resources=memcacheds,verbs=create;update,versions=v1alpha1,name=mmemcached.kb.io,admissionReviewVersions=v1 + +var _ webhook.Defaulter = &Memcached{} + +// Default implements webhook.Defaulter so a webhook will be registered for the type +func (r *Memcached) Default() { + memcachedlog.Info("default", "name", r.Name) + + // TODO(user): fill in your defaulting logic. +} + // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. // NOTE: The 'path' attribute must follow a specific pattern and should not be modified directly here. // Modifying the path for an invalid path can cause API server errors; failing to locate the webhook. diff --git a/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook_test.go b/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook_test.go index 39c2ed23133..3269398e4f9 100644 --- a/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook_test.go +++ b/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook_test.go @@ -22,6 +22,14 @@ import ( var _ = Describe("Memcached Webhook", func() { + Context("When creating Memcached under Defaulting Webhook", func() { + It("Should fill in the default value if a required field is empty", func() { + + // TODO(user): Add your logic here + + }) + }) + Context("When creating Memcached under Validating Webhook", func() { It("Should deny if a required field is empty", func() { diff --git a/testdata/project-v4-with-deploy-image/config/webhook/manifests.yaml b/testdata/project-v4-with-deploy-image/config/webhook/manifests.yaml index 135b03ac0d3..34833909a2c 100644 --- a/testdata/project-v4-with-deploy-image/config/webhook/manifests.yaml +++ b/testdata/project-v4-with-deploy-image/config/webhook/manifests.yaml @@ -1,5 +1,31 @@ --- apiVersion: admissionregistration.k8s.io/v1 +kind: MutatingWebhookConfiguration +metadata: + name: mutating-webhook-configuration +webhooks: +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /mutate-example-com-testproject-org-v1alpha1-memcached + failurePolicy: Fail + name: mmemcached.kb.io + rules: + - apiGroups: + - example.com.testproject.org + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - memcacheds + sideEffects: None +--- +apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: validating-webhook-configuration diff --git a/testdata/project-v4-with-deploy-image/dist/install.yaml b/testdata/project-v4-with-deploy-image/dist/install.yaml index 4e29265f0ae..df2ac73a9b0 100644 --- a/testdata/project-v4-with-deploy-image/dist/install.yaml +++ b/testdata/project-v4-with-deploy-image/dist/install.yaml @@ -652,6 +652,32 @@ spec: secretName: webhook-server-cert --- apiVersion: admissionregistration.k8s.io/v1 +kind: MutatingWebhookConfiguration +metadata: + name: project-v4-with-deploy-image-mutating-webhook-configuration +webhooks: +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: project-v4-with-deploy-image-webhook-service + namespace: project-v4-with-deploy-image-system + path: /mutate-example-com-testproject-org-v1alpha1-memcached + failurePolicy: Fail + name: mmemcached.kb.io + rules: + - apiGroups: + - example.com.testproject.org + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - memcacheds + sideEffects: None +--- +apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: project-v4-with-deploy-image-validating-webhook-configuration