Skip to content

Commit a061556

Browse files
annotation path constant
Signed-off-by: James Milligan <[email protected]>
1 parent d5f6228 commit a061556

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ func main() {
136136
if err := mgr.GetFieldIndexer().IndexField(
137137
context.Background(),
138138
&corev1.Pod{},
139-
"metadata.annotations.openfeature.dev/enabled",
139+
webhooks.OpenFeatureEnabledAnnotationPath,
140140
webhooks.OpenFeatureEnabledAnnotationIndex,
141141
); err != nil {
142-
setupLog.Error(err, "unable to create indexer", "webhook", "metadata.annotations.openfeature.dev/enabled")
142+
setupLog.Error(err, "unable to create indexer", "webhook", webhooks.OpenFeatureEnabledAnnotationPath)
143143
os.Exit(1)
144144
}
145145

webhooks/pod_webhook.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import (
2626

2727
// we likely want these to be configurable, eventually
2828
const (
29-
FlagDImagePullPolicy corev1.PullPolicy = "Always"
30-
clusterRoleBindingName string = "open-feature-operator-flagd-kubernetes-sync"
31-
flagdMetricPortEnvVar string = "FLAGD_METRICS_PORT"
32-
fileSyncMountPath string = "/etc/flagd/"
29+
FlagDImagePullPolicy corev1.PullPolicy = "Always"
30+
clusterRoleBindingName string = "open-feature-operator-flagd-kubernetes-sync"
31+
flagdMetricPortEnvVar string = "FLAGD_METRICS_PORT"
32+
fileSyncMountPath string = "/etc/flagd/"
33+
OpenFeatureEnabledAnnotationPath = "metadata.annotations.openfeature.dev/enabled"
3334
)
3435

3536
var FlagDTag = "main"
@@ -56,10 +57,10 @@ func (m *PodMutator) BackfillPermissions(ctx context.Context) {
5657
for i := 0; i < 5; i++ {
5758
// fetch all pods with the "openfeature.dev/enabled" annotation set to "true"
5859
podList := &corev1.PodList{}
59-
err := m.Client.List(ctx, podList, client.MatchingFields{"metadata.annotations.openfeature.dev/enabled": "true"})
60+
err := m.Client.List(ctx, podList, client.MatchingFields{OpenFeatureEnabledAnnotationPath: "true"})
6061
if err != nil {
6162
if !goErr.Is(err, &cache.ErrCacheNotStarted{}) {
62-
m.Log.Error(err, "unable to list annotated pods", "webhook", "metadata.annotations.openfeature.dev/enabled")
63+
m.Log.Error(err, "unable to list annotated pods", "webhook", OpenFeatureEnabledAnnotationPath)
6364
return
6465
}
6566
time.Sleep(1 * time.Second)
@@ -74,7 +75,7 @@ func (m *PodMutator) BackfillPermissions(ctx context.Context) {
7475
err,
7576
fmt.Sprintf("unable backfill permissions for pod %s/%s", pod.Namespace, pod.Name),
7677
"webhook",
77-
"metadata.annotations.openfeature.dev/enabled",
78+
OpenFeatureEnabledAnnotationPath,
7879
)
7980
}
8081
}
@@ -84,7 +85,7 @@ func (m *PodMutator) BackfillPermissions(ctx context.Context) {
8485
m.Log.Error(
8586
err,
8687
"webhook",
87-
"metadata.annotations.openfeature.dev/enabled",
88+
OpenFeatureEnabledAnnotationPath,
8889
)
8990
}
9091

webhooks/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func run(ctx context.Context, cfg *rest.Config, scheme *runtime.Scheme, opts *en
4141
if err := mgr.GetFieldIndexer().IndexField(
4242
context.Background(),
4343
&corev1.Pod{},
44-
"metadata.annotations.openfeature.dev/enabled",
44+
OpenFeatureEnabledAnnotationPath,
4545
OpenFeatureEnabledAnnotationIndex,
4646
); err != nil {
4747
return err

0 commit comments

Comments
 (0)