Skip to content

Commit 77d2ed5

Browse files
authored
Take AzureEnvironmentSpecConfig as param to various AgentBaker functions that use it. (#262)
* Take AzureEnvironmentSpecConfig as param to various AgentBaker functions that use it. The old code used the global mapping from cloud names to their corresponding AzureEnvironmentSpecConfig. It worked because the mapping existed globally in aks-engine code and was used by both AgentBaker and RP. Now AgentBaker and RP both use their own data models, instead of having two copies, we'll keep the canonical copy in RP and pass in the CloudSpecConfigs into AgentBaker functions. * Remove AzureCloudSpec, AzureGermanCloudSpec, AzureUSGovernmentCloudSpec and AzureChinaCloudSpec. They are not used in AgentBaker. AgentBaker requires caller to pass in the cloud config spec. * Use *AzureEnvironmentSpecConfig as param type for assignKubernetesParametersFromAgentProfile and assignKubernetesParameters. This makes the consistent with other functions in AgentBaker. * Use *AzureEnvironmentSpecConfig as param everywhere to be consistent.
1 parent 3d3a87d commit 77d2ed5

File tree

13 files changed

+197
-380
lines changed

13 files changed

+197
-380
lines changed

cmd/generate.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,27 @@ func newGenerateCmd() *cobra.Command {
6868
return errors.Wrap(err, "loading API model in generateCmd")
6969
}
7070

71-
return gc.run()
71+
azurePublicCloudSpec := &datamodel.AzureEnvironmentSpecConfig{
72+
CloudName: datamodel.AzurePublicCloud,
73+
//DockerSpecConfig specify the docker engine download repo
74+
DockerSpecConfig: datamodel.DefaultDockerSpecConfig,
75+
//KubernetesSpecConfig is the default kubernetes container image url.
76+
KubernetesSpecConfig: datamodel.DefaultKubernetesSpecConfig,
77+
78+
EndpointConfig: datamodel.AzureEndpointConfig{
79+
ResourceManagerVMDNSSuffix: "cloudapp.azure.com",
80+
},
81+
82+
OSImageConfig: map[datamodel.Distro]datamodel.AzureOSImageConfig{
83+
datamodel.Ubuntu: datamodel.Ubuntu1604OSImageConfig,
84+
datamodel.Ubuntu1804: datamodel.Ubuntu1804OSImageConfig,
85+
datamodel.Ubuntu1804Gen2: datamodel.Ubuntu1804Gen2OSImageConfig,
86+
datamodel.AKSUbuntu1604: datamodel.AKSUbuntu1604OSImageConfig,
87+
datamodel.AKSUbuntu1804: datamodel.AKSUbuntu1804OSImageConfig,
88+
},
89+
}
90+
91+
return gc.run(azurePublicCloudSpec)
7292
},
7393
}
7494

@@ -188,14 +208,14 @@ func (gc *generateCmd) autofillApimodel() error {
188208
return nil
189209
}
190210

