Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
setting default Images in addon defaults instead of params_k8s.go
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqibrahim committed Nov 7, 2018
1 parent 61aac06 commit cb620fb
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 49 deletions.
49 changes: 9 additions & 40 deletions pkg/acsengine/params_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
addValue(parametersMap, "kubernetesTillerMemoryRequests", tillerAddon.Containers[tillerIndex].MemoryRequests)
addValue(parametersMap, "kubernetesTillerMemoryLimit", tillerAddon.Containers[tillerIndex].MemoryLimits)
addValue(parametersMap, "kubernetesTillerMaxHistory", tillerAddon.Config["max-history"])
if tillerAddon.Containers[tillerIndex].Image != "" {
addValue(parametersMap, "kubernetesTillerSpec", tillerAddon.Containers[tillerIndex].Image)
} else {
addValue(parametersMap, "kubernetesTillerSpec", cloudSpecConfig.KubernetesSpecConfig.TillerImageBase+k8sComponents[DefaultTillerAddonName])
}
addValue(parametersMap, "kubernetesTillerSpec", tillerAddon.Containers[tillerIndex].Image)
}
}
if kubernetesConfig.IsAADPodIdentityEnabled() {
Expand All @@ -87,11 +83,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
addValue(parametersMap, "kubernetesACIConnectorCPULimit", aciConnectorAddon.Containers[aciConnectorIndex].CPULimits)
addValue(parametersMap, "kubernetesACIConnectorMemoryRequests", aciConnectorAddon.Containers[aciConnectorIndex].MemoryRequests)
addValue(parametersMap, "kubernetesACIConnectorMemoryLimit", aciConnectorAddon.Containers[aciConnectorIndex].MemoryLimits)
if aciConnectorAddon.Containers[aciConnectorIndex].Image != "" {
addValue(parametersMap, "kubernetesACIConnectorSpec", aciConnectorAddon.Containers[aciConnectorIndex].Image)
} else {
addValue(parametersMap, "kubernetesACIConnectorSpec", cloudSpecConfig.KubernetesSpecConfig.ACIConnectorImageBase+k8sComponents[DefaultACIConnectorAddonName])
}
addValue(parametersMap, "kubernetesACIConnectorSpec", aciConnectorAddon.Containers[aciConnectorIndex].Image)
}
} else {
addValue(parametersMap, "kubernetesACIConnectorEnabled", false)
Expand All @@ -109,11 +101,8 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
addValue(parametersMap, "kubernetesClusterAutoscalerMaxNodes", clusterAutoscalerAddon.Config["maxNodes"])
addValue(parametersMap, "kubernetesClusterAutoscalerEnabled", true)
addValue(parametersMap, "kubernetesClusterAutoscalerUseManagedIdentity", strings.ToLower(strconv.FormatBool(kubernetesConfig.UseManagedIdentity)))
if clusterAutoscalerAddon.Containers[clusterAutoScalerIndex].Image != "" {
addValue(parametersMap, "kubernetesClusterAutoscalerSpec", clusterAutoscalerAddon.Containers[clusterAutoScalerIndex].Image)
} else {
addValue(parametersMap, "kubernetesClusterAutoscalerSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+k8sComponents[DefaultClusterAutoscalerAddonName])
}
addValue(parametersMap, "kubernetesClusterAutoscalerSpec", clusterAutoscalerAddon.Containers[clusterAutoScalerIndex].Image)

}
} else {
addValue(parametersMap, "kubernetesClusterAutoscalerEnabled", false)
Expand Down Expand Up @@ -154,11 +143,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
addValue(parametersMap, "kubernetesDashboardCPULimit", dashboardAddon.Containers[dashboardIndex].CPULimits)
addValue(parametersMap, "kubernetesDashboardMemoryRequests", dashboardAddon.Containers[dashboardIndex].MemoryRequests)
addValue(parametersMap, "kubernetesDashboardMemoryLimit", dashboardAddon.Containers[dashboardIndex].MemoryLimits)
if dashboardAddon.Containers[dashboardIndex].Image != "" {
addValue(parametersMap, "kubernetesDashboardSpec", dashboardAddon.Containers[dashboardIndex].Image)
} else {
addValue(parametersMap, "kubernetesDashboardSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+k8sComponents[DefaultDashboardAddonName])
}
addValue(parametersMap, "kubernetesDashboardSpec", dashboardAddon.Containers[dashboardIndex].Image)
}
}
if kubernetesConfig.IsReschedulerEnabled() {
Expand All @@ -169,11 +154,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
addValue(parametersMap, "kubernetesReschedulerCPULimit", reschedulerAddon.Containers[reschedulerIndex].CPULimits)
addValue(parametersMap, "kubernetesReschedulerMemoryRequests", reschedulerAddon.Containers[reschedulerIndex].MemoryRequests)
addValue(parametersMap, "kubernetesReschedulerMemoryLimit", reschedulerAddon.Containers[reschedulerIndex].MemoryLimits)
if reschedulerAddon.Containers[reschedulerIndex].Image != "" {
addValue(parametersMap, "kubernetesReschedulerSpec", reschedulerAddon.Containers[reschedulerIndex].Image)
} else {
addValue(parametersMap, "kubernetesReschedulerSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+k8sComponents[DefaultReschedulerAddonName])
}
addValue(parametersMap, "kubernetesReschedulerSpec", reschedulerAddon.Containers[reschedulerIndex].Image)
}
}
if properties.OrchestratorProfile.IsMetricsServerEnabled() {
Expand All @@ -195,11 +176,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
addValue(parametersMap, "kubernetesNVIDIADevicePluginCPULimit", nvidiaDevicePluginAddon.Containers[nvidiaPluginIndex].CPULimits)
addValue(parametersMap, "kubernetesNVIDIADevicePluginMemoryRequests", nvidiaDevicePluginAddon.Containers[nvidiaPluginIndex].MemoryRequests)
addValue(parametersMap, "kubernetesNVIDIADevicePluginMemoryLimit", nvidiaDevicePluginAddon.Containers[nvidiaPluginIndex].MemoryLimits)
if nvidiaDevicePluginAddon.Containers[nvidiaPluginIndex].Image != "" {
addValue(parametersMap, "kubernetesNVIDIADevicePluginSpec", nvidiaDevicePluginAddon.Containers[nvidiaPluginIndex].Image)
} else {
addValue(parametersMap, "kubernetesNVIDIADevicePluginSpec", cloudSpecConfig.KubernetesSpecConfig.NVIDIAImageBase+k8sComponents[NVIDIADevicePluginAddonName])
}
addValue(parametersMap, "kubernetesNVIDIADevicePluginSpec", nvidiaDevicePluginAddon.Containers[nvidiaPluginIndex].Image)
}
}
if kubernetesConfig.IsContainerMonitoringEnabled() {
Expand All @@ -214,11 +191,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
addValue(parametersMap, "kubernetesOMSAgentCPULimit", containerMonitoringAddon.Containers[omsagentIndex].CPULimits)
addValue(parametersMap, "kubernetesOMSAgentMemoryRequests", containerMonitoringAddon.Containers[omsagentIndex].MemoryRequests)
addValue(parametersMap, "kubernetesOMSAgentMemoryLimit", containerMonitoringAddon.Containers[omsagentIndex].MemoryLimits)
if containerMonitoringAddon.Containers[omsagentIndex].Image != "" {
addValue(parametersMap, "omsAgentImage", containerMonitoringAddon.Containers[omsagentIndex].Image)
} else {
addValue(parametersMap, "omsAgentImage", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+k8sComponents[ContainerMonitoringAddonName])
}
addValue(parametersMap, "omsAgentImage", containerMonitoringAddon.Containers[omsagentIndex].Image)
}
}
if kubernetesConfig.IsIPMasqAgentEnabled() {
Expand All @@ -241,11 +214,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
azureCNINetworkmonitorAddon := kubernetesConfig.GetAddonByName(AzureCNINetworkMonitoringAddonName)
azureCNIIndex := azureCNINetworkmonitorAddon.GetAddonContainersIndexByName(AzureCNINetworkMonitoringAddonName)
if azureCNIIndex > -1 {
if azureCNINetworkmonitorAddon.Containers[azureCNIIndex].Image != "" {
addValue(parametersMap, "AzureCNINetworkMonitorImageURL", azureCNINetworkmonitorAddon.Containers[azureCNIIndex].Image)
} else {
addValue(parametersMap, "AzureCNINetworkMonitorImageURL", cloudSpecConfig.KubernetesSpecConfig.AzureCNIImageBase+k8sComponents[AzureCNINetworkMonitoringAddonName])
}
addValue(parametersMap, "AzureCNINetworkMonitorImageURL", azureCNINetworkmonitorAddon.Containers[azureCNIIndex].Image)
}
}
if common.IsKubernetesVersionGe(k8sVersion, "1.12.0") {
Expand Down
15 changes: 13 additions & 2 deletions pkg/api/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (

func (cs *ContainerService) setAddonsConfig() {
o := cs.Properties.OrchestratorProfile
cloudSpecConfig := cs.GetCloudSpecConfig()
k8sComponents := K8sComponentsByVersionMap[o.OrchestratorVersion]
specConfig := cloudSpecConfig.KubernetesSpecConfig
defaultTillerAddonsConfig := KubernetesAddon{
Name: DefaultTillerAddonName,
Enabled: helpers.PointerToBool(DefaultTillerAddonEnabled),
Expand All @@ -19,6 +22,7 @@ func (cs *ContainerService) setAddonsConfig() {
MemoryRequests: "150Mi",
CPULimits: "50m",
MemoryLimits: "150Mi",
Image: specConfig.TillerImageBase + k8sComponents[DefaultTillerAddonName],
},
},
Config: map[string]string{
Expand All @@ -42,6 +46,7 @@ func (cs *ContainerService) setAddonsConfig() {
MemoryRequests: "150Mi",
CPULimits: "50m",
MemoryLimits: "150Mi",
Image: specConfig.ACIConnectorImageBase + k8sComponents[DefaultACIConnectorAddonName],
},
},
}
Expand All @@ -60,6 +65,7 @@ func (cs *ContainerService) setAddonsConfig() {
MemoryRequests: "300Mi",
CPULimits: "100m",
MemoryLimits: "300Mi",
Image: specConfig.KubernetesImageBase + k8sComponents[DefaultClusterAutoscalerAddonName],
},
},
}
Expand Down Expand Up @@ -116,6 +122,7 @@ func (cs *ContainerService) setAddonsConfig() {
MemoryRequests: "150Mi",
CPULimits: "300m",
MemoryLimits: "150Mi",
Image: specConfig.KubernetesImageBase + k8sComponents[DefaultDashboardAddonName],
},
},
}
Expand All @@ -130,6 +137,7 @@ func (cs *ContainerService) setAddonsConfig() {
MemoryRequests: "100Mi",
CPULimits: "10m",
MemoryLimits: "100Mi",
Image: specConfig.KubernetesImageBase + k8sComponents[DefaultReschedulerAddonName],
},
},
}
Expand All @@ -139,7 +147,8 @@ func (cs *ContainerService) setAddonsConfig() {
Enabled: k8sVersionMetricsServerAddonEnabled(o),
Containers: []KubernetesContainerSpec{
{
Name: DefaultMetricsServerAddonName,
Name: DefaultMetricsServerAddonName,
Image: specConfig.KubernetesImageBase + k8sComponents[DefaultMetricsServerAddonName],
},
},
}
Expand All @@ -155,6 +164,7 @@ func (cs *ContainerService) setAddonsConfig() {
MemoryRequests: "10Mi",
CPULimits: "50m",
MemoryLimits: "10Mi",
Image: specConfig.NVIDIAImageBase + k8sComponents[NVIDIADevicePluginAddonName],
},
},
}
Expand All @@ -169,11 +179,11 @@ func (cs *ContainerService) setAddonsConfig() {
Containers: []KubernetesContainerSpec{
{
Name: "omsagent",
Image: "microsoft/oms:ciprod10162018-2",
CPURequests: "50m",
MemoryRequests: "200Mi",
CPULimits: "150m",
MemoryLimits: "750Mi",
Image: "microsoft/oms:ciprod10162018-2",
},
},
}
Expand All @@ -198,6 +208,7 @@ func (cs *ContainerService) setAddonsConfig() {
Containers: []KubernetesContainerSpec{
{
Name: AzureCNINetworkMonitoringAddonName,
Image: specConfig.AzureCNIImageBase + k8sComponents[AzureCNINetworkMonitoringAddonName],
},
},
}
Expand Down
54 changes: 54 additions & 0 deletions pkg/api/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,60 @@ func TestAddonsIndexByName(t *testing.T) {
}
}

