in pkg/engine/virtualmachines.go [17:217]
func CreateMasterVM(cs *api.ContainerService) VirtualMachineARM {
hasAvailabilityZones := cs.Properties.MasterProfile.HasAvailabilityZones()
isStorageAccount := cs.Properties.MasterProfile.IsStorageAccount()
kubernetesConfig := cs.Properties.OrchestratorProfile.KubernetesConfig
var useManagedIdentity, userAssignedIDEnabled bool
if kubernetesConfig != nil {
useManagedIdentity = to.Bool(kubernetesConfig.UseManagedIdentity)
userAssignedIDEnabled = kubernetesConfig.UserAssignedIDEnabled()
}
var dependencies []string
dependentNIC := "[concat('Microsoft.Network/networkInterfaces/', variables('masterVMNamePrefix'), 'nic-', copyIndex(variables('masterOffset')))]"
dependencies = append(dependencies, dependentNIC)
if !hasAvailabilityZones {
dependencies = append(dependencies, "[concat('Microsoft.Compute/availabilitySets/',variables('masterAvailabilitySet'))]")
}
if isStorageAccount {
dependencies = append(dependencies, "[variables('masterStorageAccountName')]")
}
armResource := ARMResource{
APIVersion: "[variables('apiVersionCompute')]",
Copy: map[string]string{
"count": "[sub(variables('masterCount'), variables('masterOffset'))]",
"name": "vmLoopNode",
},
DependsOn: dependencies,
}
vmTags := map[string]*string{
"creationSource": to.StringPtr("[concat(parameters('generatorCode'), '-', variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')))]"),
"resourceNameSuffix": to.StringPtr("[parameters('nameSuffix')]"),
"orchestrator": to.StringPtr("[variables('orchestratorNameVersionTag')]"),
"aksEngineVersion": to.StringPtr("[parameters('aksEngineVersion')]"),
"poolName": to.StringPtr("master"),
}
virtualMachine := compute.VirtualMachine{
Location: to.StringPtr("[variables('location')]"),
Name: to.StringPtr("[concat(variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')))]"),
Tags: vmTags,
Type: to.StringPtr("Microsoft.Compute/virtualMachines"),
}
addCustomTagsToVM(cs.Properties.MasterProfile.CustomVMTags, &virtualMachine)
if hasAvailabilityZones {
virtualMachine.Zones = &[]string{
"[string(parameters('availabilityZones')[mod(copyIndex(variables('masterOffset')), length(parameters('availabilityZones')))])]",
}
}
if useManagedIdentity {
identity := &compute.VirtualMachineIdentity{}
if userAssignedIDEnabled {
identity.Type = compute.ResourceIdentityTypeUserAssigned
identity.UserAssignedIdentities = map[string]*compute.VirtualMachineIdentityUserAssignedIdentitiesValue{
"[variables('userAssignedIDReference')]": {},
}
} else {
identity.Type = compute.ResourceIdentityTypeSystemAssigned
}
virtualMachine.Identity = identity
}
vmProperties := &compute.VirtualMachineProperties{}
if !hasAvailabilityZones {
vmProperties.AvailabilitySet = &compute.SubResource{
ID: to.StringPtr("[resourceId('Microsoft.Compute/availabilitySets',variables('masterAvailabilitySet'))]"),
}
}
vmProperties.HardwareProfile = &compute.HardwareProfile{
VMSize: compute.VirtualMachineSizeTypes(cs.Properties.MasterProfile.VMSize),
}
vmProperties.NetworkProfile = &compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{
{
ID: to.StringPtr("[resourceId('Microsoft.Network/networkInterfaces',concat(variables('masterVMNamePrefix'),'nic-', copyIndex(variables('masterOffset'))))]"),
},
},
}
osProfile := &compute.OSProfile{
AdminUsername: to.StringPtr("[parameters('linuxAdminUsername')]"),
ComputerName: to.StringPtr("[concat(variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')))]"),
LinuxConfiguration: &compute.LinuxConfiguration{
DisablePasswordAuthentication: to.BoolPtr(true),
},
}
linuxProfile := cs.Properties.LinuxProfile
if linuxProfile != nil && len(linuxProfile.SSH.PublicKeys) > 1 {
publicKeyPath := "[variables('sshKeyPath')]"
var publicKeys []compute.SSHPublicKey
for _, publicKey := range linuxProfile.SSH.PublicKeys {
publicKeyTrimmed := strings.TrimSpace(publicKey.KeyData)
publicKeys = append(publicKeys, compute.SSHPublicKey{
Path: &publicKeyPath,
KeyData: &publicKeyTrimmed,
})
}
osProfile.LinuxConfiguration.SSH = &compute.SSHConfiguration{
PublicKeys: &publicKeys,
}
} else {
osProfile.LinuxConfiguration.SSH = &compute.SSHConfiguration{
PublicKeys: &[]compute.SSHPublicKey{
{
KeyData: to.StringPtr("[parameters('sshRSAPublicKey')]"),
Path: to.StringPtr("[variables('sshKeyPath')]"),
},
},
}
}
t, err := InitializeTemplateGenerator(Context{})
customDataStr := getCustomDataFromJSON(t.GetMasterCustomDataJSONObject(cs))
osProfile.CustomData = to.StringPtr(customDataStr)
if err != nil {
panic(err)
}
if linuxProfile != nil && linuxProfile.HasSecrets() {
vsg := getVaultSecretGroup(linuxProfile)
osProfile.Secrets = &vsg
}
vmProperties.OsProfile = osProfile
storageProfile := &compute.StorageProfile{}
imageRef := cs.Properties.MasterProfile.ImageRef
etcdSizeGB, _ := strconv.ParseInt(kubernetesConfig.EtcdDiskSizeGB, 10, 32)
if !cs.Properties.MasterProfile.HasCosmosEtcd() {
dataDisk := compute.DataDisk{
CreateOption: compute.DiskCreateOptionTypesEmpty,
DiskSizeGB: to.Int32Ptr(int32(etcdSizeGB)),
Lun: to.Int32Ptr(0),
Name: to.StringPtr("[concat(variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')),'-etcddisk')]"),
}
if cs.Properties.MasterProfile.IsStorageAccount() {
dataDisk.Vhd = &compute.VirtualHardDisk{
URI: to.StringPtr("[concat(reference(concat('Microsoft.Storage/storageAccounts/',variables('masterStorageAccountName')),variables('apiVersionStorage')).primaryEndpoints.blob,'vhds/', variables('masterVMNamePrefix'),copyIndex(variables('masterOffset')),'-etcddisk.vhd')]"),
}
}
storageProfile.DataDisks = &[]compute.DataDisk{
dataDisk,
}
}
imgReference := &compute.ImageReference{}
if cs.Properties.MasterProfile.HasImageRef() {
if cs.Properties.MasterProfile.HasImageGallery() {
imgReference.ID = to.StringPtr(fmt.Sprintf("[concat('/subscriptions/', '%s', '/resourceGroups/', parameters('osImageResourceGroup'), '/providers/Microsoft.Compute/galleries/', '%s', '/images/', parameters('osImageName'), '/versions/', '%s')]", imageRef.SubscriptionID, imageRef.Gallery, imageRef.Version))
} else {
imgReference.ID = to.StringPtr("[resourceId(parameters('osImageResourceGroup'), 'Microsoft.Compute/images', parameters('osImageName'))]")
}
} else {
imgReference.Offer = to.StringPtr("[parameters('osImageOffer')]")
imgReference.Publisher = to.StringPtr("[parameters('osImagePublisher')]")
imgReference.Sku = to.StringPtr("[parameters('osImageSku')]")
imgReference.Version = to.StringPtr("[parameters('osImageVersion')]")
}
osDisk := &compute.OSDisk{
Caching: compute.CachingTypes(cs.Properties.MasterProfile.OSDiskCachingType),
CreateOption: compute.DiskCreateOptionTypesFromImage,
}
if isStorageAccount {
osDisk.Name = to.StringPtr("[concat(variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')),'-osdisk')]")
osDisk.Vhd = &compute.VirtualHardDisk{
URI: to.StringPtr("[concat(reference(concat('Microsoft.Storage/storageAccounts/',variables('masterStorageAccountName')),variables('apiVersionStorage')).primaryEndpoints.blob,'vhds/',variables('masterVMNamePrefix'),copyIndex(variables('masterOffset')),'-osdisk.vhd')]"),
}
}
if cs.Properties.MasterProfile.OSDiskSizeGB > 0 {
osDisk.DiskSizeGB = to.Int32Ptr(int32(cs.Properties.MasterProfile.OSDiskSizeGB))
}
if to.Bool(cs.Properties.MasterProfile.UltraSSDEnabled) {
vmProperties.AdditionalCapabilities = &compute.AdditionalCapabilities{
UltraSSDEnabled: to.BoolPtr(true),
}
}
storageProfile.OsDisk = osDisk
storageProfile.ImageReference = imgReference
vmProperties.StorageProfile = storageProfile
virtualMachine.VirtualMachineProperties = vmProperties
return VirtualMachineARM{
ARMResource: armResource,
VirtualMachine: virtualMachine,
}
}