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

Preserve subnets during scale up #2095

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions pkg/acsengine/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ const (
vmssResourceType = "Microsoft.Compute/virtualMachineScaleSets"
vmExtensionType = "Microsoft.Compute/virtualMachines/extensions"
nicResourceType = "Microsoft.Network/networkInterfaces"
vnetResourceType = "Microsoft.Network/virtualNetworks"

// resource ids
nsgID = "nsgID"
rtID = "routeTableID"
nsgID = "nsgID"
rtID = "routeTableID"
vnetID = "vnetID"
)

// Translator defines all required interfaces for i18n.Translator.
Expand Down Expand Up @@ -104,6 +106,7 @@ func (t *Transformer) NormalizeForK8sVMASScalingUp(logger *logrus.Entry, templat
}
rtIndex := -1
nsgIndex := -1
vnetIndex := -1
resources := templateMap[resourcesFieldName].([]interface{})
for index, resource := range resources {
resourceMap, ok := resource.(map[string]interface{})
Expand All @@ -129,6 +132,14 @@ func (t *Transformer) NormalizeForK8sVMASScalingUp(logger *logrus.Entry, templat
}
rtIndex = index
}
if ok && resourceType == vnetResourceType {
if vnetIndex != -1 {
err := t.Translator.Errorf("Found 2 resources with type %s in the template. There should only be 1", vnetResourceType)
logger.Warnf(err.Error())
return err
}
vnetIndex = index
}