func TestAssignDefaultAddonImages(t *testing.T) {
addonNameMap := map[string]string{
DefaultTillerAddonName: "gcr.io/kubernetes-helm/tiller:v2.8.1",
DefaultACIConnectorAddonName: "microsoft/virtual-kubelet:latest",
DefaultClusterAutoscalerAddonName: "k8s.gcr.io/cluster-autoscaler:v1.2.2",
DefaultBlobfuseFlexVolumeAddonName: "",
DefaultSMBFlexVolumeAddonName: "",
DefaultKeyVaultFlexVolumeAddonName: "",
DefaultDashboardAddonName: "k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0",
DefaultReschedulerAddonName: "k8s.gcr.io/rescheduler:v0.3.1",
DefaultMetricsServerAddonName: "k8s.gcr.io/metrics-server-amd64:v0.2.1",
NVIDIADevicePluginAddonName: "nvidia/k8s-device-plugin:1.10",
ContainerMonitoringAddonName: "microsoft/oms:ciprod10162018-2",
IPMASQAgentAddonName: "",
AzureCNINetworkMonitoringAddonName: "containernetworking/networkmonitor:v0.0.4",
}

var addons []KubernetesAddon
for addonName, _ := range addonNameMap {
containerName := addonName
if addonName == ContainerMonitoringAddonName {
containerName = "omsagent"
}
customAddon := KubernetesAddon{
Name: addonName,
Enabled: helpers.PointerToBool(true),
Containers: []KubernetesContainerSpec{
{
Name: containerName,
CPURequests: "50m",
MemoryRequests: "150Mi",
CPULimits: "50m",
MemoryLimits: "150Mi",
},
},
}
addons = append(addons, customAddon)
}

mockCS := getMockBaseContainerService("1.10.8")
mockCS.Properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
mockCS.Properties.OrchestratorProfile.KubernetesConfig.Addons = addons
mockCS.SetPropertiesDefaults(false, false)
modifiedAddons := mockCS.Properties.OrchestratorProfile.KubernetesConfig.Addons

for _, addon := range modifiedAddons {
expected := addonNameMap[addon.Name]
actual := addon.Containers[0].Image
if actual != expected {
t.Errorf("expected setDefaults to set Image %s in addon %s, but got %s", expected, addon.Name, actual)
}
}
}

