Skip to content

Commit

Permalink
Fix nil panic error
Browse files Browse the repository at this point in the history
  • Loading branch information
valaparthvi committed Jan 8, 2024
1 parent 631ddca commit 1ea32f3
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 33 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ To run AKS:
Run `make help` to know about other targets.

### Example
**GKE Provisioning 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
GKE_PROJECT_ID=some-project GCP_CREDENTIALS=<credentials-json> 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=<credentials-json> 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=<key-id> AWS_SECRET_ACCESS_KEY=<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=<key-id> AWS_SECRET_ACCESS_KEY=<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=<client-id> AKS_CLIENT_SECRET=<secret> AKS_SUBSCRIPTION_ID=<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
AKS_REGION=centralindia AKS_CLIENT_ID=<client-id> AKS_CLIENT_SECRET=<secret> AKS_SUBSCRIPTION_ID=<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
```
4 changes: 3 additions & 1 deletion hosted/aks/p0/p0_importing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
)

var _ = Describe("P0Importing", func() {

var (
location = helpers.GetAKSLocation()
)
When("a cluster is imported", func() {
var cluster *management.Cluster

Expand Down
1 change: 0 additions & 1 deletion hosted/aks/p0/p0_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
var (
ctx helpers.Context
clusterName string
location = helpers.GetAKSLocation()
k8sVersion = "1.26.6"
increaseBy = 1
)
Expand Down
5 changes: 4 additions & 1 deletion hosted/eks/p0/p0_importing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down
1 change: 0 additions & 1 deletion hosted/eks/p0/p0_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
var (
ctx helpers.Context
clusterName string
region = helpers.GetEKSLocation()
k8sVersion = "1.26"
increaseBy = 1
)
Expand Down
2 changes: 1 addition & 1 deletion hosted/eks/support_matrix/support_matrix_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var (
availableVersionList []string
ctx helpers.Context
region = helpers.GetEKSLocation()
region = helpers.GetEKSRegion()
)

func TestSupportMatrix(t *testing.T) {
Expand Down
11 changes: 4 additions & 7 deletions hosted/gke/p0/p0_importing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions hosted/gke/p0/p0_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions hosted/gke/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,8 +12,6 @@ import (
var (
ctx helpers.Context
clusterName string
zone = helpers.GetGKEZone()
project = os.Getenv("GKE_PROJECT_ID")
k8sVersion = "1.27.4-gke.900"
increaseBy = 1
)
Expand Down
22 changes: 14 additions & 8 deletions hosted/helpers/helper_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ func CommonBeforeSuite(cloud string) (Context, error) {
config.LoadAndUpdateConfig("awsCredentials", credentialConfig, func() {
credentialConfig.AccessKey = os.Getenv("AWS_ACCESS_KEY_ID")
credentialConfig.SecretKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
credentialConfig.DefaultRegion = GetEKSLocation()
credentialConfig.DefaultRegion = GetEKSRegion()
})
cloudCredential, err = aws.CreateAWSCloudCredentials(rancherClient)
Expect(err).To(BeNil())
eksClusterConfig := new(management.EKSClusterConfigSpec)
config.LoadAndUpdateConfig("eksClusterConfig", eksClusterConfig, func() {
eksClusterConfig.Region = GetEKSLocation()
eksClusterConfig.Region = GetEKSRegion()
})
case "gke":
credentialConfig := new(cloudcredentials.GoogleCredentialConfig)
Expand All @@ -107,6 +107,7 @@ func CommonBeforeSuite(cloud string) (Context, error) {
gkeClusterConfig := new(management.GKEClusterConfigSpec)
config.LoadAndUpdateConfig("gkeClusterConfig", gkeClusterConfig, func() {
gkeClusterConfig.Zone = GetGKEZone()
gkeClusterConfig.ProjectID = GetGKEProjectID()
})
}

Expand Down Expand Up @@ -142,10 +143,10 @@ func WaitUntilClusterIsReady(cluster *management.Cluster, client *rancher.Client
func GetGKEZone() string {
zone := os.Getenv("GKE_ZONE")
if zone == "" {
var gkeConfig management.GKEClusterConfigSpec
gkeConfig := new(management.GKEClusterConfigSpec)
config.LoadConfig("gkeClusterConfig", gkeConfig)
if gkeConfig.Zone != "" {
zone = gkeConfig.Region
zone = gkeConfig.Zone
}
if zone == "" {
zone = "asia-south2-c"
Expand All @@ -160,7 +161,7 @@ func GetGKEZone() string {
func GetAKSLocation() string {
region := os.Getenv("AKS_REGION")
if region == "" {
var aksClusterConfig management.AKSClusterConfigSpec
aksClusterConfig := new(management.AKSClusterConfigSpec)
config.LoadConfig("aksClusterConfig", aksClusterConfig)
region = aksClusterConfig.ResourceLocation
if region == "" {
Expand All @@ -170,13 +171,13 @@ func GetAKSLocation() string {
return region
}

// GetEKSLocation fetches the value of EKS 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 GetEKSLocation() string {
func GetEKSRegion() string {
region := os.Getenv("EKS_REGION")
if region == "" {
var eksClusterConfig management.EKSClusterConfigSpec
eksClusterConfig := new(management.EKSClusterConfigSpec)
config.LoadConfig("eksClusterConfig", eksClusterConfig)
region = eksClusterConfig.Region
if region == "" {
Expand All @@ -185,3 +186,8 @@ func GetEKSLocation() string {
}
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")
}

0 comments on commit 1ea32f3

Please sign in to comment.