dependencies, ok := resourceMap[dependsOnFieldName].([]interface{})
if !ok {
Expand All @@ -138,7 +149,8 @@ func (t *Transformer) NormalizeForK8sVMASScalingUp(logger *logrus.Entry, templat
for dIndex := len(dependencies) - 1; dIndex >= 0; dIndex-- {
dependency := dependencies[dIndex].(string)
if strings.Contains(dependency, nsgResourceType) || strings.Contains(dependency, nsgID) ||
strings.Contains(dependency, rtResourceType) || strings.Contains(dependency, rtID) {
strings.Contains(dependency, rtResourceType) || strings.Contains(dependency, rtID) ||
strings.Contains(dependency, vnetResourceType) || strings.Contains(dependency, vnetID) {
dependencies = append(dependencies[:dIndex], dependencies[dIndex+1:]...)
}
}
Expand All @@ -161,6 +173,11 @@ func (t *Transformer) NormalizeForK8sVMASScalingUp(logger *logrus.Entry, templat
} else {
indexesToRemove = append(indexesToRemove, rtIndex)
}
if vnetIndex == -1 {
logger.Infof("Found no resources with type %s in the template.", vnetResourceType)
} else {
indexesToRemove = append(indexesToRemove, vnetIndex)
}
indexesToRemove = append(indexesToRemove, nsgIndex)
templateMap[resourcesFieldName] = removeIndexesFromArray(resources, indexesToRemove)

Expand Down Expand Up @@ -283,7 +300,25 @@ func (t *Transformer) NormalizeResourcesForK8sMasterUpgrade(logger *logrus.Entry
continue
}

if !(resourceType == vmResourceType || resourceType == vmExtensionType || resourceType == nicResourceType) {
dependencies, ok := resourceMap[dependsOnFieldName].([]interface{})
if !ok {
continue
}

for dIndex := len(dependencies) - 1; dIndex >= 0; dIndex-- {
dependency := dependencies[dIndex].(string)
if strings.Contains(dependency, vnetResourceType) || strings.Contains(dependency, vnetID) {
dependencies = append(dependencies[:dIndex], dependencies[dIndex+1:]...)
}
}

if len(dependencies) > 0 {
resourceMap[dependsOnFieldName] = dependencies
} else {
delete(resourceMap, dependsOnFieldName)
}

if !(resourceType == vmResourceType || resourceType == vmExtensionType || resourceType == nicResourceType || resourceType == vnetResourceType) {
continue
}

Expand All @@ -293,6 +328,11 @@ func (t *Transformer) NormalizeResourcesForK8sMasterUpgrade(logger *logrus.Entry
continue
}

if resourceType == vnetResourceType {
filteredResources = filteredResources[:len(filteredResources)-1]
continue
}

if resourceType == nicResourceType {
if strings.Contains(resourceName, "variables('masterVMNamePrefix')") {
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1659,9 +1659,6 @@
"count": "[sub(variables('agentppol1Count'), variables('agentppol1Offset'))]",
"name": "loop"
},
"dependsOn": [
"[variables('vnetID')]"
],
"location": "[variables('location')]",
"name": "[concat(variables('agentppol1VMNamePrefix'), 'nic-', copyIndex(variables('agentppol1Offset')))]",
"properties": {
Expand Down Expand Up @@ -1710,9 +1707,6 @@
"count": "[sub(variables('agentpool2Count'), variables('agentpool2Offset'))]",
"name": "loop"
},
"dependsOn": [
"[variables('vnetID')]"
],
"location": "[variables('location')]",
"name": "[concat(variables('agentpool2VMNamePrefix'), 'nic-', copyIndex(variables('agentpool2Offset')))]",
"properties": {
Expand Down Expand Up @@ -1766,33 +1760,6 @@
},
"type": "Microsoft.Compute/availabilitySets"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"location": "[variables('location')]",
"name": "[variables('virtualNetworkName')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('vnetCidr')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnet')]",
"networkSecurityGroup": {
"id": "[variables('nsgID')]"
},
"routeTable": {
"id": "[variables('routeTableID')]"
}
}
}
]
},
"type": "Microsoft.Network/virtualNetworks"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"dependsOn": [
Expand Down Expand Up @@ -1854,9 +1821,6 @@
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"dependsOn": [
"[variables('vnetID')]"
],
"location": "[variables('location')]",
"name": "[variables('masterInternalLbName')]",
"properties": {
Expand Down Expand Up @@ -1950,7 +1914,6 @@
"name": "nicLoopNode"
},
"dependsOn": [
"[variables('vnetID')]",
"[concat(variables('masterLbID'),'/inboundNatRules/SSH-',variables('masterVMNamePrefix'),copyIndex(variables('masterOffset')))]",
"[variables('masterInternalLbName')]"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1659,9 +1659,6 @@
"count": "[sub(variables('agentppol1Count'), variables('agentppol1Offset'))]",
"name": "loop"
},
"dependsOn": [
"[variables('vnetID')]"
],
"location": "[variables('location')]",
"name": "[concat(variables('agentppol1VMNamePrefix'), 'nic-', copyIndex(variables('agentppol1Offset')))]",
"properties": {
Expand Down Expand Up @@ -1710,9 +1707,6 @@
"count": "[sub(variables('agentpool2Count'), variables('agentpool2Offset'))]",
"name": "loop"
},
"dependsOn": [
"[variables('vnetID')]"
],
"location": "[variables('location')]",
"name": "[concat(variables('agentpool2VMNamePrefix'), 'nic-', copyIndex(variables('agentpool2Offset')))]",
"properties": {
Expand Down Expand Up @@ -1857,37 +1851,6 @@
},
"type": "Microsoft.Compute/availabilitySets"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', variables('nsgName'))]",
"[concat('Microsoft.Network/routeTables/', variables('routeTableName'))]"
],
"location": "[variables('location')]",
"name": "[variables('virtualNetworkName')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('vnetCidr')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnet')]",
"networkSecurityGroup": {
"id": "[variables('nsgID')]"
},
"routeTable": {
"id": "[variables('routeTableID')]"
}
}
}
]
},
"type": "Microsoft.Network/virtualNetworks"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"location": "[variables('location')]",
Expand Down Expand Up @@ -1993,9 +1956,6 @@
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"dependsOn": [
"[variables('vnetID')]"
],
"location": "[variables('location')]",
"name": "[variables('masterInternalLbName')]",
"properties": {
Expand Down Expand Up @@ -2089,7 +2049,6 @@
"name": "nicLoopNode"
},
"dependsOn": [
"[variables('vnetID')]",
"[concat(variables('masterLbID'),'/inboundNatRules/SSH-',variables('masterVMNamePrefix'),copyIndex(variables('masterOffset')))]",
"[variables('masterInternalLbName')]"
],
Expand Down
37 changes: 0 additions & 37 deletions pkg/acsengine/transform/transformtestfiles/k8s_scale_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1659,9 +1659,6 @@
"count": "[sub(variables('agentppol1Count'), variables('agentppol1Offset'))]",
"name": "loop"
},
"dependsOn": [
"[variables('vnetID')]"
],
"location": "[variables('location')]",
"name": "[concat(variables('agentppol1VMNamePrefix'), 'nic-', copyIndex(variables('agentppol1Offset')))]",
"properties": {
Expand Down Expand Up @@ -1801,9 +1798,6 @@
"count": "[sub(variables('agentpool2Count'), variables('agentpool2Offset'))]",
"name": "loop"
},
"dependsOn": [
"[variables('vnetID')]"
],
"location": "[variables('location')]",
"name": "[concat(variables('agentpool2VMNamePrefix'), 'nic-', copyIndex(variables('agentpool2Offset')))]",
"properties": {
Expand Down Expand Up @@ -1948,33 +1942,6 @@
},
"type": "Microsoft.Compute/availabilitySets"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"location": "[variables('location')]",
"name": "[variables('virtualNetworkName')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('vnetCidr')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnet')]",
"networkSecurityGroup": {
"id": "[variables('nsgID')]"
},
"routeTable": {
"id": "[variables('routeTableID')]"
}
}
}
]
},
"type": "Microsoft.Network/virtualNetworks"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"dependsOn": [
Expand Down Expand Up @@ -2036,9 +2003,6 @@
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"dependsOn": [
"[variables('vnetID')]"
],
"location": "[variables('location')]",
"name": "[variables('masterInternalLbName')]",
"properties": {
Expand Down Expand Up @@ -2132,7 +2096,6 @@
"name": "nicLoopNode"
},
"dependsOn": [
"[variables('vnetID')]",
"[concat(variables('masterLbID'),'/inboundNatRules/SSH-',variables('masterVMNamePrefix'),copyIndex(variables('masterOffset')))]",
"[variables('masterInternalLbName')]"
],
Expand Down