Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ generate: bootstrap

.PHONY: generate-azure-constants
generate-azure-constants:
python pkg/engine/Get-AzureConstants.py
python pkg/helpers/Get-AzureConstants.py

.PHONY: build
build: generate
Expand Down
7 changes: 2 additions & 5 deletions pkg/engine/template_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,13 @@ func (t *TemplateGenerator) getTemplateFuncMap(cs *api.ContainerService) templat
return false
},
"GetMasterAllowedSizes": func() string {
return helpers.GetMasterAgentAllowedSizes()
return helpers.GetKubernetesAllowedSizes()
},
"GetDefaultVNETCIDR": func() string {
return DefaultVNETCIDR
},
"GetAgentAllowedSizes": func() string {
if cs.Properties.OrchestratorProfile.IsKubernetes() {
return helpers.GetKubernetesAgentAllowedSizes()
}
return helpers.GetMasterAgentAllowedSizes()
return helpers.GetKubernetesAllowedSizes()
},
"GetSizeMap": func() string {
return helpers.GetSizeMap()
Expand Down
77 changes: 11 additions & 66 deletions pkg/helpers/Get-AzureConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ def getAllSizes():

return sizeMap

min_cores_k8s = 1

def getMasterAgentMap(sizeMap):
agentMap = {}

for key in sizeMap.keys():
size = sizeMap[key]
if size['numberOfCores'] >= min_cores_k8s:
agentMap[size['name']] = size

return agentMap

def getLocations():
locations = json.loads(subprocess.check_output(['az', 'account', 'list-locations']).decode('utf-8'))

Expand All @@ -61,8 +49,11 @@ def getStorageAccountType(sizeName):
else:
return "Standard_LRS"

def getFileContents(masterAgentMap, kubernetesAgentMap, sizeMap, locations):
text = r"""package helpers
def getFileContents(kubernetesSizeMap, locations):
text = r"""// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

package helpers

// AUTOGENERATED FILE """

Expand Down Expand Up @@ -91,23 +82,11 @@ def getFileContents(masterAgentMap, kubernetesAgentMap, sizeMap, locations):
}
}

// GetMasterAgentAllowedSizes returns the agent allowed sizes
func GetMasterAgentAllowedSizes() string {
// GetKubernetesAllowedSizes returns the allowed sizes for Kubernetes agent
func GetKubernetesAllowedSizes() string {
return ` "allowedValues": [
"""
masterAgentMapKeys = sorted(masterAgentMap.keys())
for key in masterAgentMapKeys[:-1]:
text += ' "' + key + '",\n'
text += ' "' + masterAgentMapKeys[-1] + '"\n'
text += r""" ],
`
}

// GetKubernetesAgentAllowedSizes returns the allowed sizes for Kubernetes agent
func GetKubernetesAgentAllowedSizes() string {
return ` "allowedValues": [
"""
kubernetesAgentMapKeys = sorted(kubernetesAgentMap.keys())
kubernetesAgentMapKeys = sorted(kubernetesSizeMap.keys())
for key in kubernetesAgentMapKeys[:-1]:
text += ' "' + key + '",\n'
text += ' "' + kubernetesAgentMapKeys[-1] + '"\n'
Expand All @@ -121,7 +100,7 @@ def getFileContents(masterAgentMap, kubernetesAgentMap, sizeMap, locations):
"""
mergedMap = {}
for key in kubernetesAgentMapKeys:
size = kubernetesAgentMap[key]
size = kubernetesSizeMap[key]
if not key in mergedMap:
mergedMap[size['name']] = size

Expand All @@ -140,49 +119,15 @@ def getFileContents(masterAgentMap, kubernetesAgentMap, sizeMap, locations):

text += r""" }
`
}

// GetClassicAllowedSizes returns the classic allowed sizes
func GetClassicAllowedSizes() string {
return ` "allowedValues": [
"""
sizeMapKeys = sorted(sizeMap.keys())
for key in sizeMapKeys[:-1]:
text += ' "' + sizeMap[key]['name'] + '",\n'
key = sizeMapKeys[-1]
text += ' "' + sizeMap[key]['name'] + '"\n'

text += r""" ],
`
}

// GetClassicSizeMap returns the size / storage map
func GetClassicSizeMap() string {
return ` "vmSizesMap": {
"""
sizeMapKeys = sorted(sizeMap.keys())
for key in sizeMapKeys[:-1]:
text += ' "' + sizeMap[key]['name'] + '": {\n'
storageAccountType = getStorageAccountType(size['name'])
text += ' "storageAccountType": "' + storageAccountType + '"\n },\n'
key = sizeMapKeys[-1]
text += ' "' + sizeMap[key]['name'] + '": {\n'
storageAccountType = getStorageAccountType(size['name'])
text += ' "storageAccountType": "' + storageAccountType + '"\n }\n'

text += r""" }
`
}"""
return text


def main():
outfile = 'pkg/helpers/azureconst.go'
allSizes = getAllSizes()
masterAgentMap = getMasterAgentMap(allSizes)
kubernetesAgentMap = allSizes
kubernetesSizeMap = getAllSizes()
locations = getLocations()
text = getFileContents(masterAgentMap, kubernetesAgentMap, allSizes, locations)
text = getFileContents(kubernetesSizeMap, locations)

with open(outfile, 'w') as f:
f.write(text)
Expand Down
Loading