Skip to content

Commit

Permalink
chore(tests): disable KIC admission webhook for TestKongPluginInstall…
Browse files Browse the repository at this point in the history
…ationEssentials
  • Loading branch information
programmer04 committed Sep 26, 2024
1 parent 3d3dbf6 commit 7ac5a42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 18 additions & 2 deletions test/helpers/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions test/integration/test_kongplugininstallation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7ac5a42

Please sign in to comment.