Skip to content

Commit

Permalink
chore: simplify upgrade templates (#4135)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrancis authored Jan 5, 2021
1 parent 4fbfc78 commit 1cd7af8
Show file tree
Hide file tree
Showing 9 changed files with 1,278 additions and 2,335 deletions.
394 changes: 218 additions & 176 deletions pkg/engine/transform/transform.go

Large diffs are not rendered by default.

30 changes: 1 addition & 29 deletions pkg/engine/transform/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestNormalizeForK8sAddVMASPool(t *testing.T) {
func TestNormalizeMasterResourcesForVMSSPoolUpgrade(t *testing.T) {
RegisterTestingT(t)
logger := logrus.New().WithField("testName", "TestNormalizeMasterResourcesForVMSSPoolUpgrade")
fileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_template.json")
fileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_slb_vmss_template.json")
Expect(e).To(BeNil())
expectedFileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_vmss_pool_upgrade_template.json")
Expect(e).To(BeNil())
Expand Down Expand Up @@ -150,34 +150,6 @@ func TestRemoveKMSResourcesFromTemplate(t *testing.T) {
ValidateTemplate(templateMap, expectedFileContents, "TestRemoveKMSResourcesFromTemplate")
}

func TestNormalizeResourcesForK8sMasterUpgrade(t *testing.T) {
RegisterTestingT(t)
logger := logrus.New().WithField("testName", "TestNormalizeResourcesForK8sMasterUpgrade")
fileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_template.json")
Expect(e).To(BeNil())
expectedFileContents, e := ioutil.ReadFile("./transformtestfiles/k8s_master_upgrade_template.json")
Expect(e).To(BeNil())
templateJSON := string(fileContents)
var template interface{}
e = json.Unmarshal([]byte(templateJSON), &template)
Expect(e).NotTo(HaveOccurred())
templateMap := template.(map[string]interface{})
transformer := &Transformer{
Translator: &i18n.Translator{
Locale: nil,
},
}
agentsToKeepMap := make(map[string]bool)
agentsToKeepMap["agentppol1"] = true // keep the typo or update the templates in ./transformtestfiles
agentsToKeepMap["agentpool2"] = true
// The usage of NormalizeResourcesForK8sMasterUpgrade across the code base seems to indicate that
// agentPoolsToPreserve == nil => master node upgrade
// so, maybe this test is not of much value
e = transformer.NormalizeResourcesForK8sMasterUpgrade(logger, templateMap, false, agentsToKeepMap)
Expect(e).To(BeNil())
ValidateTemplate(templateMap, expectedFileContents, "TestNormalizeResourcesForK8sMasterUpgrade")
}

func TestNormalizeResourcesForK8sAgentUpgrade(t *testing.T) {
RegisterTestingT(t)
logger := logrus.New().WithField("testName", "TestNormalizeResourcesForK8sAgentUpgrade")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1794,47 +1794,6 @@
"typeHandlerVersion": "2.0"
},
"type": "Microsoft.Compute/virtualMachines/extensions"
},
{
"apiVersion": "[variables('apiVersionDefault')]",
"copy": {
"count": "[sub(variables('agentpool2Count'), variables('agentpool2Offset'))]",
"name": "loop"
},
"location": "[variables('location')]",
"name": "[concat(variables('agentpool2VMNamePrefix'), 'nic-', copyIndex(variables('agentpool2Offset')))]",
"properties": {
"enableIPForwarding": true,
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"primary": true,
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('agentpool2VnetSubnetID')]"
}
}
}
]
},
"type": "Microsoft.Network/networkInterfaces"
},
{
"apiVersion": "[variables('apiVersionStorage')]",
"copy": {
"count": "[variables('agentpool2StorageAccountsCount')]",
"name": "loop"
},
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('masterPublicIPAddressName'))]"
],
"location": "[variables('location')]",
"name": "[concat(variables('storageAccountPrefixes')[mod(add(copyIndex(),variables('agentpool2StorageAccountOffset')),variables('storageAccountPrefixesCount'))],variables('storageAccountPrefixes')[div(add(copyIndex(),variables('agentpool2StorageAccountOffset')),variables('storageAccountPrefixesCount'))],variables('agentpool2AccountName'))]",
"properties": {
"accountType": "[variables('vmSizesMap')[variables('agentpool2VMSize')].storageAccountType]"
},
"type": "Microsoft.Storage/storageAccounts"
}
]
}

Large diffs are not rendered by default.

Loading

0 comments on commit 1cd7af8

Please sign in to comment.