Skip to content

Commit 1372ac5

Browse files
Merge pull request #262 from james-milligan/annotation-refactor
refactor: annotation refactor
2 parents 3ee6075 + 012d9e4 commit 1372ac5

File tree

9 files changed

+60
-12
lines changed

9 files changed

+60
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ kind: Pod
137137
metadata:
138138
name: nginx
139139
annotations:
140-
openfeature.dev: "enabled"
141-
openfeature.dev/featureflagconfiguration: "default.featureflagconfiguration-sample"
140+
openfeature.dev/enabled: "true"
141+
openfeature.dev/featureflagconfiguration: "default/featureflagconfiguration-sample"
142142
spec:
143143
containers:
144144
- name: nginx

config/samples/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ spec:
1212
labels:
1313
app: nginx
1414
annotations:
15-
openfeature.dev: "enabled"
15+
openfeature.dev/enabled: "true"
1616
openfeature.dev/featureflagconfiguration: "featureflagconfiguration-sample"
1717
spec:
1818
containers:
@@ -35,7 +35,7 @@ spec:
3535
labels:
3636
app: nginx
3737
annotations:
38-
openfeature.dev: "enabled"
38+
openfeature.dev/enabled: "true"
3939
openfeature.dev/featureflagconfiguration: "featureflagconfiguration-sample"
4040
spec:
4141
containers:

config/samples/end-to-end.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ spec:
6262
labels:
6363
app: open-feature-demo
6464
annotations:
65-
openfeature.dev: "enabled"
65+
openfeature.dev/enabled: "true"
6666
openfeature.dev/featureflagconfiguration: "end-to-end"
6767
spec:
6868
serviceAccountName: open-feature-demo-sa

config/samples/pod.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Pod
33
metadata:
44
name: nginx
55
annotations:
6-
openfeature.dev: "enabled"
6+
openfeature.dev/enabled: "true"
77
openfeature.dev/featureflagconfiguration: "featureflagconfiguration-sample"
88
spec:
99
containers:

docs/annotations.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Annotations
2+
3+
The following annotations are used by the operator to control the injection and define configuration of the flagd sidecar.
4+
5+
### `openfeature.dev/enabled`
6+
When a value of `"true"` is provided, the operator will inject a flagd sidecar into the annotated pods.
7+
Example:
8+
```
9+
metadata:
10+
annotations:
11+
openfeature.dev/enabled: "true"
12+
```
13+
14+
### `openfeature.dev/featureflagconfiguration`
15+
This annotation specifies the names of the FeatureFlagConfigurations used to configure the injected flagd sidecar.
16+
The annotation value a comma separated list of values following one of 2 patterns: {NAME} or {NAMESPACE}/{NAME}.
17+
If no namespace is provided it is assumed that the CR is within the same namespace as the deployed pod.
18+
Example:
19+
```
20+
metadata:
21+
annotations:
22+
openfeature.dev/enabled: "true"
23+
openfeature.dev/featureflagconfiguration: "demo, test/demo-2"
24+
```
25+
26+
### `openfeature.dev`
27+
*This annotation is deprecated in favour of the `openfeature.dev/enabled` annotation and should no longer be used.*
28+
29+
When a value of `"enabled"` is provided, the operator will inject a flagd sidecar into the annotated pods.
30+
Example:
31+
```
32+
metadata:
33+
annotations:
34+
openfeature.dev: "enabled"
35+
```

test/e2e/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ spec:
5858
labels:
5959
app: open-feature-e2e-test
6060
annotations:
61-
openfeature.dev: "enabled"
61+
openfeature.dev/enabled: "true"
6262
openfeature.dev/featureflagconfiguration: "end-to-end-test"
6363
spec:
6464
serviceAccountName: open-feature-e2e-test-sa
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
./"$(dirname "${BASH_SOURCE[0]}")"/../simple-flag-evaluation.sh '{"value":true,"reason":"DEFAULT","variant":"on"}'
3+
./"$(dirname "${BASH_SOURCE[0]}")"/../simple-flag-evaluation.sh '{"value":true,"reason":"STATIC","variant":"on"}'

test/e2e/tests/002.crd-configuration-reconciliation.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
}
2222
EOF
2323

24-
./"$(dirname "${BASH_SOURCE[0]}")"/../simple-flag-evaluation.sh '{"reason":"DEFAULT","variant":"off"}'
24+
./"$(dirname "${BASH_SOURCE[0]}")"/../simple-flag-evaluation.sh '{"reason":"STATIC","variant":"off"}'
2525
EXIT_CODE=$?
2626

2727
kubectl -n open-feature-operator-system apply -f ./test/e2e/e2e.yml > /dev/null # reset state quietly

webhooks/pod_webhook.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,26 @@ func (m *PodMutator) Handle(ctx context.Context, req admission.Request) admissio
6161
}
6262

6363
// Check enablement
64+
enabled := false
6465
val, ok := pod.GetAnnotations()["openfeature.dev"]
6566
if ok {
66-
if val != "enabled" {
67-
m.Log.V(2).Info("openfeature.dev Annotation is not enabled")
68-
return admission.Allowed("openfeature is disabled")
67+
m.Log.V(1).Info("DEPRECATED: The openfeature.dev annotation has been superseded by the openfeature.dev/enabled annotation. " +
68+
"Docs: https://github.com/open-feature/open-feature-operator/blob/main/docs/annotations.md")
69+
if val == "enabled" {
70+
enabled = true
6971
}
7072
}
73+
val, ok = pod.GetAnnotations()["openfeature.dev/enabled"]
74+
if ok {
75+
if val == "true" {
76+
enabled = true
77+
}
78+
}
79+
80+
if !enabled {
81+
m.Log.V(2).Info(`openfeature.dev/enabled annotation is not set to "true"`)
82+
return admission.Allowed("OpenFeature is disabled")
83+
}
7184

7285
// Check configuration
7386
val, ok = pod.GetAnnotations()["openfeature.dev/featureflagconfiguration"]

0 commit comments

Comments
 (0)