Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 9f38909

Browse files
yangl900Cecile Robert-Michon
authored andcommitted
fix: Remove unnecessary transform on VMSS upgrade (#1633)
1 parent d195c81 commit 9f38909

File tree

5 files changed

+17
-2314
lines changed

5 files changed

+17
-2314
lines changed

pkg/engine/transform/transform.go

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,27 @@ import (
1515

1616
const (
1717
//Field names
18-
customDataFieldName = "customData"
19-
dependsOnFieldName = "dependsOn"
20-
hardwareProfileFieldName = "hardwareProfile"
21-
imageReferenceFieldName = "imageReference"
22-
nameFieldName = "name"
23-
osProfileFieldName = "osProfile"
24-
propertiesFieldName = "properties"
25-
resourcesFieldName = "resources"
26-
storageProfileFieldName = "storageProfile"
27-
typeFieldName = "type"
28-
virtualMachineProfileFieldName = "virtualMachineProfile"
29-
vmSizeFieldName = "vmSize"
30-
dataDisksFieldName = "dataDisks"
31-
createOptionFieldName = "createOption"
32-
tagsFieldName = "tags"
33-
managedDiskFieldName = "managedDisk"
34-
windowsConfigurationFieldName = "windowsConfiguration"
18+
customDataFieldName = "customData"
19+
dependsOnFieldName = "dependsOn"
20+
hardwareProfileFieldName = "hardwareProfile"
21+
imageReferenceFieldName = "imageReference"
22+
nameFieldName = "name"
23+
osProfileFieldName = "osProfile"
24+
propertiesFieldName = "properties"
25+
resourcesFieldName = "resources"
26+
storageProfileFieldName = "storageProfile"
27+
typeFieldName = "type"
28+
vmSizeFieldName = "vmSize"
29+
dataDisksFieldName = "dataDisks"
30+
createOptionFieldName = "createOption"
31+
tagsFieldName = "tags"
32+
managedDiskFieldName = "managedDisk"
33+
windowsConfigurationFieldName = "windowsConfiguration"
3534

3635
// ARM resource Types
3736
nsgResourceType = "Microsoft.Network/networkSecurityGroups"
3837
rtResourceType = "Microsoft.Network/routeTables"
3938
vmResourceType = "Microsoft.Compute/virtualMachines"
40-
vmssResourceType = "Microsoft.Compute/virtualMachineScaleSets"
4139
vmExtensionType = "Microsoft.Compute/virtualMachines/extensions"
4240
nicResourceType = "Microsoft.Network/networkInterfaces"
4341
vnetResourceType = "Microsoft.Network/virtualNetworks"
@@ -66,44 +64,6 @@ type Transformer struct {
6664
Translator Translator
6765
}
6866

69-
// NormalizeForVMSSScaling takes a template and removes elements that are unwanted in a VMSS scale up/down case
70-
func (t *Transformer) NormalizeForVMSSScaling(logger *logrus.Entry, templateMap map[string]interface{}) error {
71-
if err := t.NormalizeMasterResourcesForScaling(logger, templateMap); err != nil {
72-
return err
73-
}
74-
75-
resources := templateMap[resourcesFieldName].([]interface{})
76-
for _, resource := range resources {
77-
resourceMap, ok := resource.(map[string]interface{})
78-
if !ok {
79-
logger.Warnf("Template improperly formatted")
80-
continue
81-
}
82-
83-
resourceType, ok := resourceMap[typeFieldName].(string)
84-
if !ok || resourceType != vmssResourceType {
85-
continue
86-
}
87-
88-
resourceProperties, ok := resourceMap[propertiesFieldName].(map[string]interface{})
89-
if !ok {
90-
logger.Warnf("Template improperly formatted")
91-
continue
92-
}
93-
94-
virtualMachineProfile, ok := resourceProperties[virtualMachineProfileFieldName].(map[string]interface{})
95-
if !ok {
96-
logger.Warnf("Template improperly formatted")
97-
continue
98-
}
99-
100-
if !t.removeCustomData(logger, virtualMachineProfile) || !t.removeImageReference(logger, virtualMachineProfile) {
101-
continue
102-
}
103-
}
104-
return nil
105-
}
106-
10767
// NormalizeForK8sVMASScalingUp takes a template and removes elements that are unwanted in a K8s VMAS scale up/down case
10868
func (t *Transformer) NormalizeForK8sVMASScalingUp(logger *logrus.Entry, templateMap map[string]interface{}) error {
10969
if err := t.NormalizeMasterResourcesForScaling(logger, templateMap); err != nil {

pkg/engine/transform/transform_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,6 @@ import (
1515
"github.com/sirupsen/logrus"
1616
)
1717

18-
func TestNormalizeForVMSSScaling(t *testing.T) {
19-
RegisterTestingT(t)
20-
logger := logrus.New().WithField("testName", "TestNormalizeForVMSSScaling")
21-
fileContents, e := ioutil.ReadFile("./transformtestfiles/dcos_template.json")
22-
Expect(e).To(BeNil())
23-
expectedFileContents, e := ioutil.ReadFile("./transformtestfiles/dcos_scale_template.json")
24-
Expect(e).To(BeNil())
25-
templateJSON := string(fileContents)
26-
var template interface{}
27-
json.Unmarshal([]byte(templateJSON), &template)
28-
templateMap := template.(map[string]interface{})
29-
transformer := Transformer{}
30-
e = transformer.NormalizeForVMSSScaling(logger, templateMap)
31-
Expect(e).To(BeNil())
32-
ValidateTemplate(templateMap, expectedFileContents, "TestNormalizeForVMSSScaling")
33-
}
34-
3518
func TestNormalizeForK8sVMASScalingUp(t *testing.T) {
3619
RegisterTestingT(t)
3720
logger := logrus.New().WithField("testName", "TestNormalizeForK8sVMASScalingUp")

0 commit comments

Comments
 (0)