Skip to content

Commit

Permalink
Add overlay for deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-w-3 committed Sep 19, 2024
1 parent b558106 commit 4530a8c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .helm/starter/templates/controller/_controller.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{/*
This template gets filled with the operator SDK's controller definition
during chart build
*/}}
{{- define "awx-operator.controller" -}}
15 changes: 15 additions & 0 deletions .helm/starter/templates/controller/controller-overlay.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- $controllerTemplate := (include "awx-operator.controller" $) | fromYaml }}

{{- $existingLabels := default dict ($controllerTemplate.metadata).labels }}
{{- $mergedLabels := mergeOverwrite $existingLabels $.Values.controller.labels }}
{{- /* Use set in case the dict didn't exist */}}
{{- $_ := set $controllerTemplate.metadata "labels" $mergedLabels }}

{{- $existingAnnotations := default dict ($controllerTemplate.metadata).annotations }}
{{- $mergedAnnotations := mergeOverwrite $existingAnnotations $.Values.controller.annotations }}
{{- /* Use set in case the dict didn't exist */}}
{{- $_ := set $controllerTemplate.metadata "annotations" $mergedAnnotations }}

{{- $_ := mergeOverwrite $controllerTemplate.spec $.Values.controller.spec }}

{{ $controllerTemplate | toYaml }}
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,24 @@ helm-chart-generate: kustomize helm kubectl-slice yq charts
for file in charts/$(CHART_NAME)/raw-files/*rolebinding*; do\
$(YQ) -i '.subjects[0].namespace = "{{ .Release.Namespace }}"' $${file};\
done
# Add .spec.replicas for the controller-manager deployment
for file in charts/$(CHART_NAME)/raw-files/deployment-*-controller-manager.yaml; do\
$(YQ) -i '.spec.replicas = "{{ (.Values.Operator).replicas | default 1 }}"' $${file};\
done

# Correct .metadata.name for cluster scoped resources
cluster_scoped_files="charts/$(CHART_NAME)/raw-files/clusterrolebinding-awx-operator-proxy-rolebinding.yaml charts/$(CHART_NAME)/raw-files/clusterrole-awx-operator-metrics-reader.yaml charts/$(CHART_NAME)/raw-files/clusterrole-awx-operator-proxy-role.yaml";\
for file in $${cluster_scoped_files}; do\
$(YQ) -i '.metadata.name += "-{{ .Release.Name }}"' $${file};\
done
# Correct the reference for the clusterrolebinding
$(YQ) -i '.roleRef.name += "-{{ .Release.Name }}"' 'charts/$(CHART_NAME)/raw-files/clusterrolebinding-awx-operator-proxy-rolebinding.yaml'
# Correct .spec.replicas type for the controller-manager deployment

# Feed controller deployment file into template to allow for override from values
for file in charts/$(CHART_NAME)/raw-files/deployment-*-controller-manager.yaml; do\
$(SED_I) "s/'{{ (.Values.Operator).replicas | default 1 }}'/{{ (.Values.Operator).replicas | default 1 }}/g" $${file};\
cat $${file} >> charts/$(CHART_NAME)/templates/controller/_controller.tpl;\
echo "\n---" >> charts/$(CHART_NAME)/templates/controller/_controller.tpl;\
rm -f $${file} ;\
done
echo '{{- end -}}' >> charts/$(CHART_NAME)/templates/controller/_controller.tpl


# move all custom resource definitions to crds folder
mkdir charts/$(CHART_NAME)/crds
mv charts/$(CHART_NAME)/raw-files/customresourcedefinition*.yaml charts/$(CHART_NAME)/crds/.
Expand Down

0 comments on commit 4530a8c

Please sign in to comment.