191-
func (gc *generateCmd) run() error {
211+
func (gc *generateCmd) run(cloudSpecConfig *datamodel.AzureEnvironmentSpecConfig) error {
192212
log.Infoln(fmt.Sprintf("Generating assets into %s...", gc.outputDirectory))
193213

194214
err := gc.containerService.SetPropertiesDefaults(datamodel.PropertiesDefaultsParams{
195215
IsScale: false,
196216
IsUpgrade: false,
197217
PkiKeySize: helpers.DefaultPkiKeySize,
198-
})
218+
}, cloudSpecConfig)
199219
if err != nil {
200220
return errors.Wrapf(err, "in SetPropertiesDefaults template %s", gc.apimodelPath)
201221
}
@@ -213,6 +233,7 @@ func (gc *generateCmd) run() error {
213233

214234
config := &agent.NodeBootstrappingConfiguration{
215235
ContainerService: gc.containerService,
236+
CloudSpecConfig: cloudSpecConfig,
216237
AgentPoolProfile: gc.containerService.Properties.AgentPoolProfiles[0],
217238
TenantID: "<tenantid>",
218239
SubscriptionID: "<subid>",

pkg/agent/baker.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,19 +432,19 @@ func getContainerServiceFuncMap(config *NodeBootstrappingConfiguration) template
432432
return linuxProfile.ScriptRootURL
433433
},
434434
"GetAgentOSImageOffer": func(profile *datamodel.AgentPoolProfile) string {
435-
cloudSpecConfig := cs.GetCloudSpecConfig()
435+
cloudSpecConfig := config.CloudSpecConfig
436436
return fmt.Sprintf("\"%s\"", cloudSpecConfig.OSImageConfig[datamodel.Distro(profile.Distro)].ImageOffer)
437437
},
438438
"GetAgentOSImagePublisher": func(profile *datamodel.AgentPoolProfile) string {
439-
cloudSpecConfig := cs.GetCloudSpecConfig()
439+
cloudSpecConfig := config.CloudSpecConfig
440440
return fmt.Sprintf("\"%s\"", cloudSpecConfig.OSImageConfig[datamodel.Distro(profile.Distro)].ImagePublisher)
441441
},
442442
"GetAgentOSImageSKU": func(profile *datamodel.AgentPoolProfile) string {
443-
cloudSpecConfig := cs.GetCloudSpecConfig()
443+
cloudSpecConfig := config.CloudSpecConfig
444444
return fmt.Sprintf("\"%s\"", cloudSpecConfig.OSImageConfig[datamodel.Distro(profile.Distro)].ImageSku)
445445
},
446446
"GetAgentOSImageVersion": func(profile *datamodel.AgentPoolProfile) string {
447-
cloudSpecConfig := cs.GetCloudSpecConfig()
447+
cloudSpecConfig := config.CloudSpecConfig
448448
return fmt.Sprintf("\"%s\"", cloudSpecConfig.OSImageConfig[datamodel.Distro(profile.Distro)].ImageVersion)
449449
},
450450
"UseCloudControllerManager": func() bool {

pkg/agent/baker_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,28 @@ var _ = Describe("Assert generated customData and cseCmd", func() {
101101
agentPool := cs.Properties.AgentPoolProfiles[0]
102102
baker := InitializeTemplateGenerator()
103103

104+
azurePublicCloudSpec := &datamodel.AzureEnvironmentSpecConfig{
105+
CloudName: datamodel.AzurePublicCloud,
106+
//DockerSpecConfig specify the docker engine download repo
107+
DockerSpecConfig: datamodel.DefaultDockerSpecConfig,
108+
//KubernetesSpecConfig is the default kubernetes container image url.
109+
KubernetesSpecConfig: datamodel.DefaultKubernetesSpecConfig,
110+
111+
EndpointConfig: datamodel.AzureEndpointConfig{
112+
ResourceManagerVMDNSSuffix: "cloudapp.azure.com",
113+
},
114+
115+
OSImageConfig: map[datamodel.Distro]datamodel.AzureOSImageConfig{
116+
datamodel.Ubuntu: datamodel.Ubuntu1604OSImageConfig,
117+
datamodel.Ubuntu1804: datamodel.Ubuntu1804OSImageConfig,
118+
datamodel.Ubuntu1804Gen2: datamodel.Ubuntu1804Gen2OSImageConfig,
119+
datamodel.AKSUbuntu1604: datamodel.AKSUbuntu1604OSImageConfig,
120+
datamodel.AKSUbuntu1804: datamodel.AKSUbuntu1804OSImageConfig,
121+
},
122+
}
104123
config := &NodeBootstrappingConfiguration{
105124
ContainerService: cs,
125+
CloudSpecConfig: azurePublicCloudSpec,
106126
AgentPoolProfile: agentPool,
107127
TenantID: "tenantID",
108128
SubscriptionID: "subID",

pkg/agent/datamodel/azenvtypes.go

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -176,109 +176,4 @@ var (
176176
ImagePublisher: "Canonical",
177177
ImageVersion: "latest",
178178
}
179-
180-
//AzureCloudSpec is the default configurations for global azure.
181-
AzureCloudSpec = AzureEnvironmentSpecConfig{
182-
CloudName: AzurePublicCloud,
183-
//DockerSpecConfig specify the docker engine download repo
184-
DockerSpecConfig: DefaultDockerSpecConfig,
185-
//KubernetesSpecConfig is the default kubernetes container image url.
186-
KubernetesSpecConfig: DefaultKubernetesSpecConfig,
187-
188-
EndpointConfig: AzureEndpointConfig{
189-
ResourceManagerVMDNSSuffix: "cloudapp.azure.com",
190-
},
191-
192-
OSImageConfig: map[Distro]AzureOSImageConfig{
193-
Ubuntu: Ubuntu1604OSImageConfig,
194-
Ubuntu1804: Ubuntu1804OSImageConfig,
195-
Ubuntu1804Gen2: Ubuntu1804Gen2OSImageConfig,
196-
AKSUbuntu1604: AKSUbuntu1604OSImageConfig,
197-
AKSUbuntu1804: AKSUbuntu1804OSImageConfig,
198-
},
199-
}
200-
201-
//AzureGermanCloudSpec is the German cloud config.
202-
AzureGermanCloudSpec = AzureEnvironmentSpecConfig{
203-
CloudName: AzureGermanCloud,
204-
DockerSpecConfig: DefaultDockerSpecConfig,
205-
KubernetesSpecConfig: DefaultKubernetesSpecConfig,
206-
EndpointConfig: AzureEndpointConfig{
207-
ResourceManagerVMDNSSuffix: "cloudapp.microsoftazure.de",
208-
},
209-
OSImageConfig: map[Distro]AzureOSImageConfig{
210-
Ubuntu: Ubuntu1604OSImageConfig,
211-
Ubuntu1804: Ubuntu1804OSImageConfig,
212-
Ubuntu1804Gen2: Ubuntu1804Gen2OSImageConfig,
213-
AKSUbuntu1604: Ubuntu1604OSImageConfig,
214-
AKSUbuntu1804: Ubuntu1604OSImageConfig, // workaround for https://github.com/Azure/aks-engine/issues/761
215-
},
216-
}
217-
218-
//AzureUSGovernmentCloudSpec is the US government config.
219-
AzureUSGovernmentCloudSpec = AzureEnvironmentSpecConfig{
220-
CloudName: AzureUSGovernmentCloud,
221-
DockerSpecConfig: DefaultDockerSpecConfig,
222-
KubernetesSpecConfig: DefaultKubernetesSpecConfig,
223-
EndpointConfig: AzureEndpointConfig{
224-
ResourceManagerVMDNSSuffix: "cloudapp.usgovcloudapi.net",
225-
},
226-
OSImageConfig: map[Distro]AzureOSImageConfig{
227-
Ubuntu: Ubuntu1604OSImageConfig,
228-
Ubuntu1804: Ubuntu1804OSImageConfig,
229-
Ubuntu1804Gen2: Ubuntu1804Gen2OSImageConfig,
230-
AKSUbuntu1604: AKSUbuntu1604OSImageConfig,
231-
AKSUbuntu1804: AKSUbuntu1804OSImageConfig,
232-
},
233-
}
234-
235-
//AzureChinaCloudSpec is the configurations for Azure China (Mooncake)
236-
AzureChinaCloudSpec = AzureEnvironmentSpecConfig{
237-
CloudName: AzureChinaCloud,
238-
//DockerSpecConfig specify the docker engine download repo
239-
DockerSpecConfig: DockerSpecConfig{
240-
DockerEngineRepo: "https://mirror.azk8s.cn/docker-engine/apt/repo/",
241-
DockerComposeDownloadURL: "https://mirror.azk8s.cn/docker-toolbox/linux/compose",
242-
},
243-
//KubernetesSpecConfig - Due to Chinese firewall issue, the default containers from google is blocked, use the Chinese local mirror instead
244-
KubernetesSpecConfig: KubernetesSpecConfig{
245-
KubernetesImageBase: "gcr.azk8s.cn/google_containers/",
246-
TillerImageBase: "gcr.azk8s.cn/kubernetes-helm/",
247-
ACIConnectorImageBase: "dockerhub.azk8s.cn/microsoft/",
248-
NVIDIAImageBase: "dockerhub.azk8s.cn/nvidia/",
249-
AzureCNIImageBase: "mcr.azk8s.cn/containernetworking/",
250-
MCRKubernetesImageBase: "mcr.microsoft.com/",
251-
CalicoImageBase: "dockerhub.azk8s.cn/calico/",
252-
EtcdDownloadURLBase: "mcr.microsoft.com/oss/etcd-io/",
253-
KubeBinariesSASURLBase: DefaultKubernetesSpecConfig.KubeBinariesSASURLBase,
254-
WindowsTelemetryGUID: DefaultKubernetesSpecConfig.WindowsTelemetryGUID,
255-
CNIPluginsDownloadURL: "https://mirror.azk8s.cn/kubernetes/containernetworking-plugins/cni-plugins-amd64-" + CNIPluginVer + ".tgz",
256-
VnetCNILinuxPluginsDownloadURL: "https://mirror.azk8s.cn/azure-cni/" + AzureCniPluginVerLinux + "/binaries/azure-vnet-cni-linux-amd64-" + AzureCniPluginVerLinux + ".tgz",
257-
VnetCNIWindowsPluginsDownloadURL: "https://mirror.azk8s.cn/azure-cni/" + AzureCniPluginVerWindows + "/binaries/azure-vnet-cni-singletenancy-windows-amd64-" + AzureCniPluginVerWindows + ".zip",
258-
ContainerdDownloadURLBase: "https://mirror.azk8s.cn/kubernetes/containerd/",
259-
CSIProxyDownloadURL: "https://mirror.azk8s.cn/csi-proxy/v0.1.0/binaries/csi-proxy.tar.gz",
260-
WindowsProvisioningScriptsPackageURL: "https://mirror.azk8s.cn/aks-engine/windows/provisioning/signedscripts-" + DefaultWindowsProvisioningScriptsPackageVersion + ".zip",
261-
WindowsPauseImageURL: "mcr.microsoft.com/oss/kubernetes/pause:" + WindowsPauseImageVersion,
262-
AlwaysPullWindowsPauseImage: DefaultAlwaysPullWindowsPauseImage,
263-
},
264-
265-
EndpointConfig: AzureEndpointConfig{
266-
ResourceManagerVMDNSSuffix: "cloudapp.chinacloudapi.cn",
267-
},
268-
OSImageConfig: map[Distro]AzureOSImageConfig{
269-
Ubuntu: Ubuntu1604OSImageConfig,
270-
Ubuntu1804: Ubuntu1804OSImageConfig,
271-
Ubuntu1804Gen2: Ubuntu1804Gen2OSImageConfig,
272-
AKSUbuntu1604: AKSUbuntu1604OSImageConfig,
273-
AKSUbuntu1804: AKSUbuntu1804OSImageConfig,
274-
},
275-
}
276-
277-
// AzureCloudSpecEnvMap is the environment configuration map for all the Azure cloud environments.
278-
AzureCloudSpecEnvMap = map[string]AzureEnvironmentSpecConfig{
279-
AzureChinaCloud: AzureChinaCloudSpec,
280-
AzureGermanCloud: AzureGermanCloudSpec,
281-
AzureUSGovernmentCloud: AzureUSGovernmentCloudSpec,
282-
AzurePublicCloud: AzureCloudSpec,
283-
}
284179
)

pkg/agent/datamodel/defaults-kubelet_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ func TestProtectKernelDefaults(t *testing.T) {
562562
IsScale: false,
563563
IsUpgrade: false,
564564
PkiKeySize: helpers.DefaultPkiKeySize,
565-
})
565+
}, azurePublicCloudSpec)
566566
km := cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig
567567
if km["--protect-kernel-defaults"] != "true" {
568568
t.Fatalf("got unexpected '--protect-kernel-defaults' kubelet config value %s, the expected value is %s",
@@ -585,7 +585,7 @@ func TestProtectKernelDefaults(t *testing.T) {
585585
IsScale: false,
586586
IsUpgrade: false,
587587
PkiKeySize: helpers.DefaultPkiKeySize,
588-
})
588+
}, azurePublicCloudSpec)
589589
km = cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig
590590
if km["--protect-kernel-defaults"] != "true" {
591591
t.Fatalf("got unexpected '--protect-kernel-defaults' kubelet config value %s, the expected value is %s",
@@ -606,7 +606,7 @@ func TestProtectKernelDefaults(t *testing.T) {
606606
IsScale: false,
607607
IsUpgrade: false,
608608
PkiKeySize: helpers.DefaultPkiKeySize,
609-
})
609+
}, azurePublicCloudSpec)
610610
km = cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig
611611
if _, ok := km["--protect-kernel-defaults"]; ok {
612612
t.Fatalf("got unexpected '--protect-kernel-defaults' kubelet config value %s",
@@ -623,7 +623,7 @@ func TestProtectKernelDefaults(t *testing.T) {
623623
IsScale: false,
624624
IsUpgrade: false,
625625
PkiKeySize: helpers.DefaultPkiKeySize,
626-
})
626+
}, azurePublicCloudSpec)
627627
km = cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig
628628
if km["--protect-kernel-defaults"] != "true" {
629629
t.Fatalf("got unexpected '--protect-kernel-defaults' kubelet config value %s, the expected value is %s",
@@ -651,7 +651,7 @@ func TestProtectKernelDefaults(t *testing.T) {
651651
IsScale: false,
652652
IsUpgrade: false,
653653
PkiKeySize: helpers.DefaultPkiKeySize,
654-
})
654+
}, azurePublicCloudSpec)
655655
km = cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig
656656
if km["--protect-kernel-defaults"] != "false" {
657657
t.Fatalf("got unexpected '--protect-kernel-defaults' kubelet config value %s, the expected value is %s",

pkg/agent/datamodel/defaults.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type PropertiesDefaultsParams struct {
3131
}
3232

3333
// SetPropertiesDefaults for the container Properties
34-
func (cs *ContainerService) SetPropertiesDefaults(params PropertiesDefaultsParams) error {
34+
func (cs *ContainerService) SetPropertiesDefaults(params PropertiesDefaultsParams, cloudSpecConfig *AzureEnvironmentSpecConfig) error {
3535
// Set master profile defaults if this cluster configuration includes master node(s)
3636
if cs.Properties.MasterProfile != nil {
3737
cs.setMasterProfileDefaults(params.IsUpgrade)
@@ -43,7 +43,7 @@ func (cs *ContainerService) SetPropertiesDefaults(params PropertiesDefaultsParam
4343
cs.setAgentProfileDefaults(params.IsUpgrade, params.IsScale)
4444

4545
cs.setStorageDefaults()
46-
cs.setOrchestratorDefaults(params.IsUpgrade, params.IsScale)
46+
cs.setOrchestratorDefaults(params.IsUpgrade, params.IsScale, cloudSpecConfig)
4747
cs.setExtensionDefaults()
4848

4949
// Set hosted master profile defaults if this cluster configuration has a hosted control plane
@@ -61,11 +61,10 @@ func (cs *ContainerService) SetPropertiesDefaults(params PropertiesDefaultsParam
6161
}
6262

6363
// setOrchestratorDefaults for orchestrators
64-
func (cs *ContainerService) setOrchestratorDefaults(isUpgrade, isScale bool) {
64+
func (cs *ContainerService) setOrchestratorDefaults(isUpgrade, isScale bool, cloudSpecConfig *AzureEnvironmentSpecConfig) {
6565
isUpdate := isUpgrade || isScale
6666
a := cs.Properties
6767

68-
cloudSpecConfig := cs.GetCloudSpecConfig()
6968
if a.OrchestratorProfile == nil {
7069
return
7170
}

0 commit comments

Comments
 (0)