From 03b427531fe18776673ebac013f63816c9ca6370 Mon Sep 17 00:00:00 2001 From: Xu Deng Date: Tue, 7 Nov 2023 13:24:18 -0500 Subject: [PATCH] Add docker regional curated packages e2e test (#6964) --- .../buildspecs/docker-test-eks-a-cli.yml | 2 ++ internal/test/e2e/packages.go | 14 +++++++++++-- pkg/executables/kubectl.go | 13 +++++++----- test/e2e/docker_test.go | 20 +++++++++++++++++++ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/cmd/integration_test/build/buildspecs/docker-test-eks-a-cli.yml b/cmd/integration_test/build/buildspecs/docker-test-eks-a-cli.yml index 8dc0edd9582f..1073b2f806e6 100644 --- a/cmd/integration_test/build/buildspecs/docker-test-eks-a-cli.yml +++ b/cmd/integration_test/build/buildspecs/docker-test-eks-a-cli.yml @@ -11,6 +11,8 @@ env: EKSA_AWS_ACCESS_KEY_ID: "packages_ci_beta:aws_access_key_id" EKSA_AWS_SECRET_ACCESS_KEY: "packages_ci_beta:aws_secret_access_key_id" EKSA_AWS_REGION: "packages_ci_beta:aws_region" + REGIONAL_EKSA_AWS_ACCESS_KEY_ID: "packages_ci_beta:regional_aws_access_key_id" + REGIONAL_EKSA_AWS_SECRET_ACCESS_KEY: "packages_ci_beta:regional_aws_secret_access_key_id" EKSA_GITHUB_TOKEN: "github-eks-anywhere-flux-bot:github-token" T_GITHUB_USER: "github-eks-anywhere-flux-bot:github-user" T_GIT_REPOSITORY: "github-eks-anywhere-flux-bot:github-repository" diff --git a/internal/test/e2e/packages.go b/internal/test/e2e/packages.go index bf99fdaf0d54..aa84dc834eaa 100644 --- a/internal/test/e2e/packages.go +++ b/internal/test/e2e/packages.go @@ -8,8 +8,9 @@ import ( ) const ( - packagesRegex = `^.*CuratedPackages.*$` - certManagerRegex = "^.*CuratedPackagesCertManager.*$" + packagesRegex = `^.*CuratedPackages.*$` + regionalPackagesRegex = `^.*RegionalCuratedPackages.*$` + certManagerRegex = "^.*CuratedPackagesCertManager.*$" ) func (e *E2ESession) setupPackagesEnv(testRegex string) error { @@ -24,6 +25,15 @@ func (e *E2ESession) setupPackagesEnv(testRegex string) error { e.testEnvVars[eVar] = val } } + + // overwrite envs for regional curated packages test + if regexp.MustCompile(regionalPackagesRegex).MatchString(testRegex) { + for _, eVar := range requiredEnvVars { + if val, ok := os.LookupEnv("REGIONAL_" + eVar); ok { + e.testEnvVars[eVar] = val + } + } + } return nil } diff --git a/pkg/executables/kubectl.go b/pkg/executables/kubectl.go index 8639e786b753..9e3a612c741c 100644 --- a/pkg/executables/kubectl.go +++ b/pkg/executables/kubectl.go @@ -695,13 +695,16 @@ func (k *Kubectl) DeleteFluxConfig(ctx context.Context, managementCluster *types // GetPackageBundleController will retrieve the packagebundlecontroller from eksa-packages namespace and return the object. func (k *Kubectl) GetPackageBundleController(ctx context.Context, kubeconfigFile, clusterName string) (packagesv1.PackageBundleController, error) { params := []string{"get", eksaPackagesBundleControllerType, clusterName, "-o", "json", "--kubeconfig", kubeconfigFile, "--namespace", constants.EksaPackagesName, "--ignore-not-found=true"} - stdOut, _ := k.Execute(ctx, params...) - response := &packagesv1.PackageBundleController{} - err := json.Unmarshal(stdOut.Bytes(), response) + stdOut, err := k.Execute(ctx, params...) + if err != nil { + return packagesv1.PackageBundleController{}, fmt.Errorf("failed to execute cmd \"%s\": %w", strings.Join(params, " "), err) + } + pbc := &packagesv1.PackageBundleController{} + err = json.Unmarshal(stdOut.Bytes(), pbc) if err != nil { - return packagesv1.PackageBundleController{}, fmt.Errorf("unmarshalling kubectl response to GO struct %s: %v", clusterName, err) + return packagesv1.PackageBundleController{}, fmt.Errorf("unmarshalling kubectl response to GO struct %s: %v, response: %s", clusterName, err, stdOut.String()) } - return *response, nil + return *pbc, nil } // GetPackageBundleList will retrieve the packagebundle list from eksa-packages namespace and return the list. diff --git a/test/e2e/docker_test.go b/test/e2e/docker_test.go index 9e5593c002e9..557954faa961 100644 --- a/test/e2e/docker_test.go +++ b/test/e2e/docker_test.go @@ -1298,3 +1298,23 @@ func TestDockerCiliumSkipUpgrade_ControllerUpgrade(t *testing.T) { test.ManagementCluster.StopIfFailed() test.DeleteManagementCluster() } + +func TestDockerKubernetesRegionalCuratedPackages(t *testing.T) { + framework.CheckCuratedPackagesCredentials(t) + test := framework.NewClusterE2ETest(t, + framework.NewDocker(t), + framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube128)), + ) + + test.WithCluster(func(e *framework.ClusterE2ETest) { + runCuratedPackageInstall(e) + + pbc, err := test.KubectlClient.GetPackageBundleController(context.Background(), test.KubeconfigFilePath(), test.ClusterName) + if err != nil { + e.T.Fatalf("cannot get PackageBundleController: %v", err) + } + if pbc.Spec.DefaultImageRegistry != pbc.Spec.DefaultRegistry { + e.T.Fatal("in regional pbc, DefaultImageRegistry should equal to DefaultRegistry") + } + }) +}