Skip to content

Commit

Permalink
helm: enable clusterapi namespace autodiscovery
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrancis committed May 23, 2023
1 parent 982c821 commit f43baf9
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion charts/cluster-autoscaler/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ name: cluster-autoscaler
sources:
- https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler
type: application
version: 9.29.0
version: 9.30.0
1 change: 1 addition & 0 deletions charts/cluster-autoscaler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ $ helm install my-release autoscaler/cluster-autoscaler -f myvalues.yaml
`cloudProvider: clusterapi` must be set, and then one or more of

- `autoDiscovery.clusterName`
- or `autoDiscovery.namespace`
- or `autoDiscovery.labels`

See [here](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/clusterapi/README.md#configuring-node-group-auto-discovery) for more details.
Expand Down
4 changes: 2 additions & 2 deletions charts/cluster-autoscaler/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if or .Values.autoDiscovery.clusterName .Values.autoscalingGroups -}}
{{- if or ( or .Values.autoDiscovery.clusterName .Values.autoDiscovery.namespace .Values.autoDiscovery.labels ) .Values.autoscalingGroups }}

To verify that cluster-autoscaler has started, run:

Expand All @@ -8,7 +8,7 @@ To verify that cluster-autoscaler has started, run:

##############################################################################
#### ERROR: You must specify values for either ####
#### autoDiscovery.clusterName or autoscalingGroups[] ####
#### autoDiscovery or autoscalingGroups[] ####
##############################################################################

The deployment and pod will not be created and the installation is not functional
Expand Down
43 changes: 37 additions & 6 deletions charts/cluster-autoscaler/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,52 @@ Return true if the priority expander is enabled
{{- end -}}

{{/*
Return the autodiscoveryparameters for clusterapi.
autoDiscovery.clusterName for clusterapi.
*/}}
{{- define "cluster-autoscaler.capiAutodiscoveryConfig" -}}
{{- if .Values.autoDiscovery.clusterName -}}
{{- define "cluster-autoscaler.capiAutodiscovery.clusterName" -}}
{{- print "clusterName=" -}}{{ .Values.autoDiscovery.clusterName }}
{{- end -}}
{{- if and .Values.autoDiscovery.clusterName .Values.autoDiscovery.labels -}}
{{- print "," -}}

{{/*
autoDiscovery.namespace for clusterapi.
*/}}
{{- define "cluster-autoscaler.capiAutodiscovery.namespace" -}}
{{- print "namespace=" }}{{ .Values.autoDiscovery.namespace -}}
{{- end -}}
{{- if .Values.autoDiscovery.labels -}}

{{/*
autoDiscovery.labels for clusterapi.
*/}}
{{- define "cluster-autoscaler.capiAutodiscovery.labels" -}}
{{- range $i, $el := .Values.autoDiscovery.labels -}}
{{- if $i -}}{{- print "," -}}{{- end -}}
{{- range $key, $val := $el -}}
{{- $key -}}{{- print "=" -}}{{- $val -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Return the autodiscoveryparameters for clusterapi.
*/}}
{{- define "cluster-autoscaler.capiAutodiscoveryConfig" -}}
{{- if .Values.autoDiscovery.clusterName -}}
{{ include "cluster-autoscaler.capiAutodiscovery.clusterName" . }}
{{- if .Values.autoDiscovery.namespace }}
{{- print "," -}}
{{ include "cluster-autoscaler.capiAutodiscovery.namespace" . }}
{{- end -}}
{{- if .Values.autoDiscovery.labels }}
{{- print "," -}}
{{ include "cluster-autoscaler.capiAutodiscovery.labels" . }}
{{- end -}}
{{- else if .Values.autoDiscovery.namespace -}}
{{ include "cluster-autoscaler.capiAutodiscovery.namespace" . }}
{{- if .Values.autoDiscovery.labels }}
{{- print "," -}}
{{ include "cluster-autoscaler.capiAutodiscovery.labels" . }}
{{- end -}}
{{- else if .Values.autoDiscovery.labels -}}
{{ include "cluster-autoscaler.capiAutodiscovery.labels" . }}
{{- end -}}
{{- end -}}
4 changes: 2 additions & 2 deletions charts/cluster-autoscaler/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if or ( or .Values.autoDiscovery.clusterName .Values.autoDiscovery.labels ) .Values.autoscalingGroups }}
{{- if or ( or .Values.autoDiscovery.clusterName .Values.autoDiscovery.namespace .Values.autoDiscovery.labels ) .Values.autoscalingGroups }}
{{/* one of the above is required */}}
apiVersion: {{ template "deployment.apiVersion" . }}
kind: Deployment
Expand Down Expand Up @@ -94,7 +94,7 @@ spec:
- --cluster-name={{ .Values.magnumClusterName }}
{{- end }}
{{- else if eq .Values.cloudProvider "clusterapi" }}
{{- if or .Values.autoDiscovery.clusterName .Values.autoDiscovery.labels }}
{{- if or .Values.autoDiscovery.clusterName .Values.autoDiscovery.labels .Values.autoDiscovery.namepace }}
- --node-group-auto-discovery=clusterapi:{{ template "cluster-autoscaler.capiAutodiscoveryConfig" . }}
{{- end }}
{{- if eq .Values.clusterAPIMode "incluster-kubeconfig"}}
Expand Down
2 changes: 2 additions & 0 deletions charts/cluster-autoscaler/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ autoDiscovery:
# Enable autodiscovery for `cloudProvider=magnum`, for groups matching `autoDiscovery.roles`.
clusterName: # cluster.local

namespace: # default

# autoDiscovery.tags -- ASG tags to match, run through `tpl`.
tags:
- k8s.io/cluster-autoscaler/enabled
Expand Down
5 changes: 1 addition & 4 deletions cluster-autoscaler/cloudprovider/clusterapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ most likely need other command line flags. For more information you can invoke

## Configuring node group auto discovery

If you do not configure node group auto discovery, cluster autoscaler will attempt
to match nodes against any scalable resources found in any namespace and belonging
to any Cluster.
You must configure node group auto discovery to inform cluster autoscaler which cluster in which to find for scalable node groups.

Limiting cluster autoscaler to only match against resources in the blue namespace

Expand Down Expand Up @@ -442,4 +440,3 @@ here as a reference for users who might be deploying on these infrastructures.
| IBM Cloud | `ibm-cloud.kubernetes.io/worker-id` | Used by the IBM Cloud Cloud Controller Manager to identify the node |
| IBM Cloud | `vpc-block-csi-driver-labels` | Used by the IBM Cloud CSI driver as a target for persistent volume node affinity |
| IBM Cloud | `ibm-cloud.kubernetes.io/vpc-instance-id` | Used when a VPC is in use on IBM Cloud |

0 comments on commit f43baf9

Please sign in to comment.