Skip to content

Commit

Permalink
Automate Qase 302, 233, 299, and 238 (#190)
Browse files Browse the repository at this point in the history
* Automate Qase 302, 233, 299, and 238

Signed-off-by: Parthvi Vala <[email protected]>

* Fix#0

Signed-off-by: Parthvi Vala <[email protected]>

* Fix#2

Signed-off-by: Parthvi Vala <[email protected]>

* Fix#3

Signed-off-by: Parthvi Vala <[email protected]>

* Increase timeout#0

Signed-off-by: Parthvi Vala <[email protected]>

* Fix#4

Signed-off-by: Parthvi Vala <[email protected]>

* Fix#5

Signed-off-by: Parthvi Vala <[email protected]>

* Remove focus and fix typo in comment

Signed-off-by: Parthvi Vala <[email protected]>

---------

Signed-off-by: Parthvi Vala <[email protected]>
  • Loading branch information
valaparthvi authored Oct 30, 2024
1 parent fa3f279 commit 091b5e1
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 16 deletions.
81 changes: 72 additions & 9 deletions hosted/aks/helper/helper_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ 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, clusterCreateArgs ...string) error {
formattedTags := convertMapToAKSString(tags)
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)
Expand All @@ -474,8 +473,18 @@ func CreateAKSClusterOnAzure(location string, clusterName string, k8sVersion str
}

fmt.Println("Creating AKS cluster ...")
args := []string{"aks", "create", "--resource-group", clusterName, "--no-ssh-key", "--kubernetes-version", k8sVersion, "--enable-managed-identity", "--name", clusterName, "--subscription", subscriptionID, "--node-count", nodes, "--tags", formattedTags, "--location", location}
args = append(args, clusterCreateArgs...)
args := []string{"aks", "create", "--resource-group", clusterName, "--no-ssh-key", "--kubernetes-version", k8sVersion, "--enable-managed-identity", "--name", clusterName, "--subscription", subscriptionID, "--node-count", nodes, "--location", location}

// append tags
tagargs := []string{"--tags"}
tagargs = append(tagargs, convertMapToAKSString(tags)...)
args = append(args, tagargs...)

// append extra arguments
if len(extraArgs) > 0 {
args = append(args, extraArgs...)
}

