Skip to content

Commit c6ccfc1

Browse files
Add labels and annotations to pods.
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. Also update labels and annotations for injected pods (FlagD sidecar, FlagD standalone, and FlagD proxy). Signed-off-by: Christopher Pitstick <cpitstick@lat.ai>
1 parent 917a680 commit c6ccfc1

File tree

14 files changed

+189
-69
lines changed

14 files changed

+189
-69
lines changed
+19-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# This script is a hack to support helm flow control in kustomize overlays, which would otherwise break them.
44
# It allows us to render helm template bindings and add newlines.
55
# For instance, it transforms "___{{ .Value.myValue }}___" to {{ .Value.myValue }}.
6-
# It also adds newlines wherever ___newline___ is found.
7-
8-
CHARTS_DIR='./chart/open-feature-operator/templates';
6+
# It also adds newlines wherever ___newline___ is found, and other operations. See
7+
# sed_expressions below.
98

109
echo 'Running strip-kustomize-helm.sh script'
11-
filenames=`find $CHARTS_DIR -name "*.yaml"`
12-
for file in $filenames; do
13-
sed -i "s/___newline___/\\n/g" $file
14-
sed -i "s/\"___//g" $file
15-
sed -i "s/___\"//g" $file
16-
sed -i "s/___//g" $file
10+
CHARTS_DIR='./chart/open-feature-operator/templates'
11+
# Careful! Ordering of these expressions matter!
12+
sed_expressions=(
13+
"s/___newline___/\\n/g"
14+
"s/___space___/ /g"
15+
"s/\"___//g"
16+
"s/___\"//g"
17+
"/___delete_me___/d"
18+
"s/___//g"
19+
)
20+
find $CHARTS_DIR -name "*.yaml" | while read file; do
21+
for expr in "${sed_expressions[@]}"; do
22+
sed -i "$expr" "$file"
23+
done
1724
done
18-
echo 'Done running strip-kustomize-helm.sh script'
25+
26+
echo 'Done running strip-kustomize-helm.sh script'

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ set-helm-overlay:
252252
helm-package: set-helm-overlay generate release-manifests helm
253253
mkdir -p chart/open-feature-operator/templates/crds
254254
mv chart/open-feature-operator/templates/*customresourcedefinition* chart/open-feature-operator/templates/crds
255-
sh .github/scripts/strip-kustomize-helm.sh
255+
.github/scripts/strip-kustomize-helm.sh
256256
$(HELM) package --version $(CHART_VERSION) chart/open-feature-operator
257257
mkdir -p charts && mv open-feature-operator-*.tgz charts
258258
$(HELM) repo index --url https://open-feature.github.io/open-feature-operator/charts charts

chart/open-feature-operator/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ The command removes all the Kubernetes components associated with the chart and
9797
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
9898
| `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` |
9999
| `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"}] | `[]` |
100+
| `labels` | Labels to apply to all of the pods in the operator. | `{}` |
101+
| `annotations` | Annotations to apply to all of the pods in the operator. | `{}` |
100102

101103
### Sidecar configuration
102104

@@ -167,7 +169,7 @@ The command removes all the Kubernetes components associated with the chart and
167169
| `controllerManager.kubeRbacProxy.resources.requests.cpu` | Sets cpu resource requests for kube-rbac-proxy. | `5m` |
168170
| `controllerManager.kubeRbacProxy.resources.requests.memory` | Sets memory resource requests for kube-rbac-proxy. | `64Mi` |
169171
| `controllerManager.manager.image.repository` | Sets the image for the operator. | `ghcr.io/open-feature/open-feature-operator` |
170-
| `controllerManager.manager.image.tag` | Sets the version tag for the operator. | `v0.6.1` |
172+
| `controllerManager.manager.image.tag` | Sets the version tag for the operator. | `v0.7.0` |
171173
| `controllerManager.manager.resources.limits.cpu` | Sets cpu resource limits for operator. | `500m` |
172174
| `controllerManager.manager.resources.limits.memory` | Sets memory resource limits for operator. | `128Mi` |
173175
| `controllerManager.manager.resources.requests.cpu` | Sets cpu resource requests for operator. | `10m` |
@@ -180,3 +182,4 @@ The command removes all the Kubernetes components associated with the chart and
180182
| `managerConfig.controllerManagerConfigYaml.metrics.bindAddress` | Sets the bind address for metrics (combined with bindPort). | `127.0.0.1` |
181183
| `managerConfig.controllerManagerConfigYaml.metrics.bindPort` | Sets the bind port for metrics. | `8080` |
182184
| `managerConfig.controllerManagerConfigYaml.webhook.port` | Sets the bind address for webhook. | `9443` |
185+

chart/open-feature-operator/values.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
defaultNamespace: open-feature-operator-system
55
## @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"}]
66
imagePullSecrets: []
7+
## @param labels Labels to apply to all of the pods in the operator.
8+
labels: {}
9+
## @param annotations Annotations to apply to all of the pods in the operator.
10+
annotations: {}
711

812
## @section Sidecar configuration
913
sidecarConfiguration:

common/flagdproxy/flagdproxy.go

+23-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/go-logr/logr"
99
"github.com/open-feature/open-feature-operator/common"
1010
"github.com/open-feature/open-feature-operator/common/types"
11+
"golang.org/x/exp/maps"
1112
appsV1 "k8s.io/api/apps/v1"
1213
corev1 "k8s.io/api/core/v1"
1314
"k8s.io/apimachinery/pkg/api/errors"
@@ -39,9 +40,11 @@ type FlagdProxyConfiguration struct {
3940
Namespace string
4041
OperatorDeploymentName string
4142
ImagePullSecrets []string
43+
Labels map[string]string
44+
Annotations map[string]string
4245
}
4346

44-
func NewFlagdProxyConfiguration(env types.EnvConfig, imagePullSecrets []string) *FlagdProxyConfiguration {
47+
func NewFlagdProxyConfiguration(env types.EnvConfig, imagePullSecrets []string, labels map[string]string, annotations map[string]string) *FlagdProxyConfiguration {
4548
return &FlagdProxyConfiguration{
4649
Image: env.FlagdProxyImage,
4750
Tag: env.FlagdProxyTag,
@@ -51,6 +54,8 @@ func NewFlagdProxyConfiguration(env types.EnvConfig, imagePullSecrets []string)
5154
ManagementPort: env.FlagdProxyManagementPort,
5255
DebugLogging: env.FlagdProxyDebugLogging,
5356
ImagePullSecrets: imagePullSecrets,
57+
Labels: labels,
58+
Annotations: annotations,
5459
}
5560
}
5661

@@ -151,6 +156,21 @@ func (f *FlagdProxyHandler) newFlagdProxyManifest(ownerReference *metav1.OwnerRe
151156
Name: secret,
152157
})
153158
}
159+
flagdLabels := map[string]string{
160+
"app": FlagdProxyDeploymentName,
161+
"app.kubernetes.io/name": FlagdProxyDeploymentName,
162+
"app.kubernetes.io/managed-by": common.ManagedByAnnotationValue,
163+
"app.kubernetes.io/version": f.config.Tag,
164+
}
165+
if len(f.config.Labels) > 0 {
166+
maps.Copy(flagdLabels, f.config.Labels)
167+
}
168+
169+
// No "built-in" annotations to merge at this time. If adding them follow the same pattern as labels.
170+
flagdAnnotations := map[string]string{}
171+
if len(f.config.Annotations) > 0 {
172+
maps.Copy(flagdAnnotations, f.config.Annotations)
173+
}
154174

155175
return &appsV1.Deployment{
156176
ObjectMeta: metav1.ObjectMeta{
@@ -172,12 +192,8 @@ func (f *FlagdProxyHandler) newFlagdProxyManifest(ownerReference *metav1.OwnerRe
172192
},
173193
Template: corev1.PodTemplateSpec{
174194
ObjectMeta: metav1.ObjectMeta{
175-
Labels: map[string]string{
176-
"app": FlagdProxyDeploymentName,
177-
"app.kubernetes.io/name": FlagdProxyDeploymentName,
178-
"app.kubernetes.io/managed-by": common.ManagedByAnnotationValue,
179-
"app.kubernetes.io/version": f.config.Tag,
180-
},
195+
Labels: flagdLabels,
196+
Annotations: flagdAnnotations,
181197
},
182198
Spec: corev1.PodSpec{
183199
ServiceAccountName: FlagdProxyServiceAccountName,

common/flagdproxy/flagdproxy_test.go

+25-8
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,22 @@ import (
2121

2222
var pullSecrets = []string{"test-pullSecret"}
2323

24+
var labels = map[string]string{
25+
"label1": "labelValue1",
26+
"label2": "labelValue2",
27+
}
28+
29+
var annotations = map[string]string{
30+
"annotation1": "annotationValue1",
31+
"annotation2": "annotationValue2",
32+
}
33+
2434
func TestNewFlagdProxyConfiguration(t *testing.T) {
2535

2636
kpConfig := NewFlagdProxyConfiguration(types.EnvConfig{
2737
FlagdProxyPort: 8015,
2838
FlagdProxyManagementPort: 8016,
29-
}, pullSecrets)
39+
}, pullSecrets, labels, annotations)
3040

3141
require.NotNil(t, kpConfig)
3242
require.Equal(t, &FlagdProxyConfiguration{
@@ -35,6 +45,8 @@ func TestNewFlagdProxyConfiguration(t *testing.T) {
3545
DebugLogging: false,
3646
OperatorDeploymentName: common.OperatorDeploymentName,
3747
ImagePullSecrets: pullSecrets,
48+
Labels: labels,
49+
Annotations: annotations,
3850
}, kpConfig)
3951
}
4052

@@ -48,7 +60,7 @@ func TestNewFlagdProxyConfiguration_OverrideEnvVars(t *testing.T) {
4860
FlagdProxyDebugLogging: true,
4961
}
5062

51-
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets)
63+
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets, labels, annotations)
5264

5365
require.NotNil(t, kpConfig)
5466
require.Equal(t, &FlagdProxyConfiguration{
@@ -60,11 +72,13 @@ func TestNewFlagdProxyConfiguration_OverrideEnvVars(t *testing.T) {
6072
Namespace: "my-namespace",
6173
OperatorDeploymentName: common.OperatorDeploymentName,
6274
ImagePullSecrets: pullSecrets,
75+
Labels: labels,
76+
Annotations: annotations,
6377
}, kpConfig)
6478
}
6579

6680
func TestNewFlagdProxyHandler(t *testing.T) {
67-
kpConfig := NewFlagdProxyConfiguration(types.EnvConfig{}, pullSecrets)
81+
kpConfig := NewFlagdProxyConfiguration(types.EnvConfig{}, pullSecrets, labels, annotations)
6882

6983
require.NotNil(t, kpConfig)
7084

@@ -100,7 +114,7 @@ func TestDoesFlagdProxyExist(t *testing.T) {
100114
},
101115
}
102116

103-
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets)
117+
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets, labels, annotations)
104118

105119
require.NotNil(t, kpConfig)
106120

@@ -128,7 +142,7 @@ func TestFlagdProxyHandler_HandleFlagdProxy_ProxyExistsWithBadVersion(t *testing
128142
env := types.EnvConfig{
129143
PodNamespace: "ns",
130144
}
131-
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets)
145+
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets, labels, annotations)
132146

133147
require.NotNil(t, kpConfig)
134148

@@ -187,7 +201,7 @@ func TestFlagdProxyHandler_HandleFlagdProxy_ProxyExistsWithoutLabel(t *testing.T
187201
env := types.EnvConfig{
188202
PodNamespace: "ns",
189203
}
190-
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets)
204+
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets, labels, annotations)
191205

192206
require.NotNil(t, kpConfig)
193207

@@ -236,7 +250,7 @@ func TestFlagdProxyHandler_HandleFlagdProxy_ProxyExistsWithNewestVersion(t *test
236250
env := types.EnvConfig{
237251
PodNamespace: "ns",
238252
}
239-
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets)
253+
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets, labels, annotations)
240254

241255
require.NotNil(t, kpConfig)
242256

@@ -280,7 +294,7 @@ func TestFlagdProxyHandler_HandleFlagdProxy_CreateProxy(t *testing.T) {
280294
FlagdProxyManagementPort: 90,
281295
FlagdProxyDebugLogging: true,
282296
}
283-
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets)
297+
kpConfig := NewFlagdProxyConfiguration(env, pullSecrets, labels, annotations)
284298

285299
require.NotNil(t, kpConfig)
286300

@@ -357,7 +371,10 @@ func TestFlagdProxyHandler_HandleFlagdProxy_CreateProxy(t *testing.T) {
357371
"app.kubernetes.io/name": FlagdProxyDeploymentName,
358372
"app.kubernetes.io/managed-by": common.ManagedByAnnotationValue,
359373
"app.kubernetes.io/version": "tag",
374+
"label1": "labelValue1",
375+
"label2": "labelValue2",
360376
},
377+
Annotations: annotations,
361378
},
362379
Spec: corev1.PodSpec{
363380
ServiceAccountName: FlagdProxyServiceAccountName,

config/overlays/helm/manager.yaml

+11-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ metadata:
66
spec:
77
replicas: 0{{ .Values.controllerManager.replicas }}
88
template:
9+
metadata:
10+
# this is transformed by .github/scripts/strip-kustomize-helm.sh
11+
annotations:
12+
___delete_me___: "___ ___newline___{{ if .Values.annotations }}{{___space___toYaml___space___.Values.annotations___space___|___space___indent___space___8___space___}}{{ end }}___"
13+
# this is transformed by .github/scripts/strip-kustomize-helm.sh
14+
labels:
15+
___delete_me___: "___ ___newline___{{ if .Values.labels }}___newline___{{___space___toYaml___space___.Values.labels___space___|___space___indent___space___8___space___}}{{ end }}___"
916
spec:
1017
# this is transformed by .github/scripts/strip-kustomize-helm.sh
11-
___imagePullSecrets___: "___ ___newline___{{ toYaml .Values.imagePullSecrets | indent 8 }}___"
12-
dnsPolicy: "{{ .Values.controllerManager.manager.dnsPolicy }}"
18+
___imagePullSecrets___: "___ ___newline___ {{ toYaml .Values.imagePullSecrets___space___|___space___indent___space___8___space___}}___"
1319
# this is transformed by .github/scripts/strip-kustomize-helm.sh
1420
hostNetwork: "___{{ .Values.controllerManager.manager.hostNetwork }}___"
21+
dnsPolicy: "{{ .Values.controllerManager.manager.dnsPolicy }}"
1522
containers:
1623
- name: manager
1724
image: "{{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag }}"
@@ -104,6 +111,8 @@ spec:
104111
- --sidecar-ram-request={{ .Values.sidecarConfiguration.resources.requests.memory }}
105112
- --image-pull-secrets={{ range .Values.imagePullSecrets }}{{ .name }},{{- end }}
106113
- --metrics-bind-address=:{{ .Values.managerConfig.controllerManagerConfigYaml.metrics.bindPort }}
114+
- --labels={{ $labelKeys := keys .Values.labels -}}{{- $labelPairs := list -}}{{- range $key := $labelKeys -}}{{- $labelPairs = append $labelPairs (printf "%s:%s" $key (index $.Values.labels $key)) -}}{{- end -}}{{- join "," $labelPairs }}
115+
- --annotations={{ $annotationKeys := keys .Values.annotations -}}{{- $annotationPairs := list -}}{{- range $key := $annotationKeys -}}{{- $annotationPairs = append $annotationPairs (printf "%s:%s" $key (index $.Values.annotations $key)) -}}{{- end -}}{{- join "," $annotationPairs }}
107116
- name: kube-rbac-proxy
108117
image: "{{ .Values.controllerManager.kubeRbacProxy.image.repository }}:{{ .Values.controllerManager.kubeRbacProxy.image.tag }}"
109118
resources:

controllers/core/featureflagsource/controller_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ func TestFeatureFlagSourceReconciler_Reconcile(t *testing.T) {
3030
)
3131
var pullSecrets = []string{"test-pullsecret"}
3232

33+
var labels = map[string]string{
34+
"label1": "labelValue1",
35+
"label2": "labelValue2",
36+
}
37+
38+
var annotations = map[string]string{
39+
"annotation1": "annotationValue1",
40+
"annotation2": "annotationValue2",
41+
}
42+
3343
tests := []struct {
3444
name string
3545
fsConfig *api.FeatureFlagSource
@@ -93,7 +103,7 @@ func TestFeatureFlagSourceReconciler_Reconcile(t *testing.T) {
93103
kpConfig := flagdproxy.NewFlagdProxyConfiguration(commontypes.EnvConfig{
94104
FlagdProxyImage: "ghcr.io/open-feature/flagd-proxy",
95105
FlagdProxyTag: flagdProxyTag,
96-
}, pullSecrets)
106+
}, pullSecrets, labels, annotations)
97107

98108
kpConfig.Namespace = testNamespace
99109
kph := flagdproxy.NewFlagdProxyHandler(
@@ -169,6 +179,7 @@ func createTestDeployment(fsConfigName string, testNamespace string, deploymentN
169179
},
170180
},
171181
Spec: corev1.PodSpec{
182+
ImagePullSecrets: []corev1.LocalObjectReference{{Name: "test-pullSecret"}},
172183
Containers: []corev1.Container{
173184
{
174185
Name: "test",

controllers/core/flagd/common/common.go

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ type FlagdConfiguration struct {
99
Image string
1010
Tag string
1111
ImagePullSecrets []string
12+
Labels map[string]string
13+
Annotations map[string]string
1214

1315
OperatorNamespace string
1416
OperatorDeploymentName string

controllers/core/flagd/config.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
resources "github.com/open-feature/open-feature-operator/controllers/core/flagd/common"
77
)
88

9-
func NewFlagdConfiguration(env types.EnvConfig, imagePullSecrets []string) resources.FlagdConfiguration {
9+
func NewFlagdConfiguration(env types.EnvConfig, imagePullSecrets []string, labels map[string]string, annotations map[string]string) resources.FlagdConfiguration {
1010
return resources.FlagdConfiguration{
1111
Image: env.FlagdImage,
1212
Tag: env.FlagdTag,
@@ -17,5 +17,7 @@ func NewFlagdConfiguration(env types.EnvConfig, imagePullSecrets []string) resou
1717
ManagementPort: env.FlagdManagementPort,
1818
DebugLogging: env.FlagdDebugLogging,
1919
ImagePullSecrets: imagePullSecrets,
20+
Labels: labels,
21+
Annotations: annotations,
2022
}
2123
}

0 commit comments

Comments
 (0)