Skip to content

Commit

Permalink
Use a single source of truth to obtain provider locations
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi <parthvi.vala@gmail.com>
  • Loading branch information
valaparthvi committed Jan 4, 2024
1 parent b128499 commit 631ddca
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 26 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,27 @@ 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.

Expand Down
2 changes: 1 addition & 1 deletion cattle-config-import.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ aksClusterConfig:
osType: Linux
vmSize: Standard_DS2_v2
resourceGroup: ""
resourceLocation: centralindia
resourceLocation: centralindia
awsCredentials:
azureCredentials:
environment: AzurePublicCloud
Expand Down
2 changes: 1 addition & 1 deletion hosted/aks/p0/p0_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var (
ctx helpers.Context
clusterName string
location = "centralindia"
location = helpers.GetAKSLocation()
k8sVersion = "1.26.6"
increaseBy = 1
)
Expand Down
1 change: 0 additions & 1 deletion hosted/aks/support_matrix/support_matrix_importing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var _ = Describe("SupportMatrixImporting", func() {
When(fmt.Sprintf("a cluster is created with kubernetes version %s", version), func() {
var (
clusterName string
location = "centralindia"
cluster *management.Cluster
)
BeforeEach(func() {
Expand Down
3 changes: 2 additions & 1 deletion hosted/aks/support_matrix/support_matrix_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
var (
availableVersionList []string
ctx helpers.Context
location = helpers.GetAKSLocation()
)

func TestSupportMatrix(t *testing.T) {
RegisterFailHandler(Fail)
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")
}
3 changes: 1 addition & 2 deletions hosted/eks/p0/p0_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package p0_test

import (
"os"
"testing"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -13,7 +12,7 @@ import (
var (
ctx helpers.Context
clusterName string
region = os.Getenv("EKS_REGION")
region = helpers.GetEKSLocation()
k8sVersion = "1.26"
increaseBy = 1
)
Expand Down
3 changes: 0 additions & 3 deletions hosted/eks/support_matrix/support_matrix_importing_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package support_matrix_test

import (
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions hosted/eks/support_matrix/support_matrix_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
var (
availableVersionList []string
ctx helpers.Context
region = helpers.GetEKSLocation()
)

func TestSupportMatrix(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion hosted/gke/p0/p0_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var (
ctx helpers.Context
clusterName string
zone = "asia-south2-c"
zone = helpers.GetGKEZone()
project = os.Getenv("GKE_PROJECT_ID")
k8sVersion = "1.27.4-gke.900"
increaseBy = 1
Expand Down
4 changes: 0 additions & 4 deletions hosted/gke/support_matrix/support_matrix_importing_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package support_matrix_test

import (
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand All @@ -29,8 +27,6 @@ var _ = Describe("SupportMatrixImporting", func() {
var (
clusterName string
cluster *management.Cluster
project = os.Getenv("GKE_PROJECT_ID")
zone = "asia-south2-c"
)
BeforeEach(func() {
clusterName = namegen.AppendRandomString("gkehostcluster")
Expand Down
3 changes: 0 additions & 3 deletions hosted/gke/support_matrix/support_matrix_provisioning_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package support_matrix_test

import (
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion hosted/gke/support_matrix/support_matrix_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ var (
availableVersionList []string
ctx helpers.Context
project = os.Getenv("GKE_PROJECT_ID")
zone = helpers.GetGKEZone()
)

func TestSupportMatrix(t *testing.T) {
RegisterFailHandler(Fail)
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")
}
67 changes: 66 additions & 1 deletion hosted/helpers/helper_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,37 @@ 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 = GetEKSLocation()
})
cloudCredential, err = aws.CreateAWSCloudCredentials(rancherClient)
Expect(err).To(BeNil())
eksClusterConfig := new(management.EKSClusterConfigSpec)
config.LoadAndUpdateConfig("eksClusterConfig", eksClusterConfig, func() {
eksClusterConfig.Region = GetEKSLocation()
})
case "gke":
credentialConfig := new(cloudcredentials.GoogleCredentialConfig)
config.LoadAndUpdateConfig("googleCredentials", credentialConfig, func() {
credentialConfig.AuthEncodedJSON = os.Getenv("GCP_CREDENTIALS")
})
cloudCredential, err = google.CreateGoogleCloudCredentials(rancherClient)
Expect(err).To(BeNil())
gkeClusterConfig := new(management.GKEClusterConfigSpec)
config.LoadAndUpdateConfig("gkeClusterConfig", gkeClusterConfig, func() {
gkeClusterConfig.Zone = GetGKEZone()
})
}

return Context{
Expand Down Expand Up @@ -120,3 +135,53 @@ 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 == "" {
var gkeConfig management.GKEClusterConfigSpec
config.LoadConfig("gkeClusterConfig", gkeConfig)
if gkeConfig.Zone != "" {
zone = gkeConfig.Region
}
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 == "" {
var aksClusterConfig management.AKSClusterConfigSpec
config.LoadConfig("aksClusterConfig", aksClusterConfig)
region = aksClusterConfig.ResourceLocation
if region == "" {
region = "centralindia"
}
}
return region
}

// GetEKSLocation 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 GetEKSLocation() string {
region := os.Getenv("EKS_REGION")
if region == "" {
var eksClusterConfig management.EKSClusterConfigSpec
config.LoadConfig("eksClusterConfig", eksClusterConfig)
region = eksClusterConfig.Region
if region == "" {
region = "ap-south-1"
}
}
return region
}

0 comments on commit 631ddca

Please sign in to comment.