From 8174ef7b630a9b834d33e7c4c594f1f6d2ee4f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Thu, 28 Nov 2024 19:05:56 +0100 Subject: [PATCH] tests: add installing ingress-controller CRDs in integration tests (#905) --- pkg/utils/test/setup_helpers.go | 39 +++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/pkg/utils/test/setup_helpers.go b/pkg/utils/test/setup_helpers.go index 9c76d5c5..f4ffaf72 100644 --- a/pkg/utils/test/setup_helpers.go +++ b/pkg/utils/test/setup_helpers.go @@ -226,19 +226,10 @@ func DeployCRDs(ctx context.Context, crdPath string, operatorClient *operatorcli return err } - // CRDs for Kong configuration - // First extract version of `kong/kubernetes-configuration` module used - kongCRDVersion, err := ExtractModuleVersion(KubernetesConfigurationModuleName) - if err != nil { - return fmt.Errorf("failed to extract Kong CRDs (%s) module's version: %w", KubernetesConfigurationModuleName, err) - } - // Then install CRDs from the module found in `$GOPATH`. - kongCRDPath := filepath.Join(build.Default.GOPATH, "pkg", "mod", "github.com", "kong", - "kubernetes-configuration@"+kongCRDVersion, "config", "crd", "gateway-operator") - fmt.Printf("INFO: deploying Kong (kubernetes-configuration) CRDs: %s\n", kongCRDPath) - if err := clusters.KustomizeDeployForCluster(ctx, env.Cluster(), kongCRDPath); err != nil { + if err := InstallKubernetesConfigurationCRDs(ctx, env); err != nil { return err } + // CRDs for alpha/experimental features fmt.Printf("INFO: deploying KGO AIGateway CRD: %s\n", crdPath) if err := clusters.ApplyManifestByURL(ctx, env.Cluster(), path.Join(crdPath, AIGatewayCRDPath)); err != nil { @@ -253,6 +244,32 @@ func DeployCRDs(ctx context.Context, crdPath string, operatorClient *operatorcli return nil } +// InstallKubernetesConfigurationCRDs installs the Kong CRDs from the `kong/kubernetes-configuration` module. +// The version is extracted using ExtractModuleVersion from go.mod. +func InstallKubernetesConfigurationCRDs(ctx context.Context, env environments.Environment) error { + // First extract version of `kong/kubernetes-configuration` module used + kongCRDVersion, err := ExtractModuleVersion(KubernetesConfigurationModuleName) + if err != nil { + return fmt.Errorf("failed to extract Kong CRDs (%s) module's version: %w", KubernetesConfigurationModuleName, err) + } + + // NOTE: this installs CRDs from https://github.com/Kong/kubernetes-configuration/tree/f1475e539fa92eb5318a8b0550c6012cfc945893/config/crd + kubernetesConfigurationCRDsDirs := []string{"gateway-operator", "ingress-controller"} + for _, crdDirName := range kubernetesConfigurationCRDsDirs { + // Install CRDs from the module found in `$GOPATH`. + kongCRDPath := filepath.Join( + build.Default.GOPATH, "pkg", "mod", "github.com", "kong", + "kubernetes-configuration@"+kongCRDVersion, "config", "crd", crdDirName, + ) + fmt.Printf("INFO: deploying kubernetes-configuration CRDs: %s\n", kongCRDPath) + if err := clusters.KustomizeDeployForCluster(ctx, env.Cluster(), kongCRDPath); err != nil { + return fmt.Errorf("failed installing kubernetes-configurations (%s) CRDs: %w", kongCRDPath, err) + } + } + + return nil +} + func waitForOperatorCRDs(ctx context.Context, operatorClient *operatorclient.Clientset) error { ready := false for !ready {