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

Commit

Permalink
removing master custom script extension from scaling templates (#1764)
Browse files Browse the repository at this point in the history
this is causing issues due to switch from positional arguments to named
variables
  • Loading branch information
JackQuincy authored and jackfrancis committed Nov 13, 2017
1 parent 999442c commit 4c42d5f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 94 deletions.
26 changes: 19 additions & 7 deletions pkg/acsengine/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,25 @@ func (t *Transformer) NormalizeForK8sVMASScalingUp(logger *logrus.Entry, templat
indexesToRemove = append(indexesToRemove, rtIndex)
}
indexesToRemove = append(indexesToRemove, nsgIndex)
templateMap[resourcesFieldName] = removeIndexesFromArray(resources, indexesToRemove)

sort.Sort(sort.Reverse(sort.IntSlice(indexesToRemove)))
for _, resourceIndex := range indexesToRemove {
return nil
}

resources = append(resources[:resourceIndex], resources[resourceIndex+1:]...)
func removeIndexesFromArray(array []interface{}, indexes []int) []interface{} {
sort.Sort(sort.Reverse(sort.IntSlice(indexes)))
for _, index := range indexes {
array = append(array[:index], array[index+1:]...)
}
templateMap[resourcesFieldName] = resources

return nil
return array
}

// NormalizeMasterResourcesForScaling takes a template and removes elements that are unwanted in any scale up/down case
func (t *Transformer) NormalizeMasterResourcesForScaling(logger *logrus.Entry, templateMap map[string]interface{}) error {
resources := templateMap[resourcesFieldName].([]interface{})
indexesToRemove := []int{}
//update master nodes resources
for _, resource := range resources {
for index, resource := range resources {
resourceMap, ok := resource.(map[string]interface{})
if !ok {
logger.Warnf("Template improperly formatted")
Expand All @@ -174,6 +177,14 @@ func (t *Transformer) NormalizeMasterResourcesForScaling(logger *logrus.Entry, t

resourceType, ok := resourceMap[typeFieldName].(string)
if !ok || resourceType != vmResourceType {
resourceName, ok := resourceMap[nameFieldName].(string)
if !ok {
logger.Warnf("Template improperly formatted")
continue
}
if strings.Contains(resourceName, "variables('masterVMNamePrefix')") && resourceType == vmExtensionType {
indexesToRemove = append(indexesToRemove, index)
}
continue
}

Expand Down Expand Up @@ -208,6 +219,7 @@ func (t *Transformer) NormalizeMasterResourcesForScaling(logger *logrus.Entry, t
continue
}
}
templateMap[resourcesFieldName] = removeIndexesFromArray(resources, indexesToRemove)

return nil
}
Expand Down
18 changes: 0 additions & 18 deletions pkg/acsengine/transformtestfiles/dcos_scale_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1131,24 +1131,6 @@
"creationSource": "[concat('acsengine-', variables('masterVMNamePrefix'), copyIndex())]"
},
"type": "Microsoft.Compute/virtualMachines"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('masterVMNamePrefix'), sub(variables('masterCount'), 1))]"
],
"location": "[variables('location')]",
"name": "[concat(variables('masterVMNamePrefix'), sub(variables('masterCount'), 1), '/waitforleader')]",
"properties": {
"autoUpgradeMinorVersion": true,
"publisher": "Microsoft.OSTCExtensions",
"settings": {
"commandToExecute": "sh -c 'until ping -c1 leader.mesos;do echo waiting for leader.mesos;sleep 15;done;echo leader.mesos up'"
},
"type": "CustomScriptForLinux",
"typeHandlerVersion": "1.4"
},
"type": "Microsoft.Compute/virtualMachines/extensions"
}
],
"outputs": {
Expand Down
23 changes: 0 additions & 23 deletions pkg/acsengine/transformtestfiles/k8s_agent_upgrade_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2078,29 +2078,6 @@
"resourceNameSuffix": "[variables('nameSuffix')]"
},
"type": "Microsoft.Compute/virtualMachines"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"copy": {
"count": "[sub(variables('masterCount'), variables('masterOffset'))]",
"name": "vmLoopNode"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')))]"
],
"location": "[variables('location')]",
"name": "[concat(variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')),'/cse', copyIndex(variables('masterOffset')))]",
"properties": {
"autoUpgradeMinorVersion": true,
"protectedSettings": {
"commandToExecute": "[concat('/usr/bin/nohup /bin/bash -c \"/bin/bash /opt/azure/containers/provision.sh ',variables('tenantID'),' ',variables('subscriptionId'),' ',variables('resourceGroup'),' ',variables('location'),' ',variables('subnetName'),' ',variables('nsgName'),' ',variables('virtualNetworkName'),' ',variables('routeTableName'),' ',variables('primaryAvailabilitySetName'),' ',variables('servicePrincipalClientId'),' ',variables('servicePrincipalClientSecret'),' ',variables('clientPrivateKey'),' ',variables('targetEnvironment'),' ',variables('networkPolicy'),' ',variables('cloudProviderBackoff'),' ',variables('cloudProviderBackoffRetries'),' ',variables('cloudProviderBackoffExponent'),' ',variables('cloudProviderBackoffDuration'),' ',variables('cloudProviderBackoffJitter'),' ',variables('cloudProviderRatelimit'),' ',variables('cloudProviderRatelimitQPS'),' ',variables('cloudProviderRatelimitBucket'),' ',variables('useManagedIdentityExtension'),' ',variables('useInstanceMetadata'),' ',variables('apiServerPrivateKey'),' ',variables('caCertificate'),' ',variables('caPrivateKey'),' ',variables('masterFqdnPrefix'),' ',variables('kubeConfigCertificate'),' ',variables('kubeConfigPrivateKey'),' ',variables('username'),' \u003e\u003e /var/log/azure/cluster-provision.log 2\u003e\u00261\"')]"
},
"publisher": "Microsoft.Azure.Extensions",
"settings": {},
"type": "CustomScript",
"typeHandlerVersion": "2.0"
},
"type": "Microsoft.Compute/virtualMachines/extensions"
}
],
"outputs": {
Expand Down
23 changes: 0 additions & 23 deletions pkg/acsengine/transformtestfiles/k8s_scale_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2260,29 +2260,6 @@
"resourceNameSuffix": "[variables('nameSuffix')]"
},
"type": "Microsoft.Compute/virtualMachines"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"copy": {
"count": "[sub(variables('masterCount'), variables('masterOffset'))]",
"name": "vmLoopNode"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')))]"
],
"location": "[variables('location')]",
"name": "[concat(variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')),'/cse', copyIndex(variables('masterOffset')))]",
"properties": {
"autoUpgradeMinorVersion": true,
"protectedSettings": {
"commandToExecute": "[concat('/usr/bin/nohup /bin/bash -c \"/bin/bash /opt/azure/containers/provision.sh ',variables('tenantID'),' ',variables('subscriptionId'),' ',variables('resourceGroup'),' ',variables('location'),' ',variables('subnetName'),' ',variables('nsgName'),' ',variables('virtualNetworkName'),' ',variables('routeTableName'),' ',variables('primaryAvailabilitySetName'),' ',variables('servicePrincipalClientId'),' ',variables('servicePrincipalClientSecret'),' ',variables('clientPrivateKey'),' ',variables('targetEnvironment'),' ',variables('networkPolicy'),' ',variables('cloudProviderBackoff'),' ',variables('cloudProviderBackoffRetries'),' ',variables('cloudProviderBackoffExponent'),' ',variables('cloudProviderBackoffDuration'),' ',variables('cloudProviderBackoffJitter'),' ',variables('cloudProviderRatelimit'),' ',variables('cloudProviderRatelimitQPS'),' ',variables('cloudProviderRatelimitBucket'),' ',variables('useManagedIdentityExtension'),' ',variables('useInstanceMetadata'),' ',variables('apiServerPrivateKey'),' ',variables('caCertificate'),' ',variables('caPrivateKey'),' ',variables('masterFqdnPrefix'),' ',variables('kubeConfigCertificate'),' ',variables('kubeConfigPrivateKey'),' ',variables('username'),' \u003e\u003e /var/log/azure/cluster-provision.log 2\u003e\u00261\"')]"
},
"publisher": "Microsoft.Azure.Extensions",
"settings": {},
"type": "CustomScript",
"typeHandlerVersion": "2.0"
},
"type": "Microsoft.Compute/virtualMachines/extensions"
}
],
"outputs": {
Expand Down
23 changes: 0 additions & 23 deletions pkg/acsengine/transformtestfiles/k8s_vnet_scale_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2167,29 +2167,6 @@
"resourceNameSuffix": "[variables('nameSuffix')]"
},
"type": "Microsoft.Compute/virtualMachines"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"copy": {
"count": "[sub(variables('masterCount'), variables('masterOffset'))]",
"name": "vmLoopNode"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')))]"
],
"location": "[variables('location')]",
"name": "[concat(variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')),'/cse', copyIndex(variables('masterOffset')))]",
"properties": {
"autoUpgradeMinorVersion": true,
"protectedSettings": {
"commandToExecute": "[concat('/usr/bin/nohup /bin/bash -c \"/bin/bash /opt/azure/containers/provision.sh ',variables('tenantID'),' ',variables('subscriptionId'),' ',variables('resourceGroup'),' ',variables('location'),' ',variables('subnetName'),' ',variables('nsgName'),' ',variables('virtualNetworkName'),' ',variables('routeTableName'),' ',variables('primaryAvailabilitySetName'),' ',variables('servicePrincipalClientId'),' ',variables('servicePrincipalClientSecret'),' ',variables('clientPrivateKey'),' ',variables('targetEnvironment'),' ',variables('networkPolicy'),' ',variables('cloudProviderBackoff'),' ',variables('cloudProviderBackoffRetries'),' ',variables('cloudProviderBackoffExponent'),' ',variables('cloudProviderBackoffDuration'),' ',variables('cloudProviderBackoffJitter'),' ',variables('cloudProviderRatelimit'),' ',variables('cloudProviderRatelimitQPS'),' ',variables('cloudProviderRatelimitBucket'),' ',variables('useManagedIdentityExtension'),' ',variables('useInstanceMetadata'),' ',variables('apiServerPrivateKey'),' ',variables('caCertificate'),' ',variables('caPrivateKey'),' ',variables('masterFqdnPrefix'),' ',variables('kubeConfigCertificate'),' ',variables('kubeConfigPrivateKey'),' ',variables('username'),' \u003e\u003e /var/log/azure/cluster-provision.log 2\u003e\u00261\"')]"
},
"publisher": "Microsoft.Azure.Extensions",
"settings": {},
"type": "CustomScript",
"typeHandlerVersion": "2.0"
},
"type": "Microsoft.Compute/virtualMachines/extensions"
}
],
"outputs": {
Expand Down

0 comments on commit 4c42d5f

Please sign in to comment.