diff --git a/.helm/starter/templates/controller/_controller.tpl b/.helm/starter/templates/controller/_controller.tpl new file mode 100644 index 00000000..34ca6d67 --- /dev/null +++ b/.helm/starter/templates/controller/_controller.tpl @@ -0,0 +1,5 @@ +{{/* +This template gets filled with the operator SDK's controller definition +during chart build +*/}} +{{- define "awx-operator.controller" -}} diff --git a/.helm/starter/templates/controller/controller-overlay.yaml b/.helm/starter/templates/controller/controller-overlay.yaml new file mode 100644 index 00000000..16088559 --- /dev/null +++ b/.helm/starter/templates/controller/controller-overlay.yaml @@ -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 }} \ No newline at end of file diff --git a/Makefile b/Makefile index bb5febe1..158b9027 100644 --- a/Makefile +++ b/Makefile @@ -148,10 +148,7 @@ 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\ @@ -159,10 +156,16 @@ helm-chart-generate: kustomize helm kubectl-slice yq charts 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/.