Skip to content

Commit

Permalink
ci: enable and fix the e2e tests for deploy image sample
Browse files Browse the repository at this point in the history
We are enabling the execution of e2e tests for deploy-image in the GitHub action. However, to allow we easily configure the tests we needed to change the scaffold of the samples to have defaulting and validation webhooks.

So, we just added the --defaulting flag to generate the webhook for the testdata sample using deploy image and regenerated it. If you want to understand why see: #4119
  • Loading branch information
camilamacedo86 committed Aug 30, 2024
1 parent d3ce905 commit d1a0cb8
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 7 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/test-e2e-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ jobs:
KUSTOMIZATION_FILE_PATH="testdata/project-v4-with-deploy-image/config/default/kustomization.yaml"
sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '51s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '55,151s/^#//' $KUSTOMIZATION_FILE_PATH
cd testdata/project-v4-with-deploy-image/
go mod tidy
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
2 changes: 1 addition & 1 deletion test/testdata/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions testdata/project-v4-with-deploy-image/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 26 additions & 0 deletions testdata/project-v4-with-deploy-image/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d1a0cb8

Please sign in to comment.