From 0eb7ecedeef49a69325ce190486c1e7592edf2a3 Mon Sep 17 00:00:00 2001 From: Daniele Antonio Maggio Date: Fri, 27 Apr 2018 12:11:36 -0700 Subject: [PATCH] WIP - Adding windows agent pool scaling --- cmd/scale.go | 33 ++++++++++++++++--- pkg/armhelpers/utils/util.go | 2 +- .../kubernetesupgrade/upgradecluster.go | 3 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/cmd/scale.go b/cmd/scale.go index f7016da258..5f1cc47db9 100644 --- a/cmd/scale.go +++ b/cmd/scale.go @@ -36,6 +36,7 @@ type scaleCmd struct { location string agentPoolToScale string classicMode bool + windowsPool bool // derived apiModelPath string @@ -75,6 +76,7 @@ func newScaleCmd() *cobra.Command { f.BoolVar(&sc.classicMode, "classic-mode", false, "enable classic parameters and outputs") f.StringVar(&sc.agentPoolToScale, "node-pool", "", "node pool to scale") f.StringVar(&sc.masterFQDN, "master-FQDN", "", "FQDN for the master load balancer, Needed to scale down Kubernetes agent pools") + f.BoolVar(&sc.windowsPool, "windows", false, "true if windows pool") addAuthFlags(&sc.authArgs, f) @@ -186,7 +188,7 @@ func (sc *scaleCmd) run(cmd *cobra.Command, args []string) error { sc.validate(cmd, args) orchestratorInfo := sc.containerService.Properties.OrchestratorProfile - var currentNodeCount, highestUsedIndex int + var currentNodeCount, highestUsedIndex, index, poolindex int indexes := make([]int, 0) indexToVM := make(map[int]string) if sc.agentPool.IsAvailabilitySets() { @@ -198,12 +200,21 @@ func (sc *scaleCmd) run(cmd *cobra.Command, args []string) error { log.Fatalln("The provided resource group does not contain any vms.") } for _, vm := range *vms.Value { + vmTags := *vm.Tags + poolName := *vmTags["poolName"] + nameSuffix := *vmTags["resourceNameSuffix"] - poolName, nameSuffix, index, err := utils.K8sLinuxVMNameParts(*vm.Name) - if err != nil || !strings.EqualFold(poolName, sc.agentPoolToScale) || !strings.EqualFold(nameSuffix, sc.nameSuffix) { + //Changed to string contains for the nameSuffix as the Windows Agent Pools use only a substring of the first 5 characters of the entire nameSuffix + if err != nil || !strings.EqualFold(poolName, sc.agentPoolToScale) || !strings.Contains(sc.nameSuffix, nameSuffix) { continue } + if sc.windowsPool { + _, _, poolindex, index, err = utils.WindowsVMNameParts(*vm.Name) + } else { + _, _, index, err = utils.K8sLinuxVMNameParts(*vm.Name) + } + indexToVM[index] = *vm.Name indexes = append(indexes, index) } @@ -259,10 +270,19 @@ func (sc *scaleCmd) run(cmd *cobra.Command, args []string) error { log.Fatalln("failed to get vmss list in the resource group. Error: %s", err.Error()) } for _, vmss := range *vmssList.Value { - poolName, nameSuffix, err := utils.VmssNameParts(*vmss.Name) - if err != nil || !strings.EqualFold(poolName, sc.agentPoolToScale) || !strings.EqualFold(nameSuffix, sc.nameSuffix) { + vmTags := *vmss.Tags + poolName := *vmTags["poolName"] + nameSuffix := *vmTags["resourceNameSuffix"] + + //Changed to string contains for the nameSuffix as the Windows Agent Pools use only a substring of the first 5 characters of the entire nameSuffix + if err != nil || !strings.EqualFold(poolName, sc.agentPoolToScale) || !strings.Contains(sc.nameSuffix, nameSuffix) { continue } + + if sc.windowsPool { + _, _, poolindex, err = utils.WindowsVMSSNameParts(*vmss.Name) + } + currentNodeCount = int(*vmss.Sku.Capacity) highestUsedIndex = 0 } @@ -312,6 +332,9 @@ func (sc *scaleCmd) run(cmd *cobra.Command, args []string) error { } addValue(parametersJSON, sc.agentPool.Name+"Count", countForTemplate) + if sc.windowsPool { + templateJSON["variables"].(map[string]interface{})[sc.agentPool.Name+"Index"] = poolindex + } switch orchestratorInfo.OrchestratorType { case api.Kubernetes: err = transformer.NormalizeForK8sVMASScalingUp(sc.logger, templateJSON) diff --git a/pkg/armhelpers/utils/util.go b/pkg/armhelpers/utils/util.go index f0e8d987dd..f230b44b2d 100644 --- a/pkg/armhelpers/utils/util.go +++ b/pkg/armhelpers/utils/util.go @@ -109,7 +109,7 @@ func WindowsVMNameParts(vmName string) (poolPrefix string, acsStr string, poolIn if err != nil { return "", "", -1, -1, fmt.Errorf("Error parsing VM Name: %v", err) } - + poolIndex -= 900 agentIndex, _ = strconv.Atoi(poolInfo[3:]) fmt.Printf("%d\n", agentIndex) diff --git a/pkg/operations/kubernetesupgrade/upgradecluster.go b/pkg/operations/kubernetesupgrade/upgradecluster.go index 3c69150004..4af689d8ea 100644 --- a/pkg/operations/kubernetesupgrade/upgradecluster.go +++ b/pkg/operations/kubernetesupgrade/upgradecluster.go @@ -233,7 +233,8 @@ func (uc *UpgradeCluster) addVMToAgentPool(vm compute.VirtualMachine, isUpgradab return err } - poolIdentifier = poolPrefix + acsStr + strconv.Itoa(poolIndex) + //Verify that it is not breaking anything + poolIdentifier = poolPrefix + acsStr + strconv.Itoa(poolIndex+900) if !strings.Contains(uc.NameSuffix, poolPrefix) { uc.Logger.Infof("Skipping VM: %s for upgrade as it does not belong to cluster with expected name suffix: %s\n",