Skip to content

Commit

Permalink
feat: Allow disabling CRDs for specific controllers (#144)
Browse files Browse the repository at this point in the history
feat: Allow disabling CRDs for specific controllers
Currently, `installCRDs` is a global flag and there's no way to only install CRDs for certain controllers
This PR adds another level (true by default for retrocompatibility) that can be used to disable CRD installation for a specific controller

Signed-off-by: Julien Duchesne <[email protected]>
  • Loading branch information
julienduchesne authored Dec 6, 2022
1 parent bf2a61d commit e92e307
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 23 deletions.
16 changes: 8 additions & 8 deletions charts/flux2/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
annotations:
artifacthub.io/changes: |
- "[Added]: Allow disabling CRD installation for specific controllers"
apiVersion: v2
name: flux2
description: A Helm chart for flux2
type: application
version: 2.1.1
appVersion: 0.37.0
description: A Helm chart for flux2
name: flux2
sources:
- https://github.com/fluxcd-community/helm-charts
annotations:
artifacthub.io/changes: |
- "[Chore]: Fix bug with multi-tenancy clusterrolebinding"
- https://github.com/fluxcd-community/helm-charts
type: application
version: 2.2.0
2 changes: 1 addition & 1 deletion charts/flux2/templates/helm-controller.crds.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.installCRDs }}
{{- if and .Values.installCRDs .Values.helmController.create }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.installCRDs }}
{{- if and .Values.installCRDs .Values.imageAutomationController.create }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.installCRDs }}
{{- if and .Values.installCRDs .Values.imageReflectionController.create }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
2 changes: 1 addition & 1 deletion charts/flux2/templates/kustomize-controller.crds.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.installCRDs }}
{{- if and .Values.installCRDs .Values.kustomizeController.create }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
2 changes: 1 addition & 1 deletion charts/flux2/templates/notification-controller.crds.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.installCRDs }}
{{- if and .Values.installCRDs .Values.notificationController.create }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
2 changes: 1 addition & 1 deletion charts/flux2/templates/source-controller.crds.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.installCRDs }}
{{- if and .Values.installCRDs .Values.sourceController.create }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ should match snapshot of default values:
app.kubernetes.io/part-of: flux
app.kubernetes.io/version: 0.37.0
control-plane: controller
helm.sh/chart: flux2-2.1.1
helm.sh/chart: flux2-2.2.0
name: helm-controller
spec:
replicas: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ should match snapshot of default values:
app.kubernetes.io/part-of: flux
app.kubernetes.io/version: 0.37.0
control-plane: controller
helm.sh/chart: flux2-2.1.1
helm.sh/chart: flux2-2.2.0
name: image-automation-controller
spec:
replicas: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ should match snapshot of default values:
app.kubernetes.io/part-of: flux
app.kubernetes.io/version: 0.37.0
control-plane: controller
helm.sh/chart: flux2-2.1.1
helm.sh/chart: flux2-2.2.0
name: image-reflector-controller
spec:
replicas: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ should match snapshot of default values:
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/part-of: flux
app.kubernetes.io/version: 0.37.0
helm.sh/chart: flux2-2.1.1
helm.sh/chart: flux2-2.2.0
name: test1
namespace: NAMESPACE
type: Opaque
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ should match snapshot of default values:
app.kubernetes.io/part-of: flux
app.kubernetes.io/version: 0.37.0
control-plane: controller
helm.sh/chart: flux2-2.1.1
helm.sh/chart: flux2-2.2.0
name: kustomize-controller
spec:
replicas: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ should match snapshot of default values:
app.kubernetes.io/part-of: flux
app.kubernetes.io/version: 0.37.0
control-plane: controller
helm.sh/chart: flux2-2.1.1
helm.sh/chart: flux2-2.2.0
name: notification-controller
spec:
replicas: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ should match snapshot of default values:
app.kubernetes.io/part-of: flux
app.kubernetes.io/version: 0.37.0
control-plane: controller
helm.sh/chart: flux2-2.1.1
helm.sh/chart: flux2-2.2.0
name: source-controller
spec:
replicas: 1
Expand Down
12 changes: 10 additions & 2 deletions hack/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ delete_temp_dir() {
}
trap delete_temp_dir EXIT


get_controller_values_attribute() {
echo "$(echo $1 | cut -d '/' -f5 | sed 's/reflector/reflection/' | sed 's/-./\U&/g' | tr -d '-')"
}


for FILE in `cat .work/flux2/manifests/crds/kustomization.yaml | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*"`
do

Expand Down Expand Up @@ -38,7 +44,8 @@ transformers:
- global-labels.yaml
EOF

echo "{{- if .Values.installCRDs }}" > ./charts/flux2/templates/${FILE##*/}
attribute="$(get_controller_values_attribute ${FILE})"
echo "{{- if and .Values.installCRDs .Values.${attribute}.create }}" > ./charts/flux2/templates/${FILE##*/}
kubectl kustomize "${TEMPDIR}" >> ./charts/flux2/templates/${FILE##*/}
echo "{{- end }}">> ./charts/flux2/templates/${FILE##*/}

Expand All @@ -53,7 +60,8 @@ done
for FILE in `cat .work/flux2/manifests/crds/kustomization.yaml | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*"`
do

diff -B ./charts/flux2/values.yaml <(controllerName=`echo $FILE | cut -d '/' -f5 | tr -d '-'` controllerVersion=`echo $FILE | cut -d '/' -f8` yq eval '.[env(controllerName)].tag = env(controllerVersion)' ./charts/flux2/values.yaml) | patch ./charts/flux2/values.yaml
attribute="$(get_controller_values_attribute ${FILE})"
diff -B ./charts/flux2/values.yaml <(controllerName="${attribute}" controllerVersion=`echo $FILE | cut -d '/' -f8` yq eval '.[env(controllerName)].tag = env(controllerVersion)' ./charts/flux2/values.yaml) | patch ./charts/flux2/values.yaml

# update unittest snapshots
controllerName=`echo $FILE | cut -d '/' -f5`
Expand Down

0 comments on commit e92e307

Please sign in to comment.