From 1ff1113232680093fa968f7d948eda377f0c4da7 Mon Sep 17 00:00:00 2001 From: Tariq Ibrahim Date: Mon, 22 Oct 2018 09:14:09 -0700 Subject: [PATCH] Fix issue where kubernetesDashboard params weren't being added despite e enabling the dashboard addon (#4084) --- pkg/acsengine/params_k8s.go | 180 +++++++++++++++---------------- pkg/acsengine/params_k8s_test.go | 128 ++++++++++++++++++++++ pkg/api/mocks.go | 45 ++++++++ 3 files changed, 263 insertions(+), 90 deletions(-) diff --git a/pkg/acsengine/params_k8s.go b/pkg/acsengine/params_k8s.go index 752f636565..70ba8d4053 100644 --- a/pkg/acsengine/params_k8s.go +++ b/pkg/acsengine/params_k8s.go @@ -53,15 +53,15 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params addValue(parametersMap, "kubernetesHeapsterSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+k8sComponents["heapster"]) if kubernetesConfig.IsTillerEnabled() { tillerAddon := kubernetesConfig.GetAddonByName(DefaultTillerAddonName) - c := tillerAddon.GetAddonContainersIndexByName(DefaultTillerAddonName) - if c > -1 { - addValue(parametersMap, "kubernetesTillerCPURequests", tillerAddon.Containers[c].CPURequests) - addValue(parametersMap, "kubernetesTillerCPULimit", tillerAddon.Containers[c].CPULimits) - addValue(parametersMap, "kubernetesTillerMemoryRequests", tillerAddon.Containers[c].MemoryRequests) - addValue(parametersMap, "kubernetesTillerMemoryLimit", tillerAddon.Containers[c].MemoryLimits) + tillerIndex := tillerAddon.GetAddonContainersIndexByName(DefaultTillerAddonName) + if tillerIndex > -1 { + addValue(parametersMap, "kubernetesTillerCPURequests", tillerAddon.Containers[tillerIndex].CPURequests) + addValue(parametersMap, "kubernetesTillerCPULimit", tillerAddon.Containers[tillerIndex].CPULimits) + addValue(parametersMap, "kubernetesTillerMemoryRequests", tillerAddon.Containers[tillerIndex].MemoryRequests) + addValue(parametersMap, "kubernetesTillerMemoryLimit", tillerAddon.Containers[tillerIndex].MemoryLimits) addValue(parametersMap, "kubernetesTillerMaxHistory", tillerAddon.Config["max-history"]) - if tillerAddon.Containers[c].Image != "" { - addValue(parametersMap, "kubernetesTillerSpec", tillerAddon.Containers[c].Image) + if tillerAddon.Containers[tillerIndex].Image != "" { + addValue(parametersMap, "kubernetesTillerSpec", tillerAddon.Containers[tillerIndex].Image) } else { addValue(parametersMap, "kubernetesTillerSpec", cloudSpecConfig.KubernetesSpecConfig.TillerImageBase+k8sComponents[DefaultTillerAddonName]) } @@ -69,26 +69,26 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params } if kubernetesConfig.IsAADPodIdentityEnabled() { aadPodIdentityAddon := kubernetesConfig.GetAddonByName(DefaultAADPodIdentityAddonName) - c := aadPodIdentityAddon.GetAddonContainersIndexByName(DefaultAADPodIdentityAddonName) - if c > -1 { + aadIndex := aadPodIdentityAddon.GetAddonContainersIndexByName(DefaultAADPodIdentityAddonName) + if aadIndex > -1 { addValue(parametersMap, "kubernetesAADPodIdentityEnabled", helpers.IsTrueBoolPointer(aadPodIdentityAddon.Enabled)) } } if kubernetesConfig.IsACIConnectorEnabled() { aciConnectorAddon := kubernetesConfig.GetAddonByName(DefaultACIConnectorAddonName) - c := aciConnectorAddon.GetAddonContainersIndexByName(DefaultACIConnectorAddonName) - if c > -1 { + aciConnectorIndex := aciConnectorAddon.GetAddonContainersIndexByName(DefaultACIConnectorAddonName) + if aciConnectorIndex > -1 { addValue(parametersMap, "kubernetesACIConnectorEnabled", true) addValue(parametersMap, "kubernetesACIConnectorNodeName", aciConnectorAddon.Config["nodeName"]) addValue(parametersMap, "kubernetesACIConnectorOS", aciConnectorAddon.Config["os"]) addValue(parametersMap, "kubernetesACIConnectorTaint", aciConnectorAddon.Config["taint"]) addValue(parametersMap, "kubernetesACIConnectorRegion", aciConnectorAddon.Config["region"]) - addValue(parametersMap, "kubernetesACIConnectorCPURequests", aciConnectorAddon.Containers[c].CPURequests) - addValue(parametersMap, "kubernetesACIConnectorCPULimit", aciConnectorAddon.Containers[c].CPULimits) - addValue(parametersMap, "kubernetesACIConnectorMemoryRequests", aciConnectorAddon.Containers[c].MemoryRequests) - addValue(parametersMap, "kubernetesACIConnectorMemoryLimit", aciConnectorAddon.Containers[c].MemoryLimits) - if aciConnectorAddon.Containers[c].Image != "" { - addValue(parametersMap, "kubernetesACIConnectorSpec", aciConnectorAddon.Containers[c].Image) + addValue(parametersMap, "kubernetesACIConnectorCPURequests", aciConnectorAddon.Containers[aciConnectorIndex].CPURequests) + 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]) } @@ -98,19 +98,19 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params } if kubernetesConfig.IsClusterAutoscalerEnabled() { clusterAutoscalerAddon := kubernetesConfig.GetAddonByName(DefaultClusterAutoscalerAddonName) - c := clusterAutoscalerAddon.GetAddonContainersIndexByName(DefaultClusterAutoscalerAddonName) - if c > -1 { + clusterAutoScalerIndex := clusterAutoscalerAddon.GetAddonContainersIndexByName(DefaultClusterAutoscalerAddonName) + if clusterAutoScalerIndex > -1 { addValue(parametersMap, "kubernetesClusterAutoscalerAzureCloud", cloudSpecConfig.CloudName) - addValue(parametersMap, "kubernetesClusterAutoscalerCPURequests", clusterAutoscalerAddon.Containers[c].CPURequests) - addValue(parametersMap, "kubernetesClusterAutoscalerCPULimit", clusterAutoscalerAddon.Containers[c].CPULimits) - addValue(parametersMap, "kubernetesClusterAutoscalerMemoryRequests", clusterAutoscalerAddon.Containers[c].MemoryRequests) - addValue(parametersMap, "kubernetesClusterAutoscalerMemoryLimit", clusterAutoscalerAddon.Containers[c].MemoryLimits) + addValue(parametersMap, "kubernetesClusterAutoscalerCPURequests", clusterAutoscalerAddon.Containers[clusterAutoScalerIndex].CPURequests) + addValue(parametersMap, "kubernetesClusterAutoscalerCPULimit", clusterAutoscalerAddon.Containers[clusterAutoScalerIndex].CPULimits) + addValue(parametersMap, "kubernetesClusterAutoscalerMemoryRequests", clusterAutoscalerAddon.Containers[clusterAutoScalerIndex].MemoryRequests) + addValue(parametersMap, "kubernetesClusterAutoscalerMemoryLimit", clusterAutoscalerAddon.Containers[clusterAutoScalerIndex].MemoryLimits) addValue(parametersMap, "kubernetesClusterAutoscalerMinNodes", clusterAutoscalerAddon.Config["minNodes"]) addValue(parametersMap, "kubernetesClusterAutoscalerMaxNodes", clusterAutoscalerAddon.Config["maxNodes"]) addValue(parametersMap, "kubernetesClusterAutoscalerEnabled", true) addValue(parametersMap, "kubernetesClusterAutoscalerUseManagedIdentity", strings.ToLower(strconv.FormatBool(kubernetesConfig.UseManagedIdentity))) - if clusterAutoscalerAddon.Containers[c].Image != "" { - addValue(parametersMap, "kubernetesClusterAutoscalerSpec", clusterAutoscalerAddon.Containers[c].Image) + if clusterAutoscalerAddon.Containers[clusterAutoScalerIndex].Image != "" { + addValue(parametersMap, "kubernetesClusterAutoscalerSpec", clusterAutoscalerAddon.Containers[clusterAutoScalerIndex].Image) } else { addValue(parametersMap, "kubernetesClusterAutoscalerSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+k8sComponents[DefaultClusterAutoscalerAddonName]) } @@ -120,42 +120,42 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params } flexVolumeDriverConfig := map[string]string{} bfFlexVolumeInstallerAddon := kubernetesConfig.GetAddonByName(DefaultBlobfuseFlexVolumeAddonName) - c := bfFlexVolumeInstallerAddon.GetAddonContainersIndexByName(DefaultBlobfuseFlexVolumeAddonName) - if c > -1 { - flexVolumeDriverConfig["kubernetesBlobfuseFlexVolumeInstallerCPURequests"] = bfFlexVolumeInstallerAddon.Containers[c].CPURequests - flexVolumeDriverConfig["kubernetesBlobfuseFlexVolumeInstallerCPULimit"] = bfFlexVolumeInstallerAddon.Containers[c].CPULimits - flexVolumeDriverConfig["kubernetesBlobfuseFlexVolumeInstallerMemoryRequests"] = bfFlexVolumeInstallerAddon.Containers[c].MemoryRequests - flexVolumeDriverConfig["kubernetesBlobfuseFlexVolumeInstallerMemoryLimit"] = bfFlexVolumeInstallerAddon.Containers[c].MemoryLimits + bfFlexVolumeIndex := bfFlexVolumeInstallerAddon.GetAddonContainersIndexByName(DefaultBlobfuseFlexVolumeAddonName) + if bfFlexVolumeIndex > -1 { + flexVolumeDriverConfig["kubernetesBlobfuseFlexVolumeInstallerCPURequests"] = bfFlexVolumeInstallerAddon.Containers[bfFlexVolumeIndex].CPURequests + flexVolumeDriverConfig["kubernetesBlobfuseFlexVolumeInstallerCPULimit"] = bfFlexVolumeInstallerAddon.Containers[bfFlexVolumeIndex].CPULimits + flexVolumeDriverConfig["kubernetesBlobfuseFlexVolumeInstallerMemoryRequests"] = bfFlexVolumeInstallerAddon.Containers[bfFlexVolumeIndex].MemoryRequests + flexVolumeDriverConfig["kubernetesBlobfuseFlexVolumeInstallerMemoryLimit"] = bfFlexVolumeInstallerAddon.Containers[bfFlexVolumeIndex].MemoryLimits } smbFlexVolumeInstallerAddon := kubernetesConfig.GetAddonByName(DefaultSMBFlexVolumeAddonName) - c = smbFlexVolumeInstallerAddon.GetAddonContainersIndexByName(DefaultSMBFlexVolumeAddonName) - if c > -1 { - flexVolumeDriverConfig["kubernetesSMBFlexVolumeInstallerCPURequests"] = smbFlexVolumeInstallerAddon.Containers[c].CPURequests - flexVolumeDriverConfig["kubernetesSMBFlexVolumeInstallerCPULimit"] = smbFlexVolumeInstallerAddon.Containers[c].CPULimits - flexVolumeDriverConfig["kubernetesSMBFlexVolumeInstallerMemoryRequests"] = smbFlexVolumeInstallerAddon.Containers[c].MemoryRequests - flexVolumeDriverConfig["kubernetesSMBFlexVolumeInstallerMemoryLimit"] = smbFlexVolumeInstallerAddon.Containers[c].MemoryLimits + smbFlexVolumeIndex := smbFlexVolumeInstallerAddon.GetAddonContainersIndexByName(DefaultSMBFlexVolumeAddonName) + if smbFlexVolumeIndex > -1 { + flexVolumeDriverConfig["kubernetesSMBFlexVolumeInstallerCPURequests"] = smbFlexVolumeInstallerAddon.Containers[smbFlexVolumeIndex].CPURequests + flexVolumeDriverConfig["kubernetesSMBFlexVolumeInstallerCPULimit"] = smbFlexVolumeInstallerAddon.Containers[smbFlexVolumeIndex].CPULimits + flexVolumeDriverConfig["kubernetesSMBFlexVolumeInstallerMemoryRequests"] = smbFlexVolumeInstallerAddon.Containers[smbFlexVolumeIndex].MemoryRequests + flexVolumeDriverConfig["kubernetesSMBFlexVolumeInstallerMemoryLimit"] = smbFlexVolumeInstallerAddon.Containers[smbFlexVolumeIndex].MemoryLimits } addValue(parametersMap, "flexVolumeDriverConfig", flexVolumeDriverConfig) if kubernetesConfig.IsKeyVaultFlexVolumeEnabled() { kvFlexVolumeInstallerAddon := kubernetesConfig.GetAddonByName(DefaultKeyVaultFlexVolumeAddonName) - c := kvFlexVolumeInstallerAddon.GetAddonContainersIndexByName(DefaultKeyVaultFlexVolumeAddonName) - if c > -1 { - addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerCPURequests", kvFlexVolumeInstallerAddon.Containers[c].CPURequests) - addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerCPULimit", kvFlexVolumeInstallerAddon.Containers[c].CPULimits) - addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerMemoryRequests", kvFlexVolumeInstallerAddon.Containers[c].MemoryRequests) - addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerMemoryLimit", kvFlexVolumeInstallerAddon.Containers[c].MemoryLimits) + kvFlexVolumeIndex := kvFlexVolumeInstallerAddon.GetAddonContainersIndexByName(DefaultKeyVaultFlexVolumeAddonName) + if kvFlexVolumeIndex > -1 { + addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerCPURequests", kvFlexVolumeInstallerAddon.Containers[kvFlexVolumeIndex].CPURequests) + addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerCPULimit", kvFlexVolumeInstallerAddon.Containers[kvFlexVolumeIndex].CPULimits) + addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerMemoryRequests", kvFlexVolumeInstallerAddon.Containers[kvFlexVolumeIndex].MemoryRequests) + addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerMemoryLimit", kvFlexVolumeInstallerAddon.Containers[kvFlexVolumeIndex].MemoryLimits) } } if kubernetesConfig.IsDashboardEnabled() { dashboardAddon := kubernetesConfig.GetAddonByName(DefaultDashboardAddonName) - dashboardAddon.GetAddonContainersIndexByName(DefaultDashboardAddonName) - if c > -1 { - addValue(parametersMap, "kubernetesDashboardCPURequests", dashboardAddon.Containers[c].CPURequests) - addValue(parametersMap, "kubernetesDashboardCPULimit", dashboardAddon.Containers[c].CPULimits) - addValue(parametersMap, "kubernetesDashboardMemoryRequests", dashboardAddon.Containers[c].MemoryRequests) - addValue(parametersMap, "kubernetesDashboardMemoryLimit", dashboardAddon.Containers[c].MemoryLimits) - if dashboardAddon.Containers[c].Image != "" { - addValue(parametersMap, "kubernetesDashboardSpec", dashboardAddon.Containers[c].Image) + dashboardIndex := dashboardAddon.GetAddonContainersIndexByName(DefaultDashboardAddonName) + if dashboardIndex > -1 { + addValue(parametersMap, "kubernetesDashboardCPURequests", dashboardAddon.Containers[dashboardIndex].CPURequests) + 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]) } @@ -163,14 +163,14 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params } if kubernetesConfig.IsReschedulerEnabled() { reschedulerAddon := kubernetesConfig.GetAddonByName(DefaultReschedulerAddonName) - c := reschedulerAddon.GetAddonContainersIndexByName(DefaultReschedulerAddonName) - if c > -1 { - addValue(parametersMap, "kubernetesReschedulerCPURequests", reschedulerAddon.Containers[c].CPURequests) - addValue(parametersMap, "kubernetesReschedulerCPULimit", reschedulerAddon.Containers[c].CPULimits) - addValue(parametersMap, "kubernetesReschedulerMemoryRequests", reschedulerAddon.Containers[c].MemoryRequests) - addValue(parametersMap, "kubernetesReschedulerMemoryLimit", reschedulerAddon.Containers[c].MemoryLimits) - if reschedulerAddon.Containers[c].Image != "" { - addValue(parametersMap, "kubernetesReschedulerSpec", reschedulerAddon.Containers[c].Image) + reschedulerIndex := reschedulerAddon.GetAddonContainersIndexByName(DefaultReschedulerAddonName) + if reschedulerIndex > -1 { + addValue(parametersMap, "kubernetesReschedulerCPURequests", reschedulerAddon.Containers[reschedulerIndex].CPURequests) + 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]) } @@ -178,10 +178,10 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params } if properties.OrchestratorProfile.IsMetricsServerEnabled() { metricsServerAddon := kubernetesConfig.GetAddonByName(DefaultMetricsServerAddonName) - c = metricsServerAddon.GetAddonContainersIndexByName(DefaultMetricsServerAddonName) - if c > -1 { - if metricsServerAddon.Containers[c].Image != "" { - addValue(parametersMap, "kubernetesMetricsServerSpec", metricsServerAddon.Containers[c].Image) + metricsServerIndex := metricsServerAddon.GetAddonContainersIndexByName(DefaultMetricsServerAddonName) + if metricsServerIndex > -1 { + if metricsServerAddon.Containers[metricsServerIndex].Image != "" { + addValue(parametersMap, "kubernetesMetricsServerSpec", metricsServerAddon.Containers[metricsServerIndex].Image) } else { addValue(parametersMap, "kubernetesMetricsServerSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+k8sComponents[DefaultMetricsServerAddonName]) } @@ -189,14 +189,14 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params } if properties.IsNVIDIADevicePluginEnabled() { nvidiaDevicePluginAddon := kubernetesConfig.GetAddonByName(NVIDIADevicePluginAddonName) - c := nvidiaDevicePluginAddon.GetAddonContainersIndexByName(NVIDIADevicePluginAddonName) - if c > -1 { - addValue(parametersMap, "kubernetesNVIDIADevicePluginCPURequests", nvidiaDevicePluginAddon.Containers[c].CPURequests) - addValue(parametersMap, "kubernetesNVIDIADevicePluginCPULimit", nvidiaDevicePluginAddon.Containers[c].CPULimits) - addValue(parametersMap, "kubernetesNVIDIADevicePluginMemoryRequests", nvidiaDevicePluginAddon.Containers[c].MemoryRequests) - addValue(parametersMap, "kubernetesNVIDIADevicePluginMemoryLimit", nvidiaDevicePluginAddon.Containers[c].MemoryLimits) - if nvidiaDevicePluginAddon.Containers[c].Image != "" { - addValue(parametersMap, "kubernetesNVIDIADevicePluginSpec", nvidiaDevicePluginAddon.Containers[c].Image) + nvidiaPluginIndex := nvidiaDevicePluginAddon.GetAddonContainersIndexByName(NVIDIADevicePluginAddonName) + if nvidiaPluginIndex > -1 { + addValue(parametersMap, "kubernetesNVIDIADevicePluginCPURequests", nvidiaDevicePluginAddon.Containers[nvidiaPluginIndex].CPURequests) + 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]) } @@ -204,18 +204,18 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params } if kubernetesConfig.IsContainerMonitoringEnabled() { containerMonitoringAddon := kubernetesConfig.GetAddonByName(ContainerMonitoringAddonName) - c := containerMonitoringAddon.GetAddonContainersIndexByName("omsagent") - if c > -1 { + omsagentIndex := containerMonitoringAddon.GetAddonContainersIndexByName("omsagent") + if omsagentIndex > -1 { addValue(parametersMap, "omsAgentVersion", containerMonitoringAddon.Config["omsAgentVersion"]) addValue(parametersMap, "omsAgentDockerProviderVersion", containerMonitoringAddon.Config["dockerProviderVersion"]) addValue(parametersMap, "omsAgentWorkspaceGuid", containerMonitoringAddon.Config["workspaceGuid"]) addValue(parametersMap, "omsAgentWorkspaceKey", containerMonitoringAddon.Config["workspaceKey"]) - addValue(parametersMap, "kubernetesOMSAgentCPURequests", containerMonitoringAddon.Containers[c].CPURequests) - addValue(parametersMap, "kubernetesOMSAgentCPULimit", containerMonitoringAddon.Containers[c].CPULimits) - addValue(parametersMap, "kubernetesOMSAgentMemoryRequests", containerMonitoringAddon.Containers[c].MemoryRequests) - addValue(parametersMap, "kubernetesOMSAgentMemoryLimit", containerMonitoringAddon.Containers[c].MemoryLimits) - if containerMonitoringAddon.Containers[c].Image != "" { - addValue(parametersMap, "omsAgentImage", containerMonitoringAddon.Containers[c].Image) + addValue(parametersMap, "kubernetesOMSAgentCPURequests", containerMonitoringAddon.Containers[omsagentIndex].CPURequests) + 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]) } @@ -223,12 +223,12 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params } if kubernetesConfig.IsIPMasqAgentEnabled() { ipMasqAgentAddon := kubernetesConfig.GetAddonByName(IPMASQAgentAddonName) - i := ipMasqAgentAddon.GetAddonContainersIndexByName(IPMASQAgentAddonName) - if i > -1 { - addValue(parametersMap, "kubernetesIPMasqAgentCPURequests", ipMasqAgentAddon.Containers[c].CPURequests) - addValue(parametersMap, "kubernetesIPMasqAgentMemoryRequests", ipMasqAgentAddon.Containers[c].MemoryRequests) - addValue(parametersMap, "kubernetesIPMasqAgentCPULimit", ipMasqAgentAddon.Containers[c].CPULimits) - addValue(parametersMap, "kubernetesIPMasqAgentMemoryLimit", ipMasqAgentAddon.Containers[c].MemoryLimits) + ipMasqAgentIndex := ipMasqAgentAddon.GetAddonContainersIndexByName(IPMASQAgentAddonName) + if ipMasqAgentIndex > -1 { + addValue(parametersMap, "kubernetesIPMasqAgentCPURequests", ipMasqAgentAddon.Containers[ipMasqAgentIndex].CPURequests) + addValue(parametersMap, "kubernetesIPMasqAgentMemoryRequests", ipMasqAgentAddon.Containers[ipMasqAgentIndex].MemoryRequests) + addValue(parametersMap, "kubernetesIPMasqAgentCPULimit", ipMasqAgentAddon.Containers[ipMasqAgentIndex].CPULimits) + addValue(parametersMap, "kubernetesIPMasqAgentMemoryLimit", ipMasqAgentAddon.Containers[ipMasqAgentIndex].MemoryLimits) } } if kubernetesConfig.LoadBalancerSku == "Standard" { @@ -239,10 +239,10 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params if properties.OrchestratorProfile.IsAzureCNI() { azureCNINetworkmonitorAddon := kubernetesConfig.GetAddonByName(AzureCNINetworkMonitoringAddonName) - c = azureCNINetworkmonitorAddon.GetAddonContainersIndexByName(AzureCNINetworkMonitoringAddonName) - if c > -1 { - if azureCNINetworkmonitorAddon.Containers[c].Image != "" { - addValue(parametersMap, "AzureCNINetworkMonitorImageURL", azureCNINetworkmonitorAddon.Containers[c].Image) + 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]) } diff --git a/pkg/acsengine/params_k8s_test.go b/pkg/acsengine/params_k8s_test.go index e611383c22..f76cca2c59 100644 --- a/pkg/acsengine/params_k8s_test.go +++ b/pkg/acsengine/params_k8s_test.go @@ -4,6 +4,8 @@ import ( "path" "testing" + "github.com/Azure/acs-engine/pkg/helpers" + "github.com/Azure/acs-engine/pkg/api" "github.com/Azure/acs-engine/pkg/i18n" "github.com/leonelquinteros/gotext" @@ -45,3 +47,129 @@ func TestAssignKubernetesParameters(t *testing.T) { } } } + +func TestKubernetesParamsAddons(t *testing.T) { + tests := map[string]struct { + addon api.KubernetesAddon + expectedParams []string + }{ + "nvidia-device-plugin": { + api.KubernetesAddon{ + Name: api.NVIDIADevicePluginAddonName, + Enabled: helpers.PointerToBool(true), + Containers: []api.KubernetesContainerSpec{ + { + Name: api.NVIDIADevicePluginAddonName, + CPURequests: "50m", + MemoryRequests: "150Mi", + CPULimits: "50m", + MemoryLimits: "150Mi", + }, + }, + }, + []string{ + "kubernetesNVIDIADevicePluginCPURequests", + "kubernetesNVIDIADevicePluginMemoryRequests", + "kubernetesNVIDIADevicePluginCPULimit", + "kubernetesNVIDIADevicePluginMemoryLimit", + "kubernetesNVIDIADevicePluginSpec", + }, + }, + + "container-monitoring": { + api.KubernetesAddon{ + Name: api.ContainerMonitoringAddonName, + Enabled: helpers.PointerToBool(true), + Containers: []api.KubernetesContainerSpec{ + { + Name: "omsagent", + CPURequests: "50m", + MemoryRequests: "150Mi", + CPULimits: "50m", + MemoryLimits: "150Mi", + }, + }, + }, + []string{ + "omsAgentVersion", + "omsAgentDockerProviderVersion", + "omsAgentWorkspaceGuid", + "omsAgentWorkspaceKey", + "kubernetesOMSAgentCPURequests", + "kubernetesOMSAgentCPULimit", + "kubernetesOMSAgentMemoryLimit", + "kubernetesOMSAgentMemoryRequests", + "omsAgentImage", + }, + }, + + "kubernetes-dashboard": { + api.KubernetesAddon{ + Name: api.DefaultDashboardAddonName, + Enabled: helpers.PointerToBool(true), + Containers: []api.KubernetesContainerSpec{ + { + Name: api.DefaultDashboardAddonName, + CPURequests: "50m", + MemoryRequests: "150Mi", + CPULimits: "50m", + MemoryLimits: "150Mi", + }, + }, + }, + []string{ + "kubernetesDashboardCPURequests", + "kubernetesDashboardCPULimit", + "kubernetesDashboardMemoryRequests", + "kubernetesDashboardMemoryLimit", + "kubernetesDashboardSpec", + }, + }, + + "rescheduler": { + api.KubernetesAddon{ + Name: api.DefaultReschedulerAddonName, + Enabled: helpers.PointerToBool(true), + Containers: []api.KubernetesContainerSpec{ + { + Name: api.DefaultReschedulerAddonName, + CPURequests: "50m", + MemoryRequests: "150Mi", + CPULimits: "50m", + MemoryLimits: "150Mi", + }, + }, + }, + []string{ + "kubernetesReschedulerCPURequests", + "kubernetesReschedulerCPULimit", + "kubernetesReschedulerMemoryRequests", + "kubernetesReschedulerMemoryLimit", + "kubernetesReschedulerSpec", + }, + }, + } + + for name, test := range tests { + test := test + t.Run(name, func(t *testing.T) { + t.Parallel() + properties := api.GetK8sDefaultProperties(false) + properties.OrchestratorProfile.KubernetesConfig.Addons = []api.KubernetesAddon{test.addon} + parametersMap := paramsMap{} + assignKubernetesParameters(properties, parametersMap, api.AzureCloudSpec, DefaultGeneratorCode) + + for _, expectedParam := range test.expectedParams { + if !isKeyPresent(expectedParam, parametersMap) { + t.Errorf("expected key %s to be present in the map", expectedParam) + } + } + }) + } + +} + +func isKeyPresent(key string, paramMap map[string]interface{}) bool { + _, ok := paramMap[key] + return ok +} diff --git a/pkg/api/mocks.go b/pkg/api/mocks.go index e1d03ad51a..097c1357b1 100644 --- a/pkg/api/mocks.go +++ b/pkg/api/mocks.go @@ -87,3 +87,48 @@ func CreateMockContainerService(containerServiceName, orchestratorVersion string return &cs } + +// GetK8sDefaultProperties returns a struct of type api.Properties for testing purposes. +func GetK8sDefaultProperties(hasWindows bool) *Properties { + p := &Properties{ + OrchestratorProfile: &OrchestratorProfile{ + OrchestratorType: Kubernetes, + KubernetesConfig: &KubernetesConfig{}, + }, + MasterProfile: &MasterProfile{ + Count: 1, + DNSPrefix: "foo", + VMSize: "Standard_DS2_v2", + }, + AgentPoolProfiles: []*AgentPoolProfile{ + { + Name: "agentpool", + VMSize: "Standard_D2_v2", + Count: 1, + AvailabilityProfile: AvailabilitySet, + }, + }, + ServicePrincipalProfile: &ServicePrincipalProfile{ + ClientID: "clientID", + Secret: "clientSecret", + }, + } + + if hasWindows { + p.AgentPoolProfiles = []*AgentPoolProfile{ + { + Name: "agentpool", + VMSize: "Standard_D2_v2", + Count: 1, + AvailabilityProfile: AvailabilitySet, + OSType: Windows, + }, + } + p.WindowsProfile = &WindowsProfile{ + AdminUsername: "azureuser", + AdminPassword: "replacepassword1234$", + } + } + + return p +}