Skip to content

Commit

Permalink
Add feature flags to enable/disable resources (#18)
Browse files Browse the repository at this point in the history
* Add feature flags to enable/disable resources

* Clean up dollar vs dot usage in main Helm helper templates

* Remove unncecessary and wrong CI values
  • Loading branch information
nprokopic authored Oct 21, 2023
1 parent c753638 commit bc2f86d
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 23 deletions.
11 changes: 5 additions & 6 deletions helm/cluster/ci/ci-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,6 @@ internal:
postKubeadmCommands:
- echo "hello control plane after kubeadm"
- echo "cluster control plane after kubeadm"
resources:
controlPlane:
api:
group: asd
version: v1
kind: KubeadmControlPlane
components:
kubelet:
gracefulNodeShutdown:
Expand Down Expand Up @@ -243,6 +237,11 @@ internal:
kubernetesVersion: 1.24.10
paused: false
resourcesApi:
clusterResourceEnabled: true
controlPlaneResourceEnabled: true
machinePoolResourcesEnabled: true
machineHealthCheckResourceEnabled: true
bastionResourceEnabled: true
nodePoolKind: MachinePool
infrastructureCluster:
group: infrastructure.cluster.x-k8s.io
Expand Down
30 changes: 15 additions & 15 deletions helm/cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
Expand the name of the chart.
*/}}
{{- define "cluster.chart.name" -}}
{{- $.Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "cluster.chart.nameAndVersion" -}}
{{- printf "%s-%s" $.Chart.Name $.Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Expand All @@ -21,36 +21,36 @@ Given that Kubernetes allows 63 characters for resource names, the stem is trunc
room for such suffix.
*/}}
{{- define "cluster.resource.name" -}}
{{- $.Values.global.metadata.name | default ($.Release.Name | replace "." "-" | trunc 47 | trimSuffix "-") -}}
{{- .Values.global.metadata.name | default (.Release.Name | replace "." "-" | trunc 47 | trimSuffix "-") -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "cluster.labels.common" -}}
app: {{ include "cluster.chart.name" . | quote }}
app.kubernetes.io/managed-by: {{ $.Release.Service | quote }}
app.kubernetes.io/version: {{ $.Chart.Version | quote }}
application.giantswarm.io/team: {{ index $.Chart.Annotations "application.giantswarm.io/team" | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/version: {{ .Chart.Version | quote }}
application.giantswarm.io/team: {{ index .Chart.Annotations "application.giantswarm.io/team" | quote }}
giantswarm.io/cluster: {{ include "cluster.resource.name" . | quote }}
giantswarm.io/organization: {{ required "You must provide an existing organization name in .global.metadata.organization" $.Values.global.metadata.organization | quote }}
giantswarm.io/service-priority: {{ $.Values.global.metadata.servicePriority }}
cluster.x-k8s.io/cluster-name: {{ include "cluster.resource.name" . | quote }}
giantswarm.io/organization: {{ required "You must provide an existing organization name in .global.metadata.organization" .Values.global.metadata.organization | quote }}
giantswarm.io/service-priority: {{ .Values.global.metadata.servicePriority }}
cluster.x-k8s.io/cluster-name: {{ include "cluster.resource.name" $ | quote }}
cluster.x-k8s.io/watch-filter: capi
helm.sh/chart: {{ include "cluster.chart.nameAndVersion" . | quote }}
helm.sh/chart: {{ include "cluster.chart.nameAndVersion" $ | quote }}
{{- end -}}

{{- define "cluster.labels.custom" }}
{{- if $.Values.global.metadata.labels }}
{{- range $key, $val := $.Values.global.metadata.labels }}
{{- if .Values.global.metadata.labels }}
{{- range $key, $val := .Values.global.metadata.labels }}
{{ $key }}: {{ $val | quote }}
{{- end }}
{{- end }}
{{- end }}

{{- define "cluster.annotations.custom" }}
{{- if $.Values.global.metadata.annotations }}
{{- range $key, $val := $.Values.global.metadata.annotations }}
{{- if .Values.global.metadata.annotations }}
{{- range $key, $val := .Values.global.metadata.annotations }}
{{ $key }}: {{ $val | quote }}
{{- end }}
{{- end }}
Expand All @@ -59,7 +59,7 @@ helm.sh/chart: {{ include "cluster.chart.nameAndVersion" . | quote }}
{{/*
Hash function based on data provided
Expects two arguments (as a `dict`) E.g.
{{ include "hash" (dict "data" . "salt" $.Values.internal.hasSalt) }}
{{ include "hash" (dict "data" . "salt" .Values.internal.hasSalt) }}
Where `data` is the data to hash and `global` is the top level scope.
*/}}
{{- define "cluster.data.hash" -}}
Expand Down
4 changes: 4 additions & 0 deletions helm/cluster/templates/bastion/kubeadmconfigtemplate.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{- if $.Values.internal.resourcesApi.bastionResourceEnabled }}
{{- if .Values.global.connectivity.bastion.enabled }}
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
metadata:
Expand All @@ -14,3 +16,5 @@ spec:
template:
spec:
{{- include "cluster.internal.bastion.kubeadmconfigtemplate.spec" $ | indent 6 }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions helm/cluster/templates/bastion/machinedeployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if $.Values.internal.resourcesApi.bastionResourceEnabled }}
{{- if .Values.global.connectivity.bastion.enabled }}
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
Expand Down Expand Up @@ -45,3 +46,4 @@ spec:
name: {{ include "cluster.resource.name" $ }}-bastion-{{ include "cluster.data.hash" (dict "data" (include $.Values.internal.resourcesApi.bastion.infrastructureMachineTemplateSpecTemplateName $) "salt" $.Values.internal.hashSalt) }}
version: {{ $.Values.internal.kubernetesVersion }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions helm/cluster/templates/clusterapi/cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if $.Values.internal.resourcesApi.clusterResourceEnabled }}
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
Expand Down Expand Up @@ -34,3 +35,4 @@ spec:
{{- if .Values.internal.paused }}
paused: true
{{- end -}}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if $.Values.internal.resourcesApi.controlPlaneResourceEnabled }}
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
metadata:
Expand Down Expand Up @@ -50,3 +51,4 @@ spec:
{{- include "cluster.internal.controlPlane.kubeadm.postKubeadmCommands" $ | indent 4 }}
users:
{{- include "cluster.internal.kubeadm.users" $ | indent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{- if $.Values.internal.resourcesApi.controlPlaneResourceEnabled }}
{{- if $.Values.internal.resourcesApi.machineHealthCheckResourceEnabled }}
{{- if $.Values.global.controlPlane.machineHealthCheck.enabled }}
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineHealthCheck
Expand All @@ -9,7 +11,7 @@ metadata:
{{- end }}
{{- end }}
labels:
{{- include "cluster.labels.common" . | nindent 4 }}
{{- include "cluster.labels.common" $ | nindent 4 }}
{{- if $.Values.global.metadata.labels }}
{{- range $key, $val := $.Values.global.metadata.labels }}
{{ $key }}: {{ $val | quote }}
Expand All @@ -33,3 +35,5 @@ spec:
status: "False"
timeout: {{ $.Values.global.controlPlane.machineHealthCheck.unhealthyNotReadyTimeout }}
{{- end }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions helm/cluster/templates/clusterapi/workers/kubeadmconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if $.Values.internal.resourcesApi.machinePoolResourcesEnabled }}
{{- if eq $.Values.internal.resourcesApi.nodePoolKind "MachinePool" }}
{{- range $nodePoolName, $nodePoolConfig := $.Values.global.nodePools }}
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
Expand Down Expand Up @@ -39,3 +40,4 @@ spec:
---
{{- end }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions helm/cluster/templates/clusterapi/workers/machinepool.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if $.Values.internal.resourcesApi.machinePoolResourcesEnabled }}
{{- if eq $.Values.internal.resourcesApi.nodePoolKind "MachinePool" }}
{{- range $nodePoolName, $nodePoolConfig := $.Values.global.nodePools }}
apiVersion: cluster.x-k8s.io/v1beta1
Expand Down Expand Up @@ -42,3 +43,4 @@ spec:
---
{{- end }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions helm/cluster/templates/containerd_config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{- if or $.Values.internal.resourcesApi.controlPlaneResourceEnabled $.Values.internal.resourcesApi.machinePoolResourcesEnabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "cluster.resource.name" $ }}-registry-configuration
data:
registry-config.toml: {{ tpl ($.Files.Get "files/etc/containerd/config.toml") $ | b64enc | quote }}
{{- end }}
37 changes: 36 additions & 1 deletion helm/cluster/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,12 @@
"title": "Resources API",
"description": "Group, version and kind configuration that is required and used by a specific Cluster API provider.",
"required": [
"infrastructureCluster"
"infrastructureCluster",
"clusterResourceEnabled",
"controlPlaneResourceEnabled",
"machinePoolResourcesEnabled",
"machineHealthCheckResourceEnabled",
"bastionResourceEnabled"
],
"properties": {
"bastion": {
Expand All @@ -1373,8 +1378,38 @@
}
}
},
"bastionResourceEnabled": {
"type": "boolean",
"title": "Bastion resource enabled",
"description": "Flag that indicates if the Bastion resource is enabled and templated. This is meant only for the initial development purposes for the sake of incrementally integrating cluster chart into cluster-$provider apps.",
"default": true
},
"clusterResourceEnabled": {
"type": "boolean",
"title": "Cluster resource enabled",
"description": "Flag that indicates if the Cluster resource is enabled and templated. This is meant only for the initial development purposes for the sake of incrementally integrating cluster chart into cluster-$provider apps.",
"default": true
},
"controlPlaneResourceEnabled": {
"type": "boolean",
"title": "Control plane resource enabled",
"description": "Flag that indicates if the control plane resource is enabled and templated. This is meant only for the initial development purposes for the sake of incrementally integrating cluster chart into cluster-$provider apps.",
"default": true
},
"infrastructureCluster": {
"$ref": "#/$defs/infrastructureCluster"
},
"machineHealthCheckResourceEnabled": {
"type": "boolean",
"title": "MachineHealthCheck resource enabled",
"description": "Flag that indicates if the MachineHealthCheck resource is enabled and templated. This is meant only for the initial development purposes for the sake of incrementally integrating cluster chart into cluster-$provider apps.",
"default": true
},
"machinePoolResourcesEnabled": {
"type": "boolean",
"title": "Machine pool resources enabled",
"description": "Flag that indicates if the machine pool resources are enabled and templated. This is meant only for the initial development purposes for the sake of incrementally integrating cluster chart into cluster-$provider apps.",
"default": true
}
},
"oneOf": [
Expand Down
5 changes: 5 additions & 0 deletions helm/cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ internal:
resourcesApi:
bastion:
infrastructureMachineTemplate: {}
bastionResourceEnabled: true
clusterResourceEnabled: true
controlPlaneResourceEnabled: true
infrastructureCluster: {}
machineHealthCheckResourceEnabled: true
machinePoolResourcesEnabled: true
workers:
kubeadmConfig:
ignition:
Expand Down

0 comments on commit bc2f86d

Please sign in to comment.