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

removing the vnet from scale templates #2994

Merged
merged 2 commits into from
May 17, 2018
Merged
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
24 changes: 21 additions & 3 deletions pkg/acsengine/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,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 @@ -155,6 +157,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 Down Expand Up @@ -183,6 +186,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 @@ -192,7 +203,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 @@ -210,11 +222,17 @@ func (t *Transformer) NormalizeForK8sVMASScalingUp(logger *logrus.Entry, templat
logger.Errorf(err.Error())
return err
}

if rtIndex == -1 {
logger.Infof("Found no resources with type %s in the template.", rtResourceType)
} else {
indexesToRemove = append(indexesToRemove, rtIndex)
}

if vnetIndex != -1 {
indexesToRemove = append(indexesToRemove, vnetIndex)
}

indexesToRemove = append(indexesToRemove, nsgIndex)
templateMap[resourcesFieldName] = removeIndexesFromArray(resources, indexesToRemove)

Expand Down
Loading