Skip to content

Commit

Permalink
Take AzureEnvironmentSpecConfig as param to various AgentBaker functi…
Browse files Browse the repository at this point in the history
…ons 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.
  • Loading branch information
yizhang4321 authored Aug 26, 2020
1 parent 3d3a87d commit 77d2ed5
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 380 deletions.
27 changes: 24 additions & 3 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,27 @@ func newGenerateCmd() *cobra.Command {
return errors.Wrap(err, "loading API model in generateCmd")
}

return gc.run()
azurePublicCloudSpec := &datamodel.AzureEnvironmentSpecConfig{
CloudName: datamodel.AzurePublicCloud,
//DockerSpecConfig specify the docker engine download repo
DockerSpecConfig: datamodel.DefaultDockerSpecConfig,
//KubernetesSpecConfig is the default kubernetes container image url.
KubernetesSpecConfig: datamodel.DefaultKubernetesSpecConfig,

EndpointConfig: datamodel.AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.azure.com",
},

OSImageConfig: map[datamodel.Distro]datamodel.AzureOSImageConfig{
datamodel.Ubuntu: datamodel.Ubuntu1604OSImageConfig,
datamodel.Ubuntu1804: datamodel.Ubuntu1804OSImageConfig,
datamodel.Ubuntu1804Gen2: datamodel.Ubuntu1804Gen2OSImageConfig,
datamodel.AKSUbuntu1604: datamodel.AKSUbuntu1604OSImageConfig,
datamodel.AKSUbuntu1804: datamodel.AKSUbuntu1804OSImageConfig,
},
}

return gc.run(azurePublicCloudSpec)
},
}

Expand Down Expand Up @@ -188,14 +208,14 @@ func (gc *generateCmd) autofillApimodel() error {
return nil
}

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

