in kubetest/aksengine.go [461:621]
func (c *aksEngineDeployer) populateAPIModelTemplate() error {
var err error
v := AKSEngineAPIModel{}
if c.apiModelPath != "" {
// template already exists, read it
template, err := ioutil.ReadFile(path.Join(c.outputDir, "kubernetes.json"))
if err != nil {
return fmt.Errorf("error reading ApiModel template file: %v.", err)
}
dec := json.NewDecoder(bytes.NewReader(template))
// Enforce strict JSON
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return fmt.Errorf("error unmarshaling ApiModel template file: %w", err)
}
} else {
return fmt.Errorf("No template file specified %w", err)
}
// replace APIModel template properties from flags
if c.location != "" {
v.Location = c.location
}
if c.name != "" {
v.Name = c.name
}
if v.Properties.OrchestratorProfile == nil {
v.Properties.OrchestratorProfile = &OrchestratorProfile{}
}
if c.k8sVersion != "" {
v.Properties.OrchestratorProfile.OrchestratorRelease = c.k8sVersion
}
if v.Properties.OrchestratorProfile.KubernetesConfig == nil {
v.Properties.OrchestratorProfile.KubernetesConfig = &KubernetesConfig{}
}
// to support aks-engine validation logic `networkPolicy 'none' is not supported with networkPlugin 'azure'`
if v.Properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy != "none" && v.Properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin == "" {
// default NetworkPlugin to Azure if not provided
v.Properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin = c.networkPlugin
}
if c.dnsPrefix != "" {
v.Properties.MasterProfile.DNSPrefix = c.dnsPrefix
}
if c.masterVMSize != "" {
v.Properties.MasterProfile.VMSize = c.masterVMSize
}
if c.agentVMSize != "" {
for _, agentPool := range v.Properties.AgentPoolProfiles {
agentPool.VMSize = c.agentVMSize
}
}
if c.agentPoolCount != 0 {
for _, agentPool := range v.Properties.AgentPoolProfiles {
agentPool.Count = c.agentPoolCount
}
}
if c.adminUsername != "" {
v.Properties.LinuxProfile.AdminUsername = c.adminUsername
if v.Properties.WindowsProfile != nil {
v.Properties.WindowsProfile.AdminUsername = c.adminUsername
}
}
if c.adminPassword != "" {
if v.Properties.WindowsProfile != nil {
v.Properties.WindowsProfile.AdminPassword = c.adminPassword
}
}
v.Properties.LinuxProfile.SSHKeys.PublicKeys = []PublicKey{{
KeyData: c.sshPublicKey,
}}
if !toBool(v.Properties.OrchestratorProfile.KubernetesConfig.UseManagedIdentity) {
// prevent the nil pointer panic
v.Properties.ServicePrincipalProfile = &ServicePrincipalProfile{
ClientID: c.credentials.ClientID,
Secret: c.credentials.ClientSecret,
}
} else {
c.useManagedIdentity = true
if v.Properties.OrchestratorProfile.KubernetesConfig.UserAssignedID != "" {
c.identityName = v.Properties.OrchestratorProfile.KubernetesConfig.UserAssignedID
} else {
c.identityName = c.resourceGroup + "-id"
v.Properties.OrchestratorProfile.KubernetesConfig.UserAssignedID = c.identityName
}
}
if *aksWinBinaries {
v.Properties.OrchestratorProfile.KubernetesConfig.CustomWindowsPackageURL = c.aksCustomWinBinariesURL
}
if *aksCcm {
useCloudControllerManager := true
v.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = &useCloudControllerManager
v.Properties.OrchestratorProfile.KubernetesConfig.CustomCcmImage = c.customCcmImage
}
if *aksCnm {
cnmAddon := KubernetesAddon{
Name: cnmAddonName,
Enabled: boolPointer(true),
Containers: []KubernetesContainerSpec{
{
Name: cnmAddonName,
Image: c.customCnmImage,
},
},
}
appendAddonToAPIModel(&v, cnmAddon)
}
if *aksNodeProblemDetector {
nodeProblemDetectorAddon := KubernetesAddon{
Name: nodeProblemDetectorAddonName,
Enabled: boolPointer(true),
}
appendAddonToAPIModel(&v, nodeProblemDetectorAddon)
}
// Populate PrivateAzureRegistryServer field if we are using ACR and custom-built k8s components
if strings.Contains(imageRegistry, "azurecr") && c.aksDeploymentMethod != noop {
v.Properties.OrchestratorProfile.KubernetesConfig.PrivateAzureRegistryServer = imageRegistry
}
switch c.aksDeploymentMethod {
case customHyperkube:
v.Properties.OrchestratorProfile.KubernetesConfig.CustomKubeAPIServerImage = ""
v.Properties.OrchestratorProfile.KubernetesConfig.CustomKubeControllerManagerImage = ""
v.Properties.OrchestratorProfile.KubernetesConfig.CustomKubeProxyImage = ""
v.Properties.OrchestratorProfile.KubernetesConfig.CustomKubeSchedulerImage = ""
v.Properties.OrchestratorProfile.KubernetesConfig.CustomKubeBinaryURL = ""
v.Properties.OrchestratorProfile.KubernetesConfig.CustomHyperkubeImage = c.customHyperkubeImage
case customK8sComponents:
v.Properties.OrchestratorProfile.KubernetesConfig.CustomKubeAPIServerImage = c.customKubeAPIServerImage
v.Properties.OrchestratorProfile.KubernetesConfig.CustomKubeControllerManagerImage = c.customKubeControllerManagerImage
v.Properties.OrchestratorProfile.KubernetesConfig.CustomKubeProxyImage = c.customKubeProxyImage
v.Properties.OrchestratorProfile.KubernetesConfig.CustomKubeSchedulerImage = c.customKubeSchedulerImage
v.Properties.OrchestratorProfile.KubernetesConfig.CustomKubeBinaryURL = c.customKubeBinaryURL
v.Properties.OrchestratorProfile.KubernetesConfig.CustomHyperkubeImage = ""
}
if c.isAzureStackCloud() {
v.Properties.CustomCloudProfile.PortalURL = c.azureCustomCloudURL
}
if len(v.Properties.AgentPoolProfiles) > 0 {
// Default to VirtualMachineScaleSets if AvailabilityProfile is empty
isVMSS := v.Properties.AgentPoolProfiles[0].AvailabilityProfile == "" || v.Properties.AgentPoolProfiles[0].AvailabilityProfile == availabilityProfileVMSS
if err := populateAzureCloudConfig(isVMSS, *c.credentials, c.azureEnvironment, c.resourceGroup, c.location, c.outputDir); err != nil {
return err
}
}
// disable runUnattendedUpgradesOnBootstrap to avoid health check during node reboot
v.Properties.LinuxProfile.RunUnattendedUpgradesOnBootstrap = false
apiModel, _ := json.MarshalIndent(v, "", " ")
c.apiModelPath = path.Join(c.outputDir, "kubernetes.json")
err = ioutil.WriteFile(c.apiModelPath, apiModel, 0644)
if err != nil {
return fmt.Errorf("cannot write apimodel to file: %w", err)
}
return nil
}