diff --git a/.github/workflows/aks.yaml b/.github/workflows/aks.yaml index 149af7f8..5d76eafc 100644 --- a/.github/workflows/aks.yaml +++ b/.github/workflows/aks.yaml @@ -41,7 +41,7 @@ on: type: boolean runner_template: description: Runner template to use - default: hosted-prov-e2e-ci-runner-spot-x86-64-template-n2-highmem-32-v2 + default: hosted-prov-e2e-ci-runner-spot-n2-highmem-16-gl-template-v1 type: string jobs: diff --git a/.github/workflows/eks.yaml b/.github/workflows/eks.yaml index 116c2c00..839ae277 100644 --- a/.github/workflows/eks.yaml +++ b/.github/workflows/eks.yaml @@ -41,7 +41,7 @@ on: type: boolean runner_template: description: Runner template to use - default: hosted-prov-e2e-ci-runner-spot-x86-64-template-n2-highmem-32-v2 + default: hosted-prov-e2e-ci-runner-spot-n2-highmem-16-gl-template-v1 type: string jobs: @@ -59,4 +59,3 @@ jobs: run_support_matrix_importing_tests: ${{ inputs.run_support_matrix_importing_tests == true }} destroy_runner: ${{ inputs.destroy_runner == true }} runner_template: ${{ inputs.runner_template }} - diff --git a/.github/workflows/gke.yaml b/.github/workflows/gke.yaml index d68ab507..fa77c60a 100644 --- a/.github/workflows/gke.yaml +++ b/.github/workflows/gke.yaml @@ -42,7 +42,7 @@ on: type: boolean runner_template: description: Runner template to use - default: hosted-prov-e2e-ci-runner-spot-x86-64-template-n2-highmem-32-v2 + default: hosted-prov-e2e-ci-runner-spot-n2-highmem-16-gl-template-v1 type: string jobs: diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 93c9eca0..d1f49846 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -37,11 +37,7 @@ on: type: boolean runner_template: description: Runner template to use - default: hosted-prov-e2e-ci-runner-spot-x86-64-template-n2-highmem-32-v2 - type: string - zone: - description: GCP zone to host the runner - default: us-west1-b + default: hosted-prov-e2e-ci-runner-spot-n2-highmem-16-gl-template-v1 type: string env: @@ -57,7 +53,7 @@ env: PROVIDER: ${{ inputs.hosted_provider }} RANCHER_PASSWORD: rancherpassword RANCHER_LOG_COLLECTOR: ${{ github.workspace }}/.github/scripts/collect-rancher-logs.sh - + GCP_RUNNER_ZONE: asia-south2-c jobs: create-runner: runs-on: ubuntu-latest @@ -84,13 +80,14 @@ jobs: uses: google-github-actions/setup-gcloud@v1 - name: Create runner run: | + REGION=$(echo ${{ env.GCP_RUNNER_ZONE }} | sed 's/-[abcdef]$//') gcloud compute instances create ${{ steps.generator.outputs.runner }} \ - --zone ${{ inputs.zone }} \ - --source-instance-template ${{ inputs.runner_template }} &> /dev/null + --zone ${{ env.GCP_RUNNER_ZONE }} \ + --source-instance-template projects/${{ env.GKE_PROJECT_ID }}/regions/${REGION}/instanceTemplates/${{ inputs.runner_template }} - name: Allow traffic run: | gcloud compute instances add-tags ${{ steps.generator.outputs.runner }} \ - --tags http-server,https-server --zone ${{ inputs.zone }} + --tags http-server,https-server --zone ${{ env.GCP_RUNNER_ZONE }} - name: Create GCP secrets run: | echo -n ${{ secrets.PAT_TOKEN }} \ @@ -229,4 +226,4 @@ jobs: run: | gcloud --quiet compute instances delete ${{ needs.create-runner.outputs.runner }} \ --delete-disks all \ - --zone ${{ inputs.zone }} + --zone ${{ env.GCP_RUNNER_ZONE }} diff --git a/README.md b/README.md index a65e03d7..93c62ce0 100644 --- a/README.md +++ b/README.md @@ -21,30 +21,57 @@ To run GKE: - Project: Viewer (roles/viewer) - Kubernetes Engine: Kubernetes Engine Admin (roles/container.admin) - Service Accounts: Service Account User (roles/iam.serviceAccountUser) - 2. GKE_PROJECT_ID - Name of the Google Cloud Project +3. GKE_ZONE - Zone in which GKE must be provisioned (default: 'asia-south2-c'). This environment variable takes precedence over the config file variable. To run EKS: 1. AWS_ACCESS_KEY_ID - AWS Access Key 2. AWS_SECRET_ACCESS_KEY - AWS Secret Key -3. EKS_REGION - Default Region (default: us-west-2) +3. EKS_REGION - Region in which EKS must be provisioned (default: 'ap-south-1'). This environment variable takes precedence over the config file variable. To run AKS: 1. AKS_CLIENT_ID - Azure Client ID [Check Microsoft Entra ID to create or fetch value from an existing one](https://learn.microsoft.com/en-us/entra/identity-platform/howto-create-service-principal-portal) 2. AKS_CLIENT_SECRET - Azure Client Secret [Check Microsoft Entra ID to create or fetch value from an existing one](https://learn.microsoft.com/en-us/entra/identity-platform/howto-create-service-principal-portal) 3. AKS_SUBSCRIPTION_ID - Azure Subscription ID (In this case it is similar to a Google Cloud Project, but the value is an ID). [Check Azure Subscriptions](https://learn.microsoft.com/en-us/microsoft-365/enterprise/subscriptions-licenses-accounts-and-tenants-for-microsoft-cloud-offerings?view=o365-worldwide#subscriptions) +4. AKS_REGION - Region in which AKS must be provisioned (default: 'centralindia'). This environment variable takes precedence over the config file variable. - +**Note:** It is advisable that all the Hosted Provider cluster be provisioned in APAC region, this is because we want to geolocalize all the resources created by hosted provider. ### Makefile targets to run tests -1. `make e2e-provisioning-tests` - Covers the _P0Provisioning_ test suite for a given ${PROVIDER} -2. `make e2e-import-tests` - Covers the _P0Importing_ test suite for a given ${PROVIDER} -3. `make e2e-support-matrix-importing-tests` - Covers the _SupportMatrixImporting_ test suite for a given ${PROVIDER} -4. `make e2e-support-matrix-provisioning-tests` - Covers the _SupportMatrixProvisioning_ test suite for a given ${PROVIDER} +1. `make e2e-provisioning-tests` - Covers the _P0Provisioning_ test suite for a given `${PROVIDER}` +2. `make e2e-import-tests` - Covers the _P0Importing_ test suite for a given `${PROVIDER}` +3. `make e2e-support-matrix-importing-tests` - Covers the _SupportMatrixImporting_ test suite for a given `${PROVIDER}` +4. `make e2e-support-matrix-provisioning-tests` - Covers the _SupportMatrixProvisioning_ test suite for a given `${PROVIDER}` Run `make help` to know about other targets. ### Example +**GKE Provisioning Tests** +```shell +GKE_PROJECT_ID=some-project GCP_CREDENTIALS= PROVIDER=gke RANCHER_HOSTNAME=ec2-1-2-3-4.ap-south-1.compute.amazonaws.com RANCHER_PASSWORD=admin123 CATTLE_TEST_CONFIG=/home/pvala/go/src/github.com/rancher/hosted-providers-e2e/hosted/gke/cattle-config-provisioning.yaml make e2e-provisioning-tests +``` + +**GKE Import Tests** +```shell +GKE_PROJECT_ID=some-project GCP_CREDENTIALS= PROVIDER=gke RANCHER_HOSTNAME=ec2-1-2-3-4.ap-south-1.compute.amazonaws.com RANCHER_PASSWORD=admin123 CATTLE_TEST_CONFIG=/home/pvala/go/src/github.com/rancher/hosted-providers-e2e/hosted/gke/cattle-config-import.yaml make e2e-import-tests +``` + +**EKS Provisioning Tests** +```shell +EKS_REGION=ap-south-1 AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= PROVIDER=eks RANCHER_HOSTNAME=ec2-1-2-3-4.ap-south-1.compute.amazonaws.com RANCHER_PASSWORD=admin123 CATTLE_TEST_CONFIG=/home/pvala/go/src/github.com/rancher/hosted-providers-e2e/hosted/gke/cattle-config-provisioning.yaml make e2e-provisioning-tests +``` + +**EKS Import Tests** +```shell +EKS_REGION=ap-south-1 AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= PROVIDER=eks RANCHER_HOSTNAME=ec2-1-2-3-4.ap-south-1.compute.amazonaws.com RANCHER_PASSWORD=admin123 CATTLE_TEST_CONFIG=/home/pvala/go/src/github.com/rancher/hosted-providers-e2e/hosted/gke/cattle-config-import.yaml make e2e-import-tests +``` + +**AKS Provisioning Tests** +```shell +AKS_REGION=centralindia AKS_CLIENT_ID= AKS_CLIENT_SECRET= AKS_SUBSCRIPTION_ID= PROVIDER=aks RANCHER_HOSTNAME=ec2-1-2-3-4.ap-south-1.compute.amazonaws.com RANCHER_PASSWORD=admin123 CATTLE_TEST_CONFIG=/home/pvala/go/src/github.com/rancher/hosted-providers-e2e/hosted/gke/cattle-config-provisioning.yaml make e2e-provisioning-tests +``` + +**AKS Import Tests** ```shell -PROVIDER=gke RANCHER_HOSTNAME=ec2-1-2-3-4.ap-south-1.compute.amazonaws.com CATTLE_TEST_CONFIG=/home/pvala/go/src/github.com/rancher/hosted-providers-e2e/hosted/gke/config make e2e-provisioning-tests +AKS_REGION=centralindia AKS_CLIENT_ID= AKS_CLIENT_SECRET= AKS_SUBSCRIPTION_ID= PROVIDER=aks RANCHER_HOSTNAME=ec2-1-2-3-4.ap-south-1.compute.amazonaws.com RANCHER_PASSWORD=admin123 CATTLE_TEST_CONFIG=/home/pvala/go/src/github.com/rancher/hosted-providers-e2e/hosted/gke/cattle-config-import.yaml make e2e-import-tests ``` diff --git a/cattle-config-import.yaml b/cattle-config-import.yaml index 97b1be8a..e3da5eef 100644 --- a/cattle-config-import.yaml +++ b/cattle-config-import.yaml @@ -15,7 +15,7 @@ aksClusterConfig: osType: Linux vmSize: Standard_DS2_v2 resourceGroup: "" - resourceLocation: eastus + resourceLocation: centralindia awsCredentials: azureCredentials: environment: AzurePublicCloud @@ -39,10 +39,10 @@ eksClusterConfig: subnets: [] tags: {} userData: "" - region: ca-central-1 + region: ap-south-1 gkeClusterConfig: projectID: - zone: us-central1-c + zone: asia-south2-c imported: true nodePools: - autoscaling: {} diff --git a/cattle-config-provisioning.yaml b/cattle-config-provisioning.yaml index 60ade652..d14febf3 100644 --- a/cattle-config-provisioning.yaml +++ b/cattle-config-provisioning.yaml @@ -21,8 +21,8 @@ aksClusterConfig: vmSize: Standard_DS2_v2 privateCluster: false resourceGroup: "" - resourceLocation: eastus - tags: {} + resourceLocation: centralindia +tags: {} awsCredentials: azureCredentials: environment: AzurePublicCloud @@ -51,7 +51,7 @@ eksClusterConfig: privateAccess: false publicAccess: true publicAccessSources: [] - region: us-east-2 + region: ap-south-1 secretsEncryption: false securityGroups: [] serviceRole: "" @@ -120,7 +120,7 @@ gkeClusterConfig: masterIpv4CidrBlock: "" region: "" subnetwork: default - zone: us-central1-c + zone: asia-south2-c projectID: googleCredentials: rancher: diff --git a/hosted/aks/p0/p0_importing_test.go b/hosted/aks/p0/p0_importing_test.go index 13409c5c..796a9cd8 100644 --- a/hosted/aks/p0/p0_importing_test.go +++ b/hosted/aks/p0/p0_importing_test.go @@ -16,7 +16,9 @@ import ( ) var _ = Describe("P0Importing", func() { - + var ( + location = helpers.GetAKSLocation() + ) When("a cluster is imported", func() { var cluster *management.Cluster diff --git a/hosted/aks/p0/p0_suite_test.go b/hosted/aks/p0/p0_suite_test.go index 4d16daa0..5d838e7f 100644 --- a/hosted/aks/p0/p0_suite_test.go +++ b/hosted/aks/p0/p0_suite_test.go @@ -12,7 +12,6 @@ import ( var ( ctx helpers.Context clusterName string - location = "eastus" k8sVersion = "1.26.6" increaseBy = 1 ) diff --git a/hosted/aks/support_matrix/support_matrix_importing_test.go b/hosted/aks/support_matrix/support_matrix_importing_test.go index a481e873..e4791792 100644 --- a/hosted/aks/support_matrix/support_matrix_importing_test.go +++ b/hosted/aks/support_matrix/support_matrix_importing_test.go @@ -1,11 +1,10 @@ package support_matrix_test import ( + "fmt" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "fmt" - management "github.com/rancher/rancher/tests/framework/clients/rancher/generated/management/v3" "github.com/rancher/rancher/tests/framework/extensions/clusters" "github.com/rancher/rancher/tests/framework/extensions/clusters/aks" @@ -26,7 +25,6 @@ var _ = Describe("SupportMatrixImporting", func() { When(fmt.Sprintf("a cluster is created with kubernetes version %s", version), func() { var ( clusterName string - location = "eastus" cluster *management.Cluster ) BeforeEach(func() { diff --git a/hosted/aks/support_matrix/support_matrix_suite_test.go b/hosted/aks/support_matrix/support_matrix_suite_test.go index 06f2b106..cfed3190 100644 --- a/hosted/aks/support_matrix/support_matrix_suite_test.go +++ b/hosted/aks/support_matrix/support_matrix_suite_test.go @@ -13,6 +13,7 @@ import ( var ( availableVersionList []string ctx helpers.Context + location = helpers.GetAKSLocation() ) func TestSupportMatrix(t *testing.T) { @@ -20,7 +21,7 @@ func TestSupportMatrix(t *testing.T) { var err error ctx, err = helpers.CommonBeforeSuite("aks") Expect(err).To(BeNil()) - availableVersionList, err = helper.ListSingleVariantAKSAvailableVersions(ctx.RancherClient, ctx.CloudCred.ID, "eastus") + availableVersionList, err = helper.ListSingleVariantAKSAvailableVersions(ctx.RancherClient, ctx.CloudCred.ID, location) Expect(err).To(BeNil()) RunSpecs(t, "SupportMatrix Suite") } diff --git a/hosted/eks/p0/p0_importing_test.go b/hosted/eks/p0/p0_importing_test.go index 0c34798e..aae7a026 100644 --- a/hosted/eks/p0/p0_importing_test.go +++ b/hosted/eks/p0/p0_importing_test.go @@ -14,7 +14,10 @@ import ( ) var _ = Describe("P0Importing", func() { - var cluster *management.Cluster + var ( + cluster *management.Cluster + region = helpers.GetEKSRegion() + ) When("a cluster is imported", func() { diff --git a/hosted/eks/p0/p0_suite_test.go b/hosted/eks/p0/p0_suite_test.go index b7154093..8292270f 100644 --- a/hosted/eks/p0/p0_suite_test.go +++ b/hosted/eks/p0/p0_suite_test.go @@ -1,7 +1,6 @@ package p0_test import ( - "os" "testing" . "github.com/onsi/ginkgo/v2" @@ -13,7 +12,6 @@ import ( var ( ctx helpers.Context clusterName string - region = os.Getenv("EKS_REGION") k8sVersion = "1.26" increaseBy = 1 ) diff --git a/hosted/eks/support_matrix/support_matrix_importing_test.go b/hosted/eks/support_matrix/support_matrix_importing_test.go index 25eca87a..d4722bf6 100644 --- a/hosted/eks/support_matrix/support_matrix_importing_test.go +++ b/hosted/eks/support_matrix/support_matrix_importing_test.go @@ -1,8 +1,6 @@ package support_matrix_test import ( - "os" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -26,7 +24,6 @@ var _ = Describe("SupportMatrixImporting", func() { When(fmt.Sprintf("a cluster is created with kubernetes version %s", version), func() { var ( clusterName string - region = os.Getenv("EKS_REGION") cluster *management.Cluster ) BeforeEach(func() { diff --git a/hosted/eks/support_matrix/support_matrix_suite_test.go b/hosted/eks/support_matrix/support_matrix_suite_test.go index 2fbb33b3..178ee046 100644 --- a/hosted/eks/support_matrix/support_matrix_suite_test.go +++ b/hosted/eks/support_matrix/support_matrix_suite_test.go @@ -13,6 +13,7 @@ import ( var ( availableVersionList []string ctx helpers.Context + region = helpers.GetEKSRegion() ) func TestSupportMatrix(t *testing.T) { diff --git a/hosted/gke/p0/p0_importing_test.go b/hosted/gke/p0/p0_importing_test.go index f027fe9b..f935d130 100644 --- a/hosted/gke/p0/p0_importing_test.go +++ b/hosted/gke/p0/p0_importing_test.go @@ -8,26 +8,23 @@ import ( "github.com/rancher/hosted-providers-e2e/hosted/helpers" management "github.com/rancher/rancher/tests/framework/clients/rancher/generated/management/v3" "github.com/rancher/rancher/tests/framework/extensions/clusters" - "github.com/rancher/rancher/tests/framework/extensions/clusters/gke" nodestat "github.com/rancher/rancher/tests/framework/extensions/nodes" "github.com/rancher/rancher/tests/framework/extensions/workloads/pods" - "github.com/rancher/rancher/tests/framework/pkg/config" ) var _ = Describe("P0Importing", func() { + var ( + zone = helpers.GetGKEZone() + ) When("a cluster is created", func() { var cluster *management.Cluster BeforeEach(func() { var err error - err = helper.CreateGKEClusterOnGCloud(zone, clusterName, project, k8sVersion) + err = helper.CreateGKEClusterOnGCloud(zone, clusterName, helpers.GetGKEProjectID(), k8sVersion) Expect(err).To(BeNil()) - gkeConfig := new(helper.ImportClusterConfig) - config.LoadAndUpdateConfig(gke.GKEClusterConfigConfigurationFileKey, gkeConfig, func() { - gkeConfig.ProjectID = project - }) cluster, err = helper.ImportGKEHostedCluster(ctx.RancherClient, clusterName, ctx.CloudCred.ID, false, false, false, false, map[string]string{}) Expect(err).To(BeNil()) cluster, err = helpers.WaitUntilClusterIsReady(cluster, ctx.RancherClient) diff --git a/hosted/gke/p0/p0_provisioning_test.go b/hosted/gke/p0/p0_provisioning_test.go index 63730525..3b666e78 100644 --- a/hosted/gke/p0/p0_provisioning_test.go +++ b/hosted/gke/p0/p0_provisioning_test.go @@ -4,15 +4,13 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/rancher/hosted-providers-e2e/hosted/gke/helper" + "github.com/rancher/hosted-providers-e2e/hosted/helpers" management "github.com/rancher/rancher/tests/framework/clients/rancher/generated/management/v3" "github.com/rancher/rancher/tests/framework/extensions/clusters" "github.com/rancher/rancher/tests/framework/extensions/clusters/gke" nodestat "github.com/rancher/rancher/tests/framework/extensions/nodes" "github.com/rancher/rancher/tests/framework/extensions/workloads/pods" - "github.com/rancher/rancher/tests/framework/pkg/config" - - "github.com/rancher/hosted-providers-e2e/hosted/gke/helper" - "github.com/rancher/hosted-providers-e2e/hosted/helpers" ) var _ = Describe("P0Provisioning", func() { @@ -22,11 +20,6 @@ var _ = Describe("P0Provisioning", func() { BeforeEach(func() { var err error - gkeConfig := new(management.GKEClusterConfigSpec) - config.LoadAndUpdateConfig(gke.GKEClusterConfigConfigurationFileKey, gkeConfig, func() { - gkeConfig.ProjectID = project - }) - cluster, err = gke.CreateGKEHostedCluster(ctx.RancherClient, clusterName, ctx.CloudCred.ID, false, false, false, false, map[string]string{}) Expect(err).To(BeNil()) cluster, err = helpers.WaitUntilClusterIsReady(cluster, ctx.RancherClient) diff --git a/hosted/gke/p0/p0_suite_test.go b/hosted/gke/p0/p0_suite_test.go index f5c0c7f4..dc58f0a2 100644 --- a/hosted/gke/p0/p0_suite_test.go +++ b/hosted/gke/p0/p0_suite_test.go @@ -1,7 +1,6 @@ package p0_test import ( - "os" "testing" . "github.com/onsi/ginkgo/v2" @@ -13,8 +12,6 @@ import ( var ( ctx helpers.Context clusterName string - zone = "us-central1-c" - project = os.Getenv("GKE_PROJECT_ID") k8sVersion = "1.27.4-gke.900" increaseBy = 1 ) diff --git a/hosted/gke/support_matrix/support_matrix_importing_test.go b/hosted/gke/support_matrix/support_matrix_importing_test.go index 58ed94f2..9ba54725 100644 --- a/hosted/gke/support_matrix/support_matrix_importing_test.go +++ b/hosted/gke/support_matrix/support_matrix_importing_test.go @@ -1,8 +1,6 @@ package support_matrix_test import ( - "os" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -29,8 +27,6 @@ var _ = Describe("SupportMatrixImporting", func() { var ( clusterName string cluster *management.Cluster - project = os.Getenv("GKE_PROJECT_ID") - zone = "us-central1-c" ) BeforeEach(func() { clusterName = namegen.AppendRandomString("gkehostcluster") diff --git a/hosted/gke/support_matrix/support_matrix_provisioning_test.go b/hosted/gke/support_matrix/support_matrix_provisioning_test.go index a1eedc4d..947e9265 100644 --- a/hosted/gke/support_matrix/support_matrix_provisioning_test.go +++ b/hosted/gke/support_matrix/support_matrix_provisioning_test.go @@ -1,8 +1,6 @@ package support_matrix_test import ( - "os" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -31,7 +29,6 @@ var _ = Describe("SupportMatrixProvisioning", func() { var ( clusterName string cluster *management.Cluster - project = os.Getenv("GKE_PROJECT_ID") ) BeforeEach(func() { clusterName = namegen.AppendRandomString("gkehostcluster") diff --git a/hosted/gke/support_matrix/support_matrix_suite_test.go b/hosted/gke/support_matrix/support_matrix_suite_test.go index 8d94b1e3..6e388599 100644 --- a/hosted/gke/support_matrix/support_matrix_suite_test.go +++ b/hosted/gke/support_matrix/support_matrix_suite_test.go @@ -16,6 +16,7 @@ var ( availableVersionList []string ctx helpers.Context project = os.Getenv("GKE_PROJECT_ID") + zone = helpers.GetGKEZone() ) func TestSupportMatrix(t *testing.T) { @@ -23,7 +24,7 @@ func TestSupportMatrix(t *testing.T) { var err error ctx, err = helpers.CommonBeforeSuite("gke") Expect(err).To(BeNil()) - availableVersionList, err = helper.ListSingleVariantGKEAvailableVersions(ctx.RancherClient, project, ctx.CloudCred.ID, "", "us-central1") + availableVersionList, err = helper.ListSingleVariantGKEAvailableVersions(ctx.RancherClient, project, ctx.CloudCred.ID, zone, "") Expect(err).To(BeNil()) RunSpecs(t, "SupportMatrix Suite") } diff --git a/hosted/helpers/helper_common.go b/hosted/helpers/helper_common.go index 483d5fc2..42ed9709 100644 --- a/hosted/helpers/helper_common.go +++ b/hosted/helpers/helper_common.go @@ -77,15 +77,26 @@ func CommonBeforeSuite(cloud string) (Context, error) { }) cloudCredential, err = azure.CreateAzureCloudCredentials(rancherClient) Expect(err).To(BeNil()) + + azureClusterConfig := new(management.AKSClusterConfigSpec) + // provisioning test cases rely on config file to fetch the location information + // this is necessary so that there is a single source of truth for provisioning and import test cases + config.LoadAndUpdateConfig("azureClusterConfig", azureClusterConfig, func() { + azureClusterConfig.ResourceLocation = GetAKSLocation() + }) case "eks": credentialConfig := new(cloudcredentials.AmazonEC2CredentialConfig) config.LoadAndUpdateConfig("awsCredentials", credentialConfig, func() { credentialConfig.AccessKey = os.Getenv("AWS_ACCESS_KEY_ID") credentialConfig.SecretKey = os.Getenv("AWS_SECRET_ACCESS_KEY") - credentialConfig.DefaultRegion = os.Getenv("EKS_REGION") + credentialConfig.DefaultRegion = GetEKSRegion() }) cloudCredential, err = aws.CreateAWSCloudCredentials(rancherClient) Expect(err).To(BeNil()) + eksClusterConfig := new(management.EKSClusterConfigSpec) + config.LoadAndUpdateConfig("eksClusterConfig", eksClusterConfig, func() { + eksClusterConfig.Region = GetEKSRegion() + }) case "gke": credentialConfig := new(cloudcredentials.GoogleCredentialConfig) config.LoadAndUpdateConfig("googleCredentials", credentialConfig, func() { @@ -93,6 +104,11 @@ func CommonBeforeSuite(cloud string) (Context, error) { }) cloudCredential, err = google.CreateGoogleCloudCredentials(rancherClient) Expect(err).To(BeNil()) + gkeClusterConfig := new(management.GKEClusterConfigSpec) + config.LoadAndUpdateConfig("gkeClusterConfig", gkeClusterConfig, func() { + gkeClusterConfig.Zone = GetGKEZone() + gkeClusterConfig.ProjectID = GetGKEProjectID() + }) } return Context{ @@ -120,3 +136,58 @@ func WaitUntilClusterIsReady(cluster *management.Cluster, client *rancher.Client } return client.Management.Cluster.ByID(cluster.ID) } + +// GetGKEZone fetches the value of GKE zone; +// it first obtains the value from env var GKE_ZONE, if the value is empty, it fetches the information from config file(cattle_config-import.yaml/cattle_config-provisioning.yaml) +// if none of the sources can provide a value, it returns the default value +func GetGKEZone() string { + zone := os.Getenv("GKE_ZONE") + if zone == "" { + gkeConfig := new(management.GKEClusterConfigSpec) + config.LoadConfig("gkeClusterConfig", gkeConfig) + if gkeConfig.Zone != "" { + zone = gkeConfig.Zone + } + if zone == "" { + zone = "asia-south2-c" + } + } + return zone +} + +// GetAKSLocation fetches the value of AKS Region; +// it first obtains the value from env var AKS_REGION, if the value is empty, it fetches the information from config file(cattle_config-import.yaml/cattle_config-provisioning.yaml) +// if none of the sources can provide a value, it returns the default value +func GetAKSLocation() string { + region := os.Getenv("AKS_REGION") + if region == "" { + aksClusterConfig := new(management.AKSClusterConfigSpec) + config.LoadConfig("aksClusterConfig", aksClusterConfig) + region = aksClusterConfig.ResourceLocation + if region == "" { + region = "centralindia" + } + } + return region +} + +// GetEKSRegion fetches the value of EKS Region; +// it first obtains the value from env var EKS_REGION, if the value is empty, it fetches the information from config file(cattle_config-import.yaml/cattle_config-provisioning.yaml) +// if none of the sources can provide a value, it returns the default value +func GetEKSRegion() string { + region := os.Getenv("EKS_REGION") + if region == "" { + eksClusterConfig := new(management.EKSClusterConfigSpec) + config.LoadConfig("eksClusterConfig", eksClusterConfig) + region = eksClusterConfig.Region + if region == "" { + region = "ap-south-1" + } + } + return region +} + +// GetGKEProjectID returns the value of GKE project by fetching the value of env var GKE_PROJECT_ID +func GetGKEProjectID() string { + return os.Getenv("GKE_PROJECT_ID") +}