diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 731ade52e..18756f48e 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -97,6 +97,7 @@ jobs: GINKGO_LABEL_FILTER: 'controller' MANAGED_CLUSTER_NAME: ${{ needs.build.outputs.clustername }} IMG: 'ghcr.io/mirantis/hmc/controller-ci:${{ needs.build.outputs.version }}' + VERSION: ${{ needs.build.outputs.version }} run: | make test-e2e - name: Archive test results @@ -115,8 +116,10 @@ jobs: concurrency: group: cloud-e2e-${{ github.head_ref || github.run_id }} cancel-in-progress: true + outputs: + clustername: ${{ needs.build.outputs.clustername }} + version: ${{ needs.build.outputs.version }} env: - GINKGO_LABEL_FILTER: 'provider:cloud' AWS_REGION: us-west-2 AWS_ACCESS_KEY_ID: ${{ secrets.CI_AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_AWS_SECRET_ACCESS_KEY }} @@ -124,8 +127,6 @@ jobs: AZURE_TENANT_ID: ${{ secrets.CI_AZURE_TENANT_ID }} AZURE_CLIENT_ID: ${{ secrets.CI_AZURE_CLIENT_ID }} AZURE_CLIENT_SECRET: ${{ secrets.CI_AZURE_CLIENT_SECRET }} - clustername: ${{ needs.build.outputs.clustername }} - version: ${{ needs.build.outputs.version }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -144,8 +145,10 @@ jobs: detached: true - name: Run E2E tests env: + GINKGO_LABEL_FILTER: 'provider:cloud' MANAGED_CLUSTER_NAME: ${{ needs.build.outputs.clustername }} IMG: 'ghcr.io/mirantis/hmc/controller-ci:${{ needs.build.outputs.version }}' + VERSION: ${{ needs.build.outputs.version }} run: | make test-e2e - name: Archive test results @@ -168,7 +171,6 @@ jobs: clustername: ${{ needs.build.outputs.clustername }} version: ${{ needs.build.outputs.version }} env: - GINKGO_LABEL_FILTER: 'provider:onprem' VSPHERE_USER: ${{ secrets.CI_VSPHERE_USER }} VSPHERE_PASSWORD: ${{ secrets.CI_VSPHERE_PASSWORD }} VSPHERE_SERVER: ${{ secrets.CI_VSPHERE_SERVER }} @@ -193,8 +195,10 @@ jobs: uses: azure/setup-kubectl@v4 - name: Run E2E tests env: + GINKGO_LABEL_FILTER: 'provider:onprem' MANAGED_CLUSTER_NAME: ${{ needs.build.outputs.clustername }} IMG: 'ghcr.io/mirantis/hmc/controller-ci:${{ needs.build.outputs.version }}' + VERSION: ${{ needs.build.outputs.version }} run: | make test-e2e - name: Archive test results diff --git a/test/e2e/managedcluster/clusteridentity/clusteridentity.go b/test/e2e/managedcluster/clusteridentity/clusteridentity.go index bd483c176..a02ad1106 100644 --- a/test/e2e/managedcluster/clusteridentity/clusteridentity.go +++ b/test/e2e/managedcluster/clusteridentity/clusteridentity.go @@ -32,11 +32,11 @@ import ( ) type ClusterIdentity struct { - Resource string - Kind string - SecretName string - IdentityName string - SecretData map[string]string + GroupVersionResource schema.GroupVersionResource + Kind string + SecretName string + IdentityName string + SecretData map[string]string } // New creates a ClusterIdentity resource and associated secret for the given @@ -48,6 +48,7 @@ func New(kc *kubeclient.KubeClient, provider managedcluster.ProviderType) *Clust var ( resource string kind string + version string secretStringData map[string]string ) @@ -55,6 +56,7 @@ func New(kc *kubeclient.KubeClient, provider managedcluster.ProviderType) *Clust case managedcluster.ProviderAWS: resource = "awsclusterstaticidentities" kind = "AWSClusterStaticIdentity" + version = "v1beta2" secretStringData = map[string]string{ "AccessKeyID": os.Getenv(managedcluster.EnvVarAWSAccessKeyID), "SecretAccessKey": os.Getenv(managedcluster.EnvVarAWSSecretAccessKey), @@ -62,12 +64,14 @@ func New(kc *kubeclient.KubeClient, provider managedcluster.ProviderType) *Clust case managedcluster.ProviderAzure: resource = "azureclusterstaticidentities" kind = "AzureClusterStaticIdentity" + version = "v1beta1" secretStringData = map[string]string{ "clientSecret": os.Getenv(managedcluster.EnvVarAzureClientSecret), } case managedcluster.ProviderVSphere: resource = "vsphereclusteridentities" kind = "VSphereClusterIdentity" + version = "v1beta1" secretStringData = map[string]string{ "username": os.Getenv(managedcluster.EnvVarVSphereUser), "password": os.Getenv(managedcluster.EnvVarVSpherePassword), @@ -76,17 +80,22 @@ func New(kc *kubeclient.KubeClient, provider managedcluster.ProviderType) *Clust Fail(fmt.Sprintf("Unsupported provider: %s", provider)) } - waitForResourceCRD(kc, resource) + By(fmt.Sprintf("waiting for %s CRD to be present", resource)) validateSecretDataPopulated(secretStringData) ci := ClusterIdentity{ - Resource: resource, + GroupVersionResource: schema.GroupVersionResource{ + Group: "infrastructure.cluster.x-k8s.io", + Version: version, + Resource: resource, + }, Kind: kind, SecretName: fmt.Sprintf("%s-cluster-identity-secret", provider), IdentityName: fmt.Sprintf("%s-cluster-identity", provider), SecretData: secretStringData, } + ci.waitForResourceCRD(kc) ci.createSecret(kc) ci.createClusterIdentity(kc) @@ -101,23 +110,17 @@ func validateSecretDataPopulated(secretData map[string]string) { // waitForResourceCRD ensures the CRD for the given resource is present by // trying to list the resources of the given type until it succeeds. -func waitForResourceCRD(kc *kubeclient.KubeClient, resource string) { +func (ci *ClusterIdentity) waitForResourceCRD(kc *kubeclient.KubeClient) { GinkgoHelper() ctx := context.Background() client, err := dynamic.NewForConfig(kc.Config) Expect(err).NotTo(HaveOccurred()) - gvr := schema.GroupVersionResource{ - Group: "infrastructure.cluster.x-k8s.io", - Version: "v1beta2", - Resource: resource, - } - Eventually(func() bool { - _, err := client.Resource(gvr).List(ctx, metav1.ListOptions{}) + _, err := client.Resource(ci.GroupVersionResource).List(ctx, metav1.ListOptions{}) return err == nil - }, "1m", "5s").Should(BeTrue(), "failed to list %s resources", resource) + }, "1m", "5s").Should(BeTrue(), "failed to list %s", ci.GroupVersionResource.String()) } // createSecret creates a secret affiliated with a ClusterIdentity. @@ -156,12 +159,6 @@ func (ci *ClusterIdentity) createClusterIdentity(kc *kubeclient.KubeClient) { client, err := dynamic.NewForConfig(kc.Config) Expect(err).NotTo(HaveOccurred(), "failed to create dynamic client") - gvr := schema.GroupVersionResource{ - Group: "infrastructure.cluster.x-k8s.io", - Version: "v1beta2", - Resource: ci.Resource, - } - clusterIdentity := &unstructured.Unstructured{ Object: map[string]any{ "apiVersion": "infrastructure.cluster.x-k8s.io/v1beta2", @@ -181,7 +178,7 @@ func (ci *ClusterIdentity) createClusterIdentity(kc *kubeclient.KubeClient) { }, } - if ci.Resource == "azureclusterstaticidentities" { + if ci.GroupVersionResource.Resource == "azureclusterstaticidentities" { err = unstructured.SetNestedField(clusterIdentity.Object, os.Getenv(managedcluster.EnvVarAzureTenantID), "spec", "tenantID") Expect(err).NotTo(HaveOccurred()) @@ -202,13 +199,13 @@ func (ci *ClusterIdentity) createClusterIdentity(kc *kubeclient.KubeClient) { } } - _, err = client.Resource(gvr).Create(ctx, clusterIdentity, metav1.CreateOptions{}) + _, err = client.Resource(ci.GroupVersionResource).Create(ctx, clusterIdentity, metav1.CreateOptions{}) if apierrors.IsAlreadyExists(err) { - resp, err := client.Resource(gvr).Get(ctx, ci.IdentityName, metav1.GetOptions{}) + resp, err := client.Resource(ci.GroupVersionResource).Get(ctx, ci.IdentityName, metav1.GetOptions{}) Expect(err).NotTo(HaveOccurred()) clusterIdentity.SetResourceVersion(resp.GetResourceVersion()) - _, err = client.Resource(gvr).Update(ctx, clusterIdentity, metav1.UpdateOptions{}) + _, err = client.Resource(ci.GroupVersionResource).Update(ctx, clusterIdentity, metav1.UpdateOptions{}) Expect(err).NotTo(HaveOccurred(), "failed to create cluster identity") } else { Expect(err).NotTo(HaveOccurred())