Skip to content

Commit

Permalink
Add labels and annotations to pods.
Browse files Browse the repository at this point in the history
Currently, there is only one deployment, so avoid premature optimization
by making these global (and follow the same pattern for
imagePullSecrets)

Requires more aggressive usage of the `strip-kustomize-helm.sh` script
because we have to preserve existing annotations and labels from the
config/manager directory.

Signed-off-by: Christopher Pitstick <cpitstick@lat.ai>
  • Loading branch information
cpitstick-latai committed Jun 20, 2024
1 parent 339e5c8 commit 463eec5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
30 changes: 19 additions & 11 deletions .github/scripts/strip-kustomize-helm.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#!/bin/bash
#!/usr/bin/env bash

# This script is a hack to support helm flow control in kustomize overlays, which would otherwise break them.
# It allows us to render helm template bindings and add newlines.
# For instance, it transforms "___{{ .Value.myValue }}___" to {{ .Value.myValue }}.
# It also adds newlines wherever ___newline___ is found.

CHARTS_DIR='./chart/open-feature-operator/templates';
# It also adds newlines wherever ___newline___ is found, and other operations. See
# sed_expressions below.

echo 'Running strip-kustomize-helm.sh script'
filenames=`find $CHARTS_DIR -name "*.yaml"`
for file in $filenames; do
sed -i "s/___newline___/\\n/g" $file
sed -i "s/\"___//g" $file
sed -i "s/___\"//g" $file
sed -i "s/___//g" $file
CHARTS_DIR='./chart/open-feature-operator/templates'
# Careful! Ordering of these expressions matter!
sed_expressions=(
"s/___newline___/\\n/g"
"s/___space___/ /g"
"s/\"___//g"
"s/___\"//g"
"/___delete_me___/d"
"s/___//g"
)
find $CHARTS_DIR -name "*.yaml" | while read file; do
for expr in "${sed_expressions[@]}"; do
sed -i "$expr" "$file"
done
done
echo 'Done running strip-kustomize-helm.sh script'

echo 'Done running strip-kustomize-helm.sh script'
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ set-helm-overlay:
helm-package: set-helm-overlay generate release-manifests helm
mkdir -p chart/open-feature-operator/templates/crds
mv chart/open-feature-operator/templates/*customresourcedefinition* chart/open-feature-operator/templates/crds
sh .github/scripts/strip-kustomize-helm.sh
.github/scripts/strip-kustomize-helm.sh
$(HELM) package --version $(CHART_VERSION) chart/open-feature-operator
mkdir -p charts && mv open-feature-operator-*.tgz charts
$(HELM) repo index --url https://open-feature.github.io/open-feature-operator/charts charts
Expand Down
4 changes: 3 additions & 1 deletion chart/open-feature-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ The command removes all the Kubernetes components associated with the chart and
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
| `defaultNamespace` | To override the namespace use the `--namespace` flag. This default is provided to ensure that the kustomize build charts in `/templates` deploy correctly when no `namespace` is provided via the `-n` flag. | `open-feature-operator-system` |
| `imagePullSecrets` | Array of ImagePullSecret objects containing credentials for images pulled by the operator (flagdProxyConfiguration.image, flagdConfiguration.image, controllerManager.manager.image, controllerManager.kubeRbacProxy.image). Example: imagePullSecrets: [{"name": "my-secret"}] | `[]` |
| `labels` | Labels to apply to all of the pods in the operator. | `{}` |
| `annotations` | Annotations to apply to all of the pods in the operator. | `{}` |

### Sidecar configuration

Expand Down Expand Up @@ -167,7 +169,7 @@ The command removes all the Kubernetes components associated with the chart and
| `controllerManager.kubeRbacProxy.resources.requests.cpu` | Sets cpu resource requests for kube-rbac-proxy. | `5m` |
| `controllerManager.kubeRbacProxy.resources.requests.memory` | Sets memory resource requests for kube-rbac-proxy. | `64Mi` |
| `controllerManager.manager.image.repository` | Sets the image for the operator. | `ghcr.io/open-feature/open-feature-operator` |
| `controllerManager.manager.image.tag` | Sets the version tag for the operator. | `v0.6.0` |
| `controllerManager.manager.image.tag` | Sets the version tag for the operator. | `v0.6.1` |
| `controllerManager.manager.resources.limits.cpu` | Sets cpu resource limits for operator. | `500m` |
| `controllerManager.manager.resources.limits.memory` | Sets memory resource limits for operator. | `128Mi` |
| `controllerManager.manager.resources.requests.cpu` | Sets cpu resource requests for operator. | `10m` |
Expand Down
4 changes: 4 additions & 0 deletions chart/open-feature-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
defaultNamespace: open-feature-operator-system
## @param imagePullSecrets Array of ImagePullSecret objects containing credentials for images pulled by the operator (flagdProxyConfiguration.image, flagdConfiguration.image, controllerManager.manager.image, controllerManager.kubeRbacProxy.image). Example: imagePullSecrets: [{"name": "my-secret"}]
imagePullSecrets: []
## @param labels Labels to apply to all of the pods in the operator.
labels: {}
## @param annotations Annotations to apply to all of the pods in the operator.
annotations: {}

## @section Sidecar configuration
sidecarConfiguration:
Expand Down
9 changes: 8 additions & 1 deletion config/overlays/helm/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ metadata:
spec:
replicas: 0{{ .Values.controllerManager.replicas }}
template:
metadata:
# this is transformed by .github/scripts/strip-kustomize-helm.sh
annotations:
___delete_me___: "___ ___newline___{{ if .Values.annotations }}{{___space___toYaml___space___.Values.annotations___space___|___space___indent___space___8___space___}}{{ end }}___"
# this is transformed by .github/scripts/strip-kustomize-helm.sh
labels:
___delete_me___: "___ ___newline___{{ if .Values.labels }}___newline___{{___space___toYaml___space___.Values.labels___space___|___space___indent___space___8___space___}}{{ end }}___"
spec:
# this is transformed by .github/scripts/strip-kustomize-helm.sh
___imagePullSecrets___: "___ ___newline___{{ toYaml .Values.imagePullSecrets | indent 8 }}___"
___imagePullSecrets___: "___ ___newline___ {{ toYaml .Values.imagePullSecrets___space___|___space___indent___space___8___space___}}___"
containers:
- name: manager
image: "{{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag }}"
Expand Down

0 comments on commit 463eec5

Please sign in to comment.