err := gc.containerService.SetPropertiesDefaults(datamodel.PropertiesDefaultsParams{
IsScale: false,
IsUpgrade: false,
PkiKeySize: helpers.DefaultPkiKeySize,
})
}, cloudSpecConfig)
if err != nil {
return errors.Wrapf(err, "in SetPropertiesDefaults template %s", gc.apimodelPath)
}
Expand All @@ -213,6 +233,7 @@ func (gc *generateCmd) run() error {

config := &agent.NodeBootstrappingConfiguration{
ContainerService: gc.containerService,
CloudSpecConfig: cloudSpecConfig,
AgentPoolProfile: gc.containerService.Properties.AgentPoolProfiles[0],
TenantID: "<tenantid>",
SubscriptionID: "<subid>",
Expand Down
8 changes: 4 additions & 4 deletions pkg/agent/baker.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,19 @@ func getContainerServiceFuncMap(config *NodeBootstrappingConfiguration) template
return linuxProfile.ScriptRootURL
},
"GetAgentOSImageOffer": func(profile *datamodel.AgentPoolProfile) string {
cloudSpecConfig := cs.GetCloudSpecConfig()
cloudSpecConfig := config.CloudSpecConfig
return fmt.Sprintf("\"%s\"", cloudSpecConfig.OSImageConfig[datamodel.Distro(profile.Distro)].ImageOffer)
},
"GetAgentOSImagePublisher": func(profile *datamodel.AgentPoolProfile) string {
cloudSpecConfig := cs.GetCloudSpecConfig()
cloudSpecConfig := config.CloudSpecConfig
return fmt.Sprintf("\"%s\"", cloudSpecConfig.OSImageConfig[datamodel.Distro(profile.Distro)].ImagePublisher)
},
"GetAgentOSImageSKU": func(profile *datamodel.AgentPoolProfile) string {
cloudSpecConfig := cs.GetCloudSpecConfig()
cloudSpecConfig := config.CloudSpecConfig
return fmt.Sprintf("\"%s\"", cloudSpecConfig.OSImageConfig[datamodel.Distro(profile.Distro)].ImageSku)
},
"GetAgentOSImageVersion": func(profile *datamodel.AgentPoolProfile) string {
cloudSpecConfig := cs.GetCloudSpecConfig()
cloudSpecConfig := config.CloudSpecConfig
return fmt.Sprintf("\"%s\"", cloudSpecConfig.OSImageConfig[datamodel.Distro(profile.Distro)].ImageVersion)
},
"UseCloudControllerManager": func() bool {
Expand Down
20 changes: 20 additions & 0 deletions pkg/agent/baker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,28 @@ var _ = Describe("Assert generated customData and cseCmd", func() {
agentPool := cs.Properties.AgentPoolProfiles[0]
baker := InitializeTemplateGenerator()

azurePublicCloudSpec := &datamodel.AzureEnvironmentSpecConfig{
CloudName: datamodel.AzurePublicCloud,
//DockerSpecConfig specify the docker engine download repo
DockerSpecConfig: datamodel.DefaultDockerSpecConfig,
//KubernetesSpecConfig is the default kubernetes container image url.
KubernetesSpecConfig: datamodel.DefaultKubernetesSpecConfig,

EndpointConfig: datamodel.AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.azure.com",
},

OSImageConfig: map[datamodel.Distro]datamodel.AzureOSImageConfig{
datamodel.Ubuntu: datamodel.Ubuntu1604OSImageConfig,
datamodel.Ubuntu1804: datamodel.Ubuntu1804OSImageConfig,
datamodel.Ubuntu1804Gen2: datamodel.Ubuntu1804Gen2OSImageConfig,
datamodel.AKSUbuntu1604: datamodel.AKSUbuntu1604OSImageConfig,
datamodel.AKSUbuntu1804: datamodel.AKSUbuntu1804OSImageConfig,
},
}
config := &NodeBootstrappingConfiguration{
ContainerService: cs,
CloudSpecConfig: azurePublicCloudSpec,
AgentPoolProfile: agentPool,
TenantID: "tenantID",
SubscriptionID: "subID",
Expand Down
105 changes: 0 additions & 105 deletions pkg/agent/datamodel/azenvtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,109 +176,4 @@ var (
ImagePublisher: "Canonical",
ImageVersion: "latest",
}

//AzureCloudSpec is the default configurations for global azure.
AzureCloudSpec = AzureEnvironmentSpecConfig{
CloudName: AzurePublicCloud,
//DockerSpecConfig specify the docker engine download repo
DockerSpecConfig: DefaultDockerSpecConfig,
//KubernetesSpecConfig is the default kubernetes container image url.
KubernetesSpecConfig: DefaultKubernetesSpecConfig,

EndpointConfig: AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.azure.com",
},

OSImageConfig: map[Distro]AzureOSImageConfig{
Ubuntu: Ubuntu1604OSImageConfig,
Ubuntu1804: Ubuntu1804OSImageConfig,
Ubuntu1804Gen2: Ubuntu1804Gen2OSImageConfig,
AKSUbuntu1604: AKSUbuntu1604OSImageConfig,
AKSUbuntu1804: AKSUbuntu1804OSImageConfig,
},
}

//AzureGermanCloudSpec is the German cloud config.
AzureGermanCloudSpec = AzureEnvironmentSpecConfig{
CloudName: AzureGermanCloud,
DockerSpecConfig: DefaultDockerSpecConfig,
KubernetesSpecConfig: DefaultKubernetesSpecConfig,
EndpointConfig: AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.microsoftazure.de",
},
OSImageConfig: map[Distro]AzureOSImageConfig{
Ubuntu: Ubuntu1604OSImageConfig,
Ubuntu1804: Ubuntu1804OSImageConfig,
Ubuntu1804Gen2: Ubuntu1804Gen2OSImageConfig,
AKSUbuntu1604: Ubuntu1604OSImageConfig,
AKSUbuntu1804: Ubuntu1604OSImageConfig, // workaround for https://github.com/Azure/aks-engine/issues/761
},
}

//AzureUSGovernmentCloudSpec is the US government config.
AzureUSGovernmentCloudSpec = AzureEnvironmentSpecConfig{
CloudName: AzureUSGovernmentCloud,
DockerSpecConfig: DefaultDockerSpecConfig,
KubernetesSpecConfig: DefaultKubernetesSpecConfig,
EndpointConfig: AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.usgovcloudapi.net",
},
OSImageConfig: map[Distro]AzureOSImageConfig{
Ubuntu: Ubuntu1604OSImageConfig,
Ubuntu1804: Ubuntu1804OSImageConfig,
Ubuntu1804Gen2: Ubuntu1804Gen2OSImageConfig,
AKSUbuntu1604: AKSUbuntu1604OSImageConfig,
AKSUbuntu1804: AKSUbuntu1804OSImageConfig,
},
}

//AzureChinaCloudSpec is the configurations for Azure China (Mooncake)
AzureChinaCloudSpec = AzureEnvironmentSpecConfig{
CloudName: AzureChinaCloud,
//DockerSpecConfig specify the docker engine download repo
DockerSpecConfig: DockerSpecConfig{
DockerEngineRepo: "https://mirror.azk8s.cn/docker-engine/apt/repo/",
DockerComposeDownloadURL: "https://mirror.azk8s.cn/docker-toolbox/linux/compose",
},
//KubernetesSpecConfig - Due to Chinese firewall issue, the default containers from google is blocked, use the Chinese local mirror instead
KubernetesSpecConfig: KubernetesSpecConfig{
KubernetesImageBase: "gcr.azk8s.cn/google_containers/",
TillerImageBase: "gcr.azk8s.cn/kubernetes-helm/",
ACIConnectorImageBase: "dockerhub.azk8s.cn/microsoft/",
NVIDIAImageBase: "dockerhub.azk8s.cn/nvidia/",
AzureCNIImageBase: "mcr.azk8s.cn/containernetworking/",
MCRKubernetesImageBase: "mcr.microsoft.com/",
CalicoImageBase: "dockerhub.azk8s.cn/calico/",
EtcdDownloadURLBase: "mcr.microsoft.com/oss/etcd-io/",
KubeBinariesSASURLBase: DefaultKubernetesSpecConfig.KubeBinariesSASURLBase,
WindowsTelemetryGUID: DefaultKubernetesSpecConfig.WindowsTelemetryGUID,
CNIPluginsDownloadURL: "https://mirror.azk8s.cn/kubernetes/containernetworking-plugins/cni-plugins-amd64-" + CNIPluginVer + ".tgz",
VnetCNILinuxPluginsDownloadURL: "https://mirror.azk8s.cn/azure-cni/" + AzureCniPluginVerLinux + "/binaries/azure-vnet-cni-linux-amd64-" + AzureCniPluginVerLinux + ".tgz",
VnetCNIWindowsPluginsDownloadURL: "https://mirror.azk8s.cn/azure-cni/" + AzureCniPluginVerWindows + "/binaries/azure-vnet-cni-singletenancy-windows-amd64-" + AzureCniPluginVerWindows + ".zip",
ContainerdDownloadURLBase: "https://mirror.azk8s.cn/kubernetes/containerd/",
CSIProxyDownloadURL: "https://mirror.azk8s.cn/csi-proxy/v0.1.0/binaries/csi-proxy.tar.gz",
WindowsProvisioningScriptsPackageURL: "https://mirror.azk8s.cn/aks-engine/windows/provisioning/signedscripts-" + DefaultWindowsProvisioningScriptsPackageVersion + ".zip",
WindowsPauseImageURL: "mcr.microsoft.com/oss/kubernetes/pause:" + WindowsPauseImageVersion,
AlwaysPullWindowsPauseImage: DefaultAlwaysPullWindowsPauseImage,
},

EndpointConfig: AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.chinacloudapi.cn",
},
OSImageConfig: map[Distro]AzureOSImageConfig{
Ubuntu: Ubuntu1604OSImageConfig,
Ubuntu1804: Ubuntu1804OSImageConfig,
Ubuntu1804Gen2: Ubuntu1804Gen2OSImageConfig,
AKSUbuntu1604: AKSUbuntu1604OSImageConfig,
AKSUbuntu1804: AKSUbuntu1804OSImageConfig,
},
}

