From 7ac5a4290be5c3a769eb61f0d88d3bdd77225e4c Mon Sep 17 00:00:00 2001 From: Jakub Warczarek Date: Thu, 26 Sep 2024 13:39:33 +0200 Subject: [PATCH] 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)