func TestAssignDefaultAddonVals(t *testing.T) {
addonName := "testaddon"
customCPURequests := "60m"
Expand Down
15 changes: 8 additions & 7 deletions pkg/api/k8s_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var k8sComponentVersions = map[string]map[string]string{
"tiller": "tiller:v2.8.1",
"rescheduler": "rescheduler:v0.4.0",
"aci-connector": "virtual-kubelet:latest",
ContainerMonitoringAddonName: "oms:ciprod05082018",
ContainerMonitoringAddonName: "microsoft/oms:ciprod10162018-2",
AzureCNINetworkMonitoringAddonName: "networkmonitor:v0.0.4",
"cluster-autoscaler": "cluster-autoscaler:v1.3.3",
NVIDIADevicePluginAddonName: "k8s-device-plugin:1.11",
Expand Down Expand Up @@ -56,7 +56,7 @@ var k8sComponentVersions = map[string]map[string]string{
"tiller": "tiller:v2.8.1",
"rescheduler": "rescheduler:v0.4.0",
"aci-connector": "virtual-kubelet:latest",
ContainerMonitoringAddonName: "oms:ciprod05082018",
ContainerMonitoringAddonName: "microsoft/oms:ciprod10162018-2",
AzureCNINetworkMonitoringAddonName: "networkmonitor:v0.0.4",
"cluster-autoscaler": "cluster-autoscaler:v1.3.3",
NVIDIADevicePluginAddonName: "k8s-device-plugin:1.11",
Expand Down Expand Up @@ -88,7 +88,7 @@ var k8sComponentVersions = map[string]map[string]string{
"tiller": "tiller:v2.8.1",
"rescheduler": "rescheduler:v0.4.0",
"aci-connector": "virtual-kubelet:latest",
ContainerMonitoringAddonName: "oms:ciprod05082018",
ContainerMonitoringAddonName: "microsoft/oms:ciprod10162018-2",
AzureCNINetworkMonitoringAddonName: "networkmonitor:v0.0.4",
"cluster-autoscaler": "cluster-autoscaler:v1.3.0",
NVIDIADevicePluginAddonName: "k8s-device-plugin:1.11",
Expand Down Expand Up @@ -120,7 +120,7 @@ var k8sComponentVersions = map[string]map[string]string{
"tiller": "tiller:v2.8.1",
"rescheduler": "rescheduler:v0.3.1",
"aci-connector": "virtual-kubelet:latest",
ContainerMonitoringAddonName: "oms:ciprod05082018",
ContainerMonitoringAddonName: "microsoft/oms:ciprod10162018-2",
AzureCNINetworkMonitoringAddonName: "networkmonitor:v0.0.4",
"cluster-autoscaler": "cluster-autoscaler:v1.2.2",
NVIDIADevicePluginAddonName: "k8s-device-plugin:1.10",
Expand Down Expand Up @@ -152,7 +152,7 @@ var k8sComponentVersions = map[string]map[string]string{
"tiller": "tiller:v2.8.1",
"rescheduler": "rescheduler:v0.3.1",
"aci-connector": "virtual-kubelet:latest",
ContainerMonitoringAddonName: "oms:ciprod05082018",
ContainerMonitoringAddonName: "microsoft/oms:ciprod10162018-2",
AzureCNINetworkMonitoringAddonName: "networkmonitor:v0.0.4",
"cluster-autoscaler": "cluster-autoscaler:v1.1.2",
"k8s-dns-sidecar": "k8s-dns-sidecar-amd64:1.14.7",
Expand Down Expand Up @@ -183,7 +183,7 @@ var k8sComponentVersions = map[string]map[string]string{
"tiller": "tiller:v2.8.1",
"rescheduler": "rescheduler:v0.3.1",
"aci-connector": "virtual-kubelet:latest",
ContainerMonitoringAddonName: "oms:ciprod05082018",
ContainerMonitoringAddonName: "microsoft/oms:ciprod10162018-2",
AzureCNINetworkMonitoringAddonName: "networkmonitor:v0.0.4",
"nodestatusfreq": DefaultKubernetesNodeStatusUpdateFrequency,
"nodegraceperiod": DefaultKubernetesCtrlMgrNodeMonitorGracePeriod,
Expand Down Expand Up @@ -212,7 +212,7 @@ var k8sComponentVersions = map[string]map[string]string{
"tiller": "tiller:v2.8.1",
"rescheduler": "rescheduler:v0.3.1",
"aci-connector": "virtual-kubelet:latest",
ContainerMonitoringAddonName: "oms:ciprod05082018",
ContainerMonitoringAddonName: "microsoft/oms:ciprod10162018-2",
AzureCNINetworkMonitoringAddonName: "networkmonitor:v0.0.4",
"nodestatusfreq": DefaultKubernetesNodeStatusUpdateFrequency,
"nodegraceperiod": DefaultKubernetesCtrlMgrNodeMonitorGracePeriod,
Expand Down Expand Up @@ -241,6 +241,7 @@ var k8sComponentVersions = map[string]map[string]string{
"tiller": "tiller:v2.8.1",
"rescheduler": "rescheduler:v0.3.1",
"aci-connector": "virtual-kubelet:latest",
ContainerMonitoringAddonName: "microsoft/oms:ciprod10162018-2",
AzureCNINetworkMonitoringAddonName: "networkmonitor:v0.0.4",
"nodestatusfreq": DefaultKubernetesNodeStatusUpdateFrequency,
"nodegraceperiod": DefaultKubernetesCtrlMgrNodeMonitorGracePeriod,
Expand Down

0 comments on commit cb620fb

Please sign in to comment.