// AzureCloudSpecEnvMap is the environment configuration map for all the Azure cloud environments.
AzureCloudSpecEnvMap = map[string]AzureEnvironmentSpecConfig{
AzureChinaCloud: AzureChinaCloudSpec,
AzureGermanCloud: AzureGermanCloudSpec,
AzureUSGovernmentCloud: AzureUSGovernmentCloudSpec,
AzurePublicCloud: AzureCloudSpec,
}
)
10 changes: 5 additions & 5 deletions pkg/agent/datamodel/defaults-kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ func TestProtectKernelDefaults(t *testing.T) {
IsScale: false,
IsUpgrade: false,
PkiKeySize: helpers.DefaultPkiKeySize,
})
}, azurePublicCloudSpec)
km := cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig
if km["--protect-kernel-defaults"] != "true" {
t.Fatalf("got unexpected '--protect-kernel-defaults' kubelet config value %s, the expected value is %s",
Expand All @@ -585,7 +585,7 @@ func TestProtectKernelDefaults(t *testing.T) {
IsScale: false,
IsUpgrade: false,
PkiKeySize: helpers.DefaultPkiKeySize,
})
}, azurePublicCloudSpec)
km = cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig
if km["--protect-kernel-defaults"] != "true" {
t.Fatalf("got unexpected '--protect-kernel-defaults' kubelet config value %s, the expected value is %s",
Expand All @@ -606,7 +606,7 @@ func TestProtectKernelDefaults(t *testing.T) {
IsScale: false,
IsUpgrade: false,
PkiKeySize: helpers.DefaultPkiKeySize,
})
}, azurePublicCloudSpec)
km = cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig
if _, ok := km["--protect-kernel-defaults"]; ok {
t.Fatalf("got unexpected '--protect-kernel-defaults' kubelet config value %s",
Expand All @@ -623,7 +623,7 @@ func TestProtectKernelDefaults(t *testing.T) {
IsScale: false,
IsUpgrade: false,
PkiKeySize: helpers.DefaultPkiKeySize,
})
}, azurePublicCloudSpec)
km = cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig
if km["--protect-kernel-defaults"] != "true" {
t.Fatalf("got unexpected '--protect-kernel-defaults' kubelet config value %s, the expected value is %s",
Expand Down Expand Up @@ -651,7 +651,7 @@ func TestProtectKernelDefaults(t *testing.T) {
IsScale: false,
IsUpgrade: false,
PkiKeySize: helpers.DefaultPkiKeySize,
})
}, azurePublicCloudSpec)
km = cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig
if km["--protect-kernel-defaults"] != "false" {
t.Fatalf("got unexpected '--protect-kernel-defaults' kubelet config value %s, the expected value is %s",
Expand Down
7 changes: 3 additions & 4 deletions pkg/agent/datamodel/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type PropertiesDefaultsParams struct {
}

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

cs.setStorageDefaults()
cs.setOrchestratorDefaults(params.IsUpgrade, params.IsScale)
cs.setOrchestratorDefaults(params.IsUpgrade, params.IsScale, cloudSpecConfig)
cs.setExtensionDefaults()

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

// setOrchestratorDefaults for orchestrators
func (cs *ContainerService) setOrchestratorDefaults(isUpgrade, isScale bool) {
func (cs *ContainerService) setOrchestratorDefaults(isUpgrade, isScale bool, cloudSpecConfig *AzureEnvironmentSpecConfig) {
isUpdate := isUpgrade || isScale
a := cs.Properties

cloudSpecConfig := cs.GetCloudSpecConfig()
if a.OrchestratorProfile == nil {
return
}
Expand Down
Loading

0 comments on commit 77d2ed5

Please sign in to comment.