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

Commit

Permalink
Removing code duplication in addon logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Tariq Ibrahim committed Sep 12, 2018
1 parent ef344ca commit 7b0fa21
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 164 deletions.
20 changes: 10 additions & 10 deletions pkg/acsengine/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func kubernetesAddonSettingsInit(profile *api.Properties) []kubernetesFeatureSet
{
"kubernetesmasteraddons-kubernetes-dashboard-deployment.yaml",
"kubernetes-dashboard-deployment.yaml",
profile.OrchestratorProfile.KubernetesConfig.IsDashboardEnabled(),
profile.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultDashboardAddonName, api.DefaultDashboardAddonEnabled),
},
{
"kubernetesmasteraddons-unmanaged-azure-storage-classes.yaml",
Expand All @@ -55,27 +55,27 @@ func kubernetesAddonSettingsInit(profile *api.Properties) []kubernetesFeatureSet
{
"kubernetesmasteraddons-tiller-deployment.yaml",
"kube-tiller-deployment.yaml",
profile.OrchestratorProfile.KubernetesConfig.IsTillerEnabled(),
profile.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultTillerAddonName, api.DefaultTillerAddonEnabled),
},
{
"kubernetesmasteraddons-aad-pod-identity-deployment.yaml",
"aad-pod-identity-deployment.yaml",
profile.OrchestratorProfile.KubernetesConfig.IsAADPodIdentityEnabled(),
profile.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultAADPodIdentityAddonName, api.DefaultAADPodIdentityAddonEnabled),
},
{
"kubernetesmasteraddons-aci-connector-deployment.yaml",
"aci-connector-deployment.yaml",
profile.OrchestratorProfile.KubernetesConfig.IsACIConnectorEnabled(),
profile.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultACIConnectorAddonName, api.DefaultACIConnectorAddonEnabled),
},
{
"kubernetesmasteraddons-cluster-autoscaler-deployment.yaml",
"cluster-autoscaler-deployment.yaml",
profile.OrchestratorProfile.KubernetesConfig.IsClusterAutoscalerEnabled(),
profile.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultClusterAutoscalerAddonName, api.DefaultACIConnectorAddonEnabled),
},
{
"kubernetesmasteraddons-kube-rescheduler-deployment.yaml",
"kube-rescheduler-deployment.yaml",
profile.OrchestratorProfile.KubernetesConfig.IsReschedulerEnabled(),
profile.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultReschedulerAddonName, api.DefaultReschedulerAddonEnabled),
},
{
"kubernetesmasteraddons-azure-npm-daemonset.yaml",
Expand Down Expand Up @@ -115,7 +115,7 @@ func kubernetesAddonSettingsInit(profile *api.Properties) []kubernetesFeatureSet
{
"kubernetesmasteraddons-omsagent-daemonset.yaml",
"omsagent-daemonset.yaml",
profile.OrchestratorProfile.KubernetesConfig.IsContainerMonitoringEnabled(),
profile.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(ContainerMonitoringAddonName, api.DefaultContainerMonitoringAddonEnabled),
},
{
"azure-cni-networkmonitor.yaml",
Expand All @@ -130,17 +130,17 @@ func kubernetesAddonSettingsInit(profile *api.Properties) []kubernetesFeatureSet
{
"kubernetesmasteraddons-blobfuse-flexvolume-installer.yaml",
"blobfuse-flexvolume-installer.yaml",
profile.OrchestratorProfile.KubernetesConfig.IsBlobfuseFlexVolumeEnabled(),
profile.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultBlobfuseFlexVolumeAddonName, api.DefaultBlobfuseFlexVolumeAddonEnabled),
},
{
"kubernetesmasteraddons-smb-flexvolume-installer.yaml",
"smb-flexvolume-installer.yaml",
profile.OrchestratorProfile.KubernetesConfig.IsSMBFlexVolumeEnabled(),
profile.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultSMBFlexVolumeAddonName, api.DefaultSMBFlexVolumeAddonEnabled),
},
{
"kubernetesmasteraddons-keyvault-flexvolume-installer.yaml",
"keyvault-flexvolume-installer.yaml",
profile.OrchestratorProfile.KubernetesConfig.IsKeyVaultFlexVolumeEnabled(),
profile.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultKeyVaultFlexVolumeAddonName, api.DefaultSMBFlexVolumeAddonEnabled),
},
{
"kubernetesmasteraddons-elb-svc.yaml",
Expand Down
16 changes: 8 additions & 8 deletions pkg/acsengine/params_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
addValue(parametersMap, "kubernetesExecHealthzSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion]["exechealthz"])
addValue(parametersMap, "kubernetesDNSSidecarSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion]["k8s-dns-sidecar"])
addValue(parametersMap, "kubernetesHeapsterSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion]["heapster"])
if properties.OrchestratorProfile.KubernetesConfig.IsTillerEnabled() {
if properties.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultTillerAddonName, api.DefaultTillerAddonEnabled) {
tillerAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultTillerAddonName)
c := getAddonContainersIndexByName(tillerAddon.Containers, DefaultTillerAddonName)
if c > -1 {
Expand All @@ -60,14 +60,14 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
}
}
}
if properties.OrchestratorProfile.KubernetesConfig.IsAADPodIdentityEnabled() {
if properties.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultAADPodIdentityAddonName, api.DefaultAADPodIdentityAddonEnabled) {
aadPodIdentityAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultAADPodIdentityAddonName)
c := getAddonContainersIndexByName(aadPodIdentityAddon.Containers, DefaultAADPodIdentityAddonName)
if c > -1 {
addValue(parametersMap, "kubernetesAADPodIdentityEnabled", helpers.IsTrueBoolPointer(aadPodIdentityAddon.Enabled))
}
}
if properties.OrchestratorProfile.KubernetesConfig.IsACIConnectorEnabled() {
if properties.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultACIConnectorAddonName, api.DefaultACIConnectorAddonEnabled) {
aciConnectorAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultACIConnectorAddonName)
c := getAddonContainersIndexByName(aciConnectorAddon.Containers, DefaultACIConnectorAddonName)
if c > -1 {
Expand All @@ -89,7 +89,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
} else {
addValue(parametersMap, "kubernetesACIConnectorEnabled", false)
}
if properties.OrchestratorProfile.KubernetesConfig.IsClusterAutoscalerEnabled() {
if properties.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultClusterAutoscalerAddonName, api.DefaultClusterAutoscalerAddonEnabled) {
clusterAutoscalerAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultClusterAutoscalerAddonName)
c := getAddonContainersIndexByName(clusterAutoscalerAddon.Containers, DefaultClusterAutoscalerAddonName)
if c > -1 {
Expand Down Expand Up @@ -129,7 +129,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
flexVolumeDriverConfig["kubernetesSMBFlexVolumeInstallerMemoryLimit"] = smbFlexVolumeInstallerAddon.Containers[c].MemoryLimits
}
addValue(parametersMap, "flexVolumeDriverConfig", flexVolumeDriverConfig)
if properties.OrchestratorProfile.KubernetesConfig.IsKeyVaultFlexVolumeEnabled() {
if properties.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultKeyVaultFlexVolumeAddonName, api.DefaultKeyVaultFlexVolumeAddonEnabled) {
kvFlexVolumeInstallerAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultKeyVaultFlexVolumeAddonName)
c := getAddonContainersIndexByName(kvFlexVolumeInstallerAddon.Containers, DefaultKeyVaultFlexVolumeAddonName)
if c > -1 {
Expand All @@ -139,7 +139,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerMemoryLimit", kvFlexVolumeInstallerAddon.Containers[c].MemoryLimits)
}
}
if properties.OrchestratorProfile.KubernetesConfig.IsDashboardEnabled() {
if properties.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultDashboardAddonName, api.DefaultDashboardAddonEnabled) {
dashboardAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultDashboardAddonName)
c = getAddonContainersIndexByName(dashboardAddon.Containers, DefaultDashboardAddonName)
if c > -1 {
Expand All @@ -154,7 +154,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
}
}
}
if properties.OrchestratorProfile.KubernetesConfig.IsReschedulerEnabled() {
if properties.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(DefaultReschedulerAddonName, api.DefaultReschedulerAddonEnabled) {
reschedulerAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultReschedulerAddonName)
c := getAddonContainersIndexByName(reschedulerAddon.Containers, DefaultReschedulerAddonName)
if c > -1 {
Expand Down Expand Up @@ -195,7 +195,7 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
}
}
}
if properties.OrchestratorProfile.KubernetesConfig.IsContainerMonitoringEnabled() {
if properties.OrchestratorProfile.KubernetesConfig.IsAddonEnabled(ContainerMonitoringAddonName, api.DefaultContainerMonitoringAddonEnabled) {
containerMonitoringAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, ContainerMonitoringAddonName)
c := getAddonContainersIndexByName(containerMonitoringAddon.Containers, "omsagent")
if c > -1 {
Expand Down
146 changes: 18 additions & 128 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,115 +886,22 @@ func (o *OrchestratorProfile) GetAPIServerEtcdAPIVersion() string {
return ""
}

// IsMetricsServerEnabled checks if the metrics server addon is enabled
func (o *OrchestratorProfile) IsMetricsServerEnabled() bool {
var metricsServerAddon KubernetesAddon
k := o.KubernetesConfig
for i := range k.Addons {
if k.Addons[i].Name == DefaultMetricsServerAddonName {
metricsServerAddon = k.Addons[i]
// IsAddonEnabled checks whether a k8s addon with name "addonName" is enabled or not based on the Enabled field of KubernetesAddon.
// If the value of Enabled in nil, the "defaultValue" is returned.
func (k *KubernetesConfig) IsAddonEnabled(addonName string, defaultValue bool) bool {
var kubeAddon KubernetesAddon
for _, addon := range k.Addons {
if addon.Name == addonName {
kubeAddon = addon
}
}
return metricsServerAddon.IsEnabled(DefaultMetricsServerAddonEnabled || common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.9.0"))
return kubeAddon.IsEnabled(defaultValue)
}

// IsContainerMonitoringEnabled checks if the container monitoring addon is enabled
func (k *KubernetesConfig) IsContainerMonitoringEnabled() bool {
var containerMonitoringAddon KubernetesAddon
for i := range k.Addons {
if k.Addons[i].Name == ContainerMonitoringAddonName {
containerMonitoringAddon = k.Addons[i]
}
}
return containerMonitoringAddon.IsEnabled(DefaultContainerMonitoringAddonEnabled)
}

// IsTillerEnabled checks if the tiller addon is enabled
func (k *KubernetesConfig) IsTillerEnabled() bool {
var tillerAddon KubernetesAddon
for i := range k.Addons {
if k.Addons[i].Name == DefaultTillerAddonName {
tillerAddon = k.Addons[i]
}
}
return tillerAddon.IsEnabled(DefaultTillerAddonEnabled)
}

// IsAADPodIdentityEnabled checks if the tiller addon is enabled
func (k *KubernetesConfig) IsAADPodIdentityEnabled() bool {
var aadPodIdentityAddon KubernetesAddon
for i := range k.Addons {
if k.Addons[i].Name == DefaultAADPodIdentityAddonName {
aadPodIdentityAddon = k.Addons[i]
}
}
return aadPodIdentityAddon.IsEnabled(DefaultAADPodIdentityAddonEnabled)
}

// IsACIConnectorEnabled checks if the ACI Connector addon is enabled
func (k *KubernetesConfig) IsACIConnectorEnabled() bool {
var aciConnectorAddon KubernetesAddon
for i := range k.Addons {
if k.Addons[i].Name == DefaultACIConnectorAddonName {
aciConnectorAddon = k.Addons[i]
}
}
return aciConnectorAddon.IsEnabled(DefaultACIConnectorAddonEnabled)
}

// IsClusterAutoscalerEnabled checks if the cluster autoscaler addon is enabled
func (k *KubernetesConfig) IsClusterAutoscalerEnabled() bool {
var clusterAutoscalerAddon KubernetesAddon
for i := range k.Addons {
if k.Addons[i].Name == DefaultClusterAutoscalerAddonName {
clusterAutoscalerAddon = k.Addons[i]
}
}
return clusterAutoscalerAddon.IsEnabled(DefaultClusterAutoscalerAddonEnabled)
}

// IsBlobfuseFlexVolumeEnabled checks if the Blobfuse FlexVolume addon is enabled
func (k *KubernetesConfig) IsBlobfuseFlexVolumeEnabled() bool {
var bfFlexVolumeAddon KubernetesAddon
for i := range k.Addons {
if k.Addons[i].Name == DefaultBlobfuseFlexVolumeAddonName {
bfFlexVolumeAddon = k.Addons[i]
}
}
return bfFlexVolumeAddon.IsEnabled(DefaultBlobfuseFlexVolumeAddonEnabled)
}

// IsSMBFlexVolumeEnabled checks if the SMB FlexVolume addon is enabled
func (k *KubernetesConfig) IsSMBFlexVolumeEnabled() bool {
var smbFlexVolumeAddon KubernetesAddon
for i := range k.Addons {
if k.Addons[i].Name == DefaultSMBFlexVolumeAddonName {
smbFlexVolumeAddon = k.Addons[i]
}
}
return smbFlexVolumeAddon.IsEnabled(DefaultSMBFlexVolumeAddonEnabled)
}

// IsKeyVaultFlexVolumeEnabled checks if the Key Vault FlexVolume addon is enabled
func (k *KubernetesConfig) IsKeyVaultFlexVolumeEnabled() bool {
var kvFlexVolumeAddon KubernetesAddon
for i := range k.Addons {
if k.Addons[i].Name == DefaultKeyVaultFlexVolumeAddonName {
kvFlexVolumeAddon = k.Addons[i]
}
}
return kvFlexVolumeAddon.IsEnabled(DefaultKeyVaultFlexVolumeAddonEnabled)
}

// IsDashboardEnabled checks if the kubernetes-dashboard addon is enabled
func (k *KubernetesConfig) IsDashboardEnabled() bool {
var dashboardAddon KubernetesAddon
for i := range k.Addons {
if k.Addons[i].Name == DefaultDashboardAddonName {
dashboardAddon = k.Addons[i]
}
}
return dashboardAddon.IsEnabled(DefaultDashboardAddonEnabled)
// IsMetricsServerEnabled checks if the metrics server addon is enabled
func (o *OrchestratorProfile) IsMetricsServerEnabled() bool {
return o.KubernetesConfig.IsAddonEnabled(DefaultMetricsServerAddonName,
common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.9.0"))
}

// IsNSeriesSKU returns whether or not the agent pool has Standard_N SKU VMs
Expand All @@ -1010,36 +917,19 @@ func IsNSeriesSKU(p *Properties) bool {
// IsNVIDIADevicePluginEnabled checks if the NVIDIA Device Plugin addon is enabled
// It is enabled by default if agents contain a GPU and Kubernetes version is >= 1.10.0
func (p *Properties) IsNVIDIADevicePluginEnabled() bool {
var nvidiaDevicePluginAddon KubernetesAddon
k := p.OrchestratorProfile.KubernetesConfig
o := p.OrchestratorProfile
for i := range k.Addons {
if k.Addons[i].Name == NVIDIADevicePluginAddonName {
nvidiaDevicePluginAddon = k.Addons[i]
}
}
return k.IsAddonEnabled(NVIDIADevicePluginAddonName, getDefaultNVIDIADevicePluginEnabled(p))
}

func getDefaultNVIDIADevicePluginEnabled(p *Properties) bool {
o := p.OrchestratorProfile
var addonEnabled bool
if nvidiaDevicePluginAddon.Enabled != nil && !*nvidiaDevicePluginAddon.Enabled {
addonEnabled = false
} else if IsNSeriesSKU(p) && common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.10.0") {
if IsNSeriesSKU(p) && common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.10.0") {
addonEnabled = true
} else {
addonEnabled = false
}

return nvidiaDevicePluginAddon.IsEnabled(addonEnabled)
}

// IsReschedulerEnabled checks if the rescheduler addon is enabled
func (k *KubernetesConfig) IsReschedulerEnabled() bool {
var reschedulerAddon KubernetesAddon
for i := range k.Addons {
if k.Addons[i].Name == DefaultReschedulerAddonName {
reschedulerAddon = k.Addons[i]
}
}
return reschedulerAddon.IsEnabled(DefaultReschedulerAddonEnabled)
return addonEnabled
}

// PrivateJumpboxProvision checks if a private cluster has jumpbox auto-provisioning
Expand Down
Loading

0 comments on commit 7b0fa21

Please sign in to comment.