From 8553b8e3e6b7c278e9b4b4ad1984aa5e80150769 Mon Sep 17 00:00:00 2001 From: Jakub Warczarek Date: Thu, 26 Sep 2024 13:39:33 +0200 Subject: [PATCH 1/2] chore(tests): disable KIC admission webhook for TestKongPluginInstallationEssentials --- test/helpers/generators.go | 20 +++++++++++++++++-- .../test_kongplugininstallation.go | 9 +++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/test/helpers/generators.go b/test/helpers/generators.go index 0827cb814..941d3623b 100644 --- a/test/helpers/generators.go +++ b/test/helpers/generators.go @@ -65,9 +65,11 @@ func GenerateGateway(gatewayNSN types.NamespacedName, gatewayClass *gatewayv1.Ga return gateway } +type gatewayConfigurationOption func(*operatorv1beta1.GatewayConfiguration) + // GenerateGatewayConfiguration generates a GatewayConfiguration to be used in tests -func GenerateGatewayConfiguration(namespace string) *operatorv1beta1.GatewayConfiguration { - return &operatorv1beta1.GatewayConfiguration{ +func GenerateGatewayConfiguration(namespace string, opts ...gatewayConfigurationOption) *operatorv1beta1.GatewayConfiguration { + gwc := &operatorv1beta1.GatewayConfiguration{ ObjectMeta: metav1.ObjectMeta{ Namespace: namespace, Name: uuid.NewString(), @@ -139,6 +141,20 @@ func GenerateGatewayConfiguration(namespace string) *operatorv1beta1.GatewayConf }, }, } + for _, opt := range opts { + opt(gwc) + } + return gwc +} + +// WithWebhookDisabled disables the admission webhook for the control plane +func WithWebhookDisabled() func(*operatorv1beta1.GatewayConfiguration) { + return func(gc *operatorv1beta1.GatewayConfiguration) { + gc.Spec.ControlPlaneOptions.Deployment.PodTemplateSpec.Spec.Containers[0].Env = append(gc.Spec.ControlPlaneOptions.Deployment.PodTemplateSpec.Spec.Containers[0].Env, corev1.EnvVar{ + Name: "CONTROLLER_ADMISSION_WEBHOOK_LISTEN", + Value: "off", + }) + } } // GenerateHTTPRoute generates an HTTPRoute to be used in tests diff --git a/test/integration/test_kongplugininstallation.go b/test/integration/test_kongplugininstallation.go index b40ba7dba..148536c23 100644 --- a/test/integration/test_kongplugininstallation.go +++ b/test/integration/test_kongplugininstallation.go @@ -31,11 +31,6 @@ import ( ) func TestKongPluginInstallationEssentials(t *testing.T) { - if webhookEnabled { - // It can't be tested with webhook, because it rejects resources immediately, that would - // be accepted by the controller taking into account the eventual consistency nature of K8s. - t.Skip("webhook is enabled, skipping the test (due to webhook validation limitations)") - } namespace, cleaner := helpers.SetupTestEnv(t, GetCtx(), GetEnv()) const registryUrl = "northamerica-northeast1-docker.pkg.dev/k8s-team-playground/" @@ -212,7 +207,9 @@ func TestKongPluginInstallationEssentials(t *testing.T) { func deployGatewayWithKPI( t *testing.T, cleaner *clusters.Cleaner, namespace string, ) (gatewayIPAddress string, gatewayConfigNN, httpRouteNN k8stypes.NamespacedName) { - gatewayConfig := helpers.GenerateGatewayConfiguration(namespace) + // NOTE: Disable webhook for KIC, because it checks for the plugin in Kong Gateway and rejects, + // thus it requires strict order of deployment. + gatewayConfig := helpers.GenerateGatewayConfiguration(namespace, helpers.WithWebhookDisabled()) t.Logf("deploying GatewayConfiguration %s/%s", gatewayConfig.Namespace, gatewayConfig.Name) gatewayConfig, err := GetClients().OperatorClient.ApisV1beta1().GatewayConfigurations(namespace).Create(GetCtx(), gatewayConfig, metav1.CreateOptions{}) require.NoError(t, err) From aa3e7a01f19c2690419d83c7e753e252cbb24e37 Mon Sep 17 00:00:00 2001 From: Jakub Warczarek Date: Thu, 26 Sep 2024 16:00:11 +0200 Subject: [PATCH 2/2] Update test/integration/test_kongplugininstallation.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Patryk Małek --- test/helpers/generators.go | 4 ++-- test/integration/test_kongplugininstallation.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/helpers/generators.go b/test/helpers/generators.go index 941d3623b..0b7fda068 100644 --- a/test/helpers/generators.go +++ b/test/helpers/generators.go @@ -147,8 +147,8 @@ func GenerateGatewayConfiguration(namespace string, opts ...gatewayConfiguration return gwc } -// WithWebhookDisabled disables the admission webhook for the control plane -func WithWebhookDisabled() func(*operatorv1beta1.GatewayConfiguration) { +// WithControlPlaneWebhookDisabled disables the admission webhook for the control plane +func WithControlPlaneWebhookDisabled() func(*operatorv1beta1.GatewayConfiguration) { return func(gc *operatorv1beta1.GatewayConfiguration) { gc.Spec.ControlPlaneOptions.Deployment.PodTemplateSpec.Spec.Containers[0].Env = append(gc.Spec.ControlPlaneOptions.Deployment.PodTemplateSpec.Spec.Containers[0].Env, corev1.EnvVar{ Name: "CONTROLLER_ADMISSION_WEBHOOK_LISTEN", diff --git a/test/integration/test_kongplugininstallation.go b/test/integration/test_kongplugininstallation.go index 148536c23..3946a9cfa 100644 --- a/test/integration/test_kongplugininstallation.go +++ b/test/integration/test_kongplugininstallation.go @@ -208,8 +208,8 @@ func deployGatewayWithKPI( t *testing.T, cleaner *clusters.Cleaner, namespace string, ) (gatewayIPAddress string, gatewayConfigNN, httpRouteNN k8stypes.NamespacedName) { // NOTE: Disable webhook for KIC, because it checks for the plugin in Kong Gateway and rejects, - // thus it requires strict order of deployment. - gatewayConfig := helpers.GenerateGatewayConfiguration(namespace, helpers.WithWebhookDisabled()) + // thus it requires strict order of deployment which is not guaranteed. + gatewayConfig := helpers.GenerateGatewayConfiguration(namespace, helpers.WithControlPlaneWebhookDisabled()) t.Logf("deploying GatewayConfiguration %s/%s", gatewayConfig.Namespace, gatewayConfig.Name) gatewayConfig, err := GetClients().OperatorClient.ApisV1beta1().GatewayConfigurations(namespace).Create(GetCtx(), gatewayConfig, metav1.CreateOptions{}) require.NoError(t, err)