Skip to content

Commit

Permalink
Fix AKS failure
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <[email protected]>
  • Loading branch information
valaparthvi committed Jan 8, 2025
1 parent df9e5e2 commit d71c00e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
23 changes: 17 additions & 6 deletions hosted/aks/helper/helper_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,9 @@ func UpdateCluster(cluster *management.Cluster, client *rancher.Client, updateFu
// ====================================================================Azure CLI (start)=================================
// Create Azure AKS cluster using AZ CLI
func CreateAKSClusterOnAzure(location string, clusterName string, k8sVersion string, nodes string, tags map[string]string, extraArgs ...string) error {
fmt.Println("Creating AKS resource group ...")
rgargs := []string{"group", "create", "--location", location, "--resource-group", clusterName, "--subscription", subscriptionID}
fmt.Printf("Running command: az %v\n", rgargs)

out, err := proc.RunW("az", rgargs...)
err := CreateAKSRGOnAzure(clusterName, location)
if err != nil {
return errors.Wrap(err, "Failed to create cluster: "+out)
return err
}

fmt.Println("Creating AKS cluster ...")
Expand All @@ -486,6 +482,7 @@ func CreateAKSClusterOnAzure(location string, clusterName string, k8sVersion str
}

fmt.Printf("Running command: az %v\n", args)
var out string
out, err = proc.RunW("az", args...)
if err != nil {
return errors.Wrap(err, "Failed to create cluster: "+out)
Expand All @@ -496,6 +493,20 @@ func CreateAKSClusterOnAzure(location string, clusterName string, k8sVersion str
return nil
}

// CreateAKSRGOnAzure creates resource group on azure via CLI
func CreateAKSRGOnAzure(name, location string) error {
fmt.Println("Creating AKS resource group ...")
rgargs := []string{"group", "create", "--location", location, "--resource-group", name, "--subscription", subscriptionID}
fmt.Printf("Running command: az %v\n", rgargs)

out, err := proc.RunW("az", rgargs...)
if err != nil {
return errors.Wrap(err, "Failed to create cluster: "+out)
}
fmt.Println("Created AKS resource group: ", name)
return nil
}

// AddNodePoolOnAzure adds nodepool to an AKS cluster via CLI; helpful when creating a cluster with multiple nodepools
func AddNodePoolOnAzure(npName, clusterName, resourceGroupName, nodeCount string, extraArgs ...string) error {
fmt.Println("Adding node pool ...")
Expand Down
22 changes: 18 additions & 4 deletions hosted/aks/p1/p1_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ import (
var _ = Describe("P1Provisioning", func() {
var cluster *management.Cluster
var k8sVersion string

BeforeEach(func() {
GinkgoLogr.Info(fmt.Sprintf("Running on process: %d", GinkgoParallelProcess()))
var err error
k8sVersion, err = helper.GetK8sVersion(ctx.RancherAdminClient, ctx.CloudCredID, location, false)
Expect(err).NotTo(HaveOccurred())
GinkgoLogr.Info(fmt.Sprintf("Using K8s version %s for cluster %s", k8sVersion, clusterName))
})

AfterEach(func() {
if ctx.ClusterCleanup && (cluster != nil && cluster.ID != "") {
GinkgoLogr.Info(fmt.Sprintf("Cleaning up resources %s %s", cluster.Name, cluster.ID))
err := helper.DeleteAKSHostCluster(cluster, ctx.RancherAdminClient)
Expect(err).To(BeNil())
} else {
Expand Down Expand Up @@ -461,8 +465,21 @@ var _ = Describe("P1Provisioning", func() {

// Refer: https://github.com/rancher/hosted-providers-e2e/issues/192
It("should successfully create 2 clusters in the same RG", func() {
testCaseID = 217
testCaseID = 214

// Setting this to nil ensures we do not use the `cluster` variable value from another test running in parallel with this one.
cluster = nil

// Create the resource group via CLI
rgName := namegen.AppendRandomString(helpers.ClusterNamePrefix + "-custom-rg")
err := helper.CreateAKSRGOnAzure(rgName, location)
Expect(err).To(BeNil())
defer func() {
// This is to delete the resource group
err = helper.DeleteAKSClusteronAzure(rgName)
Expect(err).To(BeNil())
}()

updateFunc := func(aksConfig *aks.ClusterConfig) {
aksConfig.ResourceGroup = rgName
}
Expand All @@ -488,9 +505,6 @@ var _ = Describe("P1Provisioning", func() {
}()
}
wg.Wait()
// This is to delete the resource group
err := helper.DeleteAKSClusteronAzure(rgName)
Expect(err).To(BeNil())
})

When("a cluster is created for upgrade", func() {
Expand Down
2 changes: 1 addition & 1 deletion hosted/aks/p1/p1_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func npUpgradeToVersionGTCPCheck(cluster *management.Cluster, client *rancher.Cl
cluster, err = client.Management.Cluster.ByID(cluster.ID)
Expect(err).NotTo(HaveOccurred())
return cluster.Transitioning == "error" && strings.Contains(cluster.TransitioningMessage, fmt.Sprintf("Node pool version %s and control plane version %s are incompatible.", upgradeK8sVersion, k8sVersion))
}, "1m", "2s").Should(BeTrue())
}, "2m", "2s").Should(BeTrue())
}

// updateTagsCheck runs checks to add and delete the cluster with a new tag and an empty tag
Expand Down

0 comments on commit d71c00e

Please sign in to comment.