Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Add Pod Annotations and Labels to Helm Chart #400

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions charts/hnc/templates/hnc-controller-manager-ha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ spec:
metadata:
annotations:
prometheus.io/scrape: "true"
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8}}
{{- end }}
labels:
control-plane: controller-manager-ha
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8}}
{{- end }}
spec:
containers:
- args:
Expand Down
6 changes: 6 additions & 0 deletions charts/hnc/templates/hnc-controller-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ spec:
metadata:
annotations:
prometheus.io/scrape: "true"
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8}}
{{- end }}
labels:
control-plane: controller-manager
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8}}
{{- end }}
spec:
containers:
- args:
Expand Down
2 changes: 2 additions & 0 deletions charts/hnc/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ ha:
nodeSelector: {}
affinity: {}
tolerations: []
podAnnotations: {}
podLabels: {}
34 changes: 31 additions & 3 deletions hack/helm_patches/update-helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,27 @@ cat <<'EOF'
EOF
)

POD_ANNOTATIONS=$(
cat <<'EOF'
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8}}
{{- end }}
EOF
)

POD_LABELS=$(
cat <<'EOF'
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8}}
{{- end }}
EOF
)

# Update templates
for output_file in ${TEMPLATESDIR}/*.yaml; do
# Add prefix placeholder to Resource Name
if [ "$($YQ '.metadata | has("name")' $output_file)" = "true" ]; then

resourcename=$($YQ -N '.metadata.name' $output_file | sed s/hnc-//g) $YQ -N -i '.metadata.name |= "{{ include \"hnc.fullname\" . }}-" + strenv(resourcename)' $output_file

# Add prefix placeholder to Service Name of WebhookConfiguration
Expand Down Expand Up @@ -148,6 +164,12 @@ for output_file in ${TEMPLATESDIR}/*.yaml; do
sed -i -e 's/tolerations:/\{{- with .Values.manager.tolerations }}\n \ tolerations:/' $output_file
sed -i -e '/tolerations:/a \ {{- end }}' $output_file

# Add scope block for podLabels
awk -i inplace -v pl="$POD_LABELS" 'BEGIN{found=0} /labels:/ {count++} (count==2 && found==0) {print $0 "\n" pl; found=1; next} 1' $output_file

# Add scope block for podAnnotations
awk -i inplace -v pa="$POD_ANNOTATIONS" 'BEGIN{found=0} /annotations:/ {count++} (count==1 && found==0) {print $0 "\n" pa; found=1; next} 1' $output_file

# [HA] Additional update for controller-manager-ha Deployment
elif [ "$($YQ '.metadata.name | (. == "*-controller-manager-ha")' $output_file)" = "true" ]; then

Expand All @@ -167,6 +189,12 @@ for output_file in ${TEMPLATESDIR}/*.yaml; do
sed -i -e 's/tolerations:/\{{- with .Values.ha.manager.tolerations }}\n \ tolerations:/' $output_file
sed -i -e '/tolerations:/a \ {{- end }}' $output_file

# [HA] Add scope block for podLabels
awk -i inplace -v pl="$POD_LABELS" 'BEGIN{found=0} /labels:/ {count++} (count==2 && found==0) {print $0 "\n" pl; found=1; next} 1' $output_file

# [HA] Add scope block for podAnnotations
awk -i inplace -v pa="$POD_ANNOTATIONS" 'BEGIN{found=0} /annotations:/ {count++} (count==1 && found==0) {print $0 "\n" pa; found=1; next} 1' $output_file

# [HA] Add conditional blocks for controller-manager-ha Deployment
sed -i -e '1s/^/{{- if .Values.ha.enabled }}\n/g' $output_file
sed -i -e '$s/$/\n{{- end }}/g' $output_file
Expand All @@ -184,7 +212,7 @@ for output_file in ${TEMPLATESDIR}/*.yaml; do
sed -i -e '/imagePullPolicy:/a \ {{- end }}' $output_file

# Remove extra '' from templates
sed -i -e s/\'//g $output_file
sed -i -e s/\'//g $output_file

# Update RoleBinding template
elif [ "$($YQ '.kind | (. == "RoleBinding")' $output_file)" = "true" ]; then
Expand Down Expand Up @@ -214,4 +242,4 @@ for output_file in ${TEMPLATESDIR}/*.yaml; do
echo "$HRQWEBHOOK" >> "$output_file"
fi

done
done