Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
WIP - Adding windows agent pool scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
danigian committed Apr 27, 2018
1 parent 22d2e88 commit 0eb7ece
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
33 changes: 28 additions & 5 deletions cmd/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type scaleCmd struct {
location string
agentPoolToScale string
classicMode bool
windowsPool bool

// derived
apiModelPath string
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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() {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/armhelpers/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion pkg/operations/kubernetesupgrade/upgradecluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0eb7ece

Please sign in to comment.