fmt.Printf("Running command: az %v\n", args)
out, err = proc.RunW("az", args...)
if err != nil {
Expand Down Expand Up @@ -503,6 +512,61 @@ func AddNodePoolOnAzure(npName, clusterName, resourceGroupName, nodeCount string
return nil
}

// DeleteNodePoolOnAzure deletes nodepool from an AKS cluster via CLI
func DeleteNodePoolOnAzure(npName, clusterName, resourceGroupName string, extraArgs ...string) error {
fmt.Println("Deleting node pool ...")
args := []string{"aks", "nodepool", "delete", "--resource-group", resourceGroupName, "--cluster-name", clusterName, "--name", npName, "--subscription", subscriptionID}
if len(extraArgs) > 0 {
args = append(args, extraArgs...)
}
fmt.Printf("Running command: az %v\n", args)
out, err := proc.RunW("az", args...)
if err != nil {
return errors.Wrap(err, "Failed to delete node pool: "+out)
}
fmt.Println("Deleted node pool: ", npName)
return nil
}

// ScaleNodePoolOnAzure scales nodepool of an AKS cluster via CLI
func ScaleNodePoolOnAzure(npName, clusterName, resourceGroupName, nodeCount string, extraArgs ...string) error {
fmt.Println("Scaling node pool ...")
args := []string{"aks", "nodepool", "scale", "--resource-group", resourceGroupName, "--cluster-name", clusterName, "--name", npName, "--node-count", nodeCount, "--subscription", subscriptionID}
if len(extraArgs) > 0 {
args = append(args, extraArgs...)
}
fmt.Printf("Running command: az %v\n", args)
out, err := proc.RunW("az", args...)
if err != nil {
return errors.Wrap(err, "Failed to scale node pool: "+out)
}
fmt.Println("Scaled node pool: ", npName)
return nil
}

// UpdateClusterTagOnAzure updates the tags of an existing AKS cluster via CLI
func UpdateClusterTagOnAzure(tags map[string]string, clusterName, resourceGroupName string, extraArgs ...string) error {
fmt.Println("Adding tags on Azure ...")
args := []string{"aks", "update", "--resource-group", resourceGroupName, "--name", clusterName, "--subscription", subscriptionID}

// append tags
tagsarg := []string{"--tags"}
tagsarg = append(tagsarg, convertMapToAKSString(tags)...)
args = append(args, tagsarg...)

// append extra args
if len(extraArgs) > 0 {
args = append(args, extraArgs...)
}
fmt.Printf("Running command: az %v\n", args)
out, err := proc.RunW("az", args...)
if err != nil {
return errors.Wrap(err, "Failed to add tag on Azure: "+out)
}
fmt.Println("Added tags on Azure: ", clusterName)
return nil
}

// ClusterExistsOnAzure gets a list of cluster based on the name filter and returns true if the cluster is not in Deleting state;
// it returns false if the cluster does not exist or is in Deleting state.
func ClusterExistsOnAzure(clusterName, resourceGroup string) (bool, error) {
Expand All @@ -520,7 +584,7 @@ func ClusterExistsOnAzure(clusterName, resourceGroup string) (bool, error) {
}

// UpgradeAKSOnAzure upgrade the AKS cluster using az CLI
// `--control-plane-only` flag can be passed to only upgrade Control Plane version. If not specified, both control plane AND all node pools will be upgraded.
// `--control-plane-only` flag can be passed to only upgrade Control Plane version. (Default) If not specified, both control plane AND all node pools will be upgraded.
// `--node-image-only` flag can be passed to only upgrade Node Pool version
func UpgradeAKSOnAzure(clusterName, resourceGroup, upgradeToVersion string, additionalArgs ...string) error {
fmt.Println("Upgrading AKS cluster ...")
Expand All @@ -538,11 +602,10 @@ func UpgradeAKSOnAzure(clusterName, resourceGroup, upgradeToVersion string, addi
}

// convertMapToAKSString converts the map of labels to a string format acceptable by azure CLI
// acceptable format: `--tags "owner=hostedproviders" "testname=sometest"`
func convertMapToAKSString(tags map[string]string) string {
var convertedString string
func convertMapToAKSString(tags map[string]string) []string {
var convertedString []string
for key, value := range tags {
convertedString += fmt.Sprintf("\"%s=%s\" ", key, value)
convertedString = append(convertedString, fmt.Sprintf("%s=%s", key, value))
}
return convertedString
}
Expand Down
5 changes: 5 additions & 0 deletions hosted/aks/p1/p1_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ var _ = Describe("P1Import", func() {
updateCloudCredentialsCheck(cluster, ctx.RancherAdminClient)
})

It("should fail to update with invalid (deleted) cloud credential and update when the cloud credentials becomes valid", func() {
testCaseID = 238
invalidateCloudCredentialsCheck(cluster, ctx.RancherAdminClient, ctx.CloudCredID)
})

It("should be able to update autoscaling", func() {
testCaseID = 266
updateAutoScaling(cluster, ctx.RancherAdminClient)
Expand Down
26 changes: 20 additions & 6 deletions hosted/aks/p1/p1_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ var _ = Describe("P1Provisioning", func() {
updateCloudCredentialsCheck(cluster, ctx.RancherAdminClient)
})

It("should fail to update with invalid (deleted) cloud credential and update when the cloud credentials becomes valid", func() {
testCaseID = 299
invalidateCloudCredentialsCheck(cluster, ctx.RancherAdminClient, ctx.CloudCredID)
})

It("should not be able to edit availability zone of a nodepool", func() {
// Refer: https://github.com/rancher/aks-operator/issues/669
testCaseID = 195
Expand Down Expand Up @@ -459,28 +464,37 @@ var _ = Describe("P1Provisioning", func() {

})

XIt("should successfully create 2 clusters in the same RG", func() {
// TODO: Refer https://github.com/rancher/hosted-providers-e2e/issues/192
It("should successfully create 2 clusters in the same RG", func() {
testCaseID = 217
rgName := namegen.AppendRandomString("custom-aks-rg")
rgName := namegen.AppendRandomString(helpers.ClusterNamePrefix + "-custom-rg")
updateFunc := func(aksConfig *aks.ClusterConfig) {
aksConfig.ResourceGroup = rgName
}
var wg sync.WaitGroup
for i := 1; i <= 2; i++ {
wg.Add(1)
go func() {
defer GinkgoRecover()
defer wg.Done()
clusterName := namegen.AppendRandomString(helpers.ClusterNamePrefix)
cluster1, err := helper.CreateAKSHostedCluster(ctx.RancherAdminClient, clusterName, ctx.CloudCredID, k8sVersion, location, updateFunc)
Expect(err).To(BeNil())
if err != nil {
Fail(err.Error())
}
cluster1, err = helpers.WaitUntilClusterIsReady(cluster1, ctx.RancherAdminClient)
Expect(err).To(BeNil())
if err != nil {
Fail(err.Error())
}
err = helper.DeleteAKSHostCluster(cluster1, ctx.RancherAdminClient)
Expect(err).To(BeNil())
if err != nil {
Fail(err.Error())
}
}()
}
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
Loading

0 comments on commit 091b5e1

Please sign in to comment.