Skip to content

Commit eec16af

Browse files
fix: removed duplicate config map generation, resolve permissions issue (#305)
Signed-off-by: James Milligan <[email protected]>
1 parent 5deff60 commit eec16af

File tree

6 files changed

+33
-57
lines changed

6 files changed

+33
-57
lines changed

chart/open-feature-operator/templates/rendered.yaml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,14 @@ spec:
581581
listKind: FlagSourceConfigurationList
582582
plural: flagsourceconfigurations
583583
shortNames:
584-
- fdc
584+
- fsc
585585
singular: flagsourceconfiguration
586586
scope: Namespaced
587587
versions:
588588
- name: v1alpha1
589589
schema:
590590
openAPIV3Schema:
591-
description: FlagSourceConfiguration is the Schema for the flagsourceconfigurations
591+
description: FlagSourceConfiguration is the Schema for the FlagSourceConfigurations
592592
API
593593
properties:
594594
apiVersion:
@@ -604,7 +604,8 @@ spec:
604604
metadata:
605605
type: object
606606
spec:
607-
description: FlagSourceConfigurationSpec defines the desired state of FlagSourceConfiguration
607+
description: FlagSourceConfigurationSpec defines the desired state of
608+
FlagSourceConfiguration
608609
properties:
609610
evaluator:
610611
description: Evaluator sets an evaluator, defaults to 'json'
@@ -615,11 +616,11 @@ spec:
615616
type: string
616617
metricsPort:
617618
description: MetricsPort defines the port to serve metrics on, defaults
618-
to 8013
619+
to 8014
619620
format: int32
620621
type: integer
621622
port:
622-
description: Port defines the port to listen on, defaults to 8014
623+
description: Port defines the port to listen on, defaults to 8013
623624
format: int32
624625
type: integer
625626
socketPath:
@@ -636,7 +637,8 @@ spec:
636637
type: string
637638
type: object
638639
status:
639-
description: FlagSourceConfigurationStatus defines the observed state of FlagSourceConfiguration
640+
description: FlagSourceConfigurationStatus defines the observed state
641+
of FlagSourceConfiguration
640642
type: object
641643
type: object
642644
served: true
@@ -646,7 +648,7 @@ spec:
646648
- name: v1alpha2
647649
schema:
648650
openAPIV3Schema:
649-
description: FlagSourceConfiguration is the Schema for the flagsourceconfigurations
651+
description: FlagSourceConfiguration is the Schema for the FlagSourceConfigurations
650652
API
651653
properties:
652654
apiVersion:
@@ -662,14 +664,15 @@ spec:
662664
metadata:
663665
type: object
664666
spec:
665-
description: FlagSourceConfigurationSpec defines the desired state of FlagSourceConfiguration
667+
description: FlagSourceConfigurationSpec defines the desired state of
668+
FlagSourceConfiguration
666669
properties:
667670
evaluator:
668671
description: Evaluator sets an evaluator, defaults to 'json'
669672
type: string
670673
image:
671-
description: Image allows for the flagd image to be overridden, defaults
672-
to 'ghcr.io/open-feature/flagd'
674+
description: Image allows for the sidecar image to be overridden,
675+
defaults to 'ghcr.io/open-feature/flagd'
673676
type: string
674677
metricsPort:
675678
description: MetricsPort defines the port to serve metrics on, defaults
@@ -690,11 +693,13 @@ spec:
690693
type: string
691694
type: array
692695
tag:
693-
description: Tag to be appended to the flagd image, defaults to 'main'
696+
description: Tag to be appended to the sidecar image, defaults to
697+
'main'
694698
type: string
695699
type: object
696700
status:
697-
description: FlagSourceConfigurationStatus defines the observed state of FlagSourceConfiguration
701+
description: FlagSourceConfigurationStatus defines the observed state
702+
of FlagSourceConfiguration
698703
type: object
699704
type: object
700705
served: true
@@ -1019,7 +1024,7 @@ spec:
10191024
- /manager
10201025
env:
10211026
- name: FLAGD_VERSION
1022-
value: v0.2.7
1027+
value: v0.3.1
10231028
image: ghcr.io/open-feature/open-feature-operator:main
10241029
imagePullPolicy: IfNotPresent
10251030
livenessProbe:
@@ -1156,4 +1161,4 @@ webhooks:
11561161
- UPDATE
11571162
resources:
11581163
- featureflagconfigurations
1159-
sideEffects: None
1164+
sideEffects: None

config/crd/bases/core.openfeature.dev_flagsourceconfigurations.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spec:
1313
listKind: FlagSourceConfigurationList
1414
plural: flagsourceconfigurations
1515
shortNames:
16-
- fdc
16+
- fsc
1717
singular: flagsourceconfiguration
1818
scope: Namespaced
1919
versions:

config/rbac/role.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rules:
4040
- apiGroups:
4141
- core.openfeature.dev
4242
resources:
43-
- FlagSourceConfigurations
43+
- featureflagconfigurations
4444
verbs:
4545
- create
4646
- delete
@@ -52,21 +52,21 @@ rules:
5252
- apiGroups:
5353
- core.openfeature.dev
5454
resources:
55-
- FlagSourceConfigurations/finalizers
55+
- featureflagconfigurations/finalizers
5656
verbs:
5757
- update
5858
- apiGroups:
5959
- core.openfeature.dev
6060
resources:
61-
- FlagSourceConfigurations/status
61+
- featureflagconfigurations/status
6262
verbs:
6363
- get
6464
- patch
6565
- update
6666
- apiGroups:
6767
- core.openfeature.dev
6868
resources:
69-
- featureflagconfigurations
69+
- flagsourceconfigurations
7070
verbs:
7171
- create
7272
- delete
@@ -78,13 +78,13 @@ rules:
7878
- apiGroups:
7979
- core.openfeature.dev
8080
resources:
81-
- featureflagconfigurations/finalizers
81+
- flagsourceconfigurations/finalizers
8282
verbs:
8383
- update
8484
- apiGroups:
8585
- core.openfeature.dev
8686
resources:
87-
- featureflagconfigurations/status
87+
- flagsourceconfigurations/status
8888
verbs:
8989
- get
9090
- patch

controllers/featureflagconfiguration_controller.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/open-feature/open-feature-operator/pkg/utils"
2626
corev1 "k8s.io/api/core/v1"
2727
"k8s.io/apimachinery/pkg/api/errors"
28-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2928
"k8s.io/client-go/tools/record"
3029
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3130

@@ -126,13 +125,11 @@ func (r *FeatureFlagConfigurationReconciler) Reconcile(ctx context.Context, req
126125
return r.finishReconcile(err, false)
127126
}
128127

129-
cmExists := false
130128
// Get list of configmaps with annotation
131129
for _, cm := range configMapList.Items {
132130
val, ok := cm.GetAnnotations()["openfeature.dev/featureflagconfiguration"]
133131
if ok && val == ffconf.Name {
134132
ffConfigMapList = append(ffConfigMapList, cm)
135-
cmExists = true
136133
}
137134
}
138135

@@ -162,32 +159,6 @@ func (r *FeatureFlagConfigurationReconciler) Reconcile(ctx context.Context, req
162159
}
163160
}
164161

165-
if !cmExists {
166-
ffOwnerRefs := []metav1.OwnerReference{
167-
corev1alpha1.GetFfReference(ffconf),
168-
}
169-
cm := corev1alpha1.GenerateFfConfigMap(ffconf.Name, ffconf.Namespace, ffOwnerRefs, ffconf.Spec)
170-
171-
podList := &corev1.PodList{}
172-
if err := r.List(ctx, podList); err != nil {
173-
return r.finishReconcile(err, false)
174-
}
175-
for _, pod := range podList.Items {
176-
val, ok := pod.GetAnnotations()["openfeature.dev/featureflagconfiguration"]
177-
if ok && val == ffconf.Name {
178-
reference := pod.OwnerReferences[0]
179-
reference.Controller = utils.FalseVal()
180-
cm.OwnerReferences = append(cm.OwnerReferences, reference)
181-
}
182-
}
183-
// Create ConfigMap only if there is a pod which uses it
184-
if len(cm.OwnerReferences) > 1 {
185-
err := r.Client.Create(ctx, &cm)
186-
return r.finishReconcile(err, true)
187-
}
188-
189-
}
190-
191162
return r.finishReconcile(nil, false)
192163
}
193164

controllers/flagdconfiguration_controller.go renamed to controllers/flagsourceconfiguration_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ type FlagSourceConfigurationReconciler struct {
3333
Scheme *runtime.Scheme
3434
}
3535

36-
//+kubebuilder:rbac:groups=core.openfeature.dev,resources=FlagSourceConfigurations,verbs=get;list;watch;create;update;patch;delete
37-
//+kubebuilder:rbac:groups=core.openfeature.dev,resources=FlagSourceConfigurations/status,verbs=get;update;patch
38-
//+kubebuilder:rbac:groups=core.openfeature.dev,resources=FlagSourceConfigurations/finalizers,verbs=update
36+
//+kubebuilder:rbac:groups=core.openfeature.dev,resources=flagsourceconfigurations,verbs=get;list;watch;create;update;patch;delete
37+
//+kubebuilder:rbac:groups=core.openfeature.dev,resources=flagsourceconfigurations/status,verbs=get;update;patch
38+
//+kubebuilder:rbac:groups=core.openfeature.dev,resources=flagsourceconfigurations/finalizers,verbs=update
3939

4040
// Reconcile is part of the main kubernetes reconciliation loop which aims to
4141
// move the current state of the cluster closer to the desired state.

webhooks/pod_webhook.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (m *PodMutator) Handle(ctx context.Context, req admission.Request) admissio
138138
}
139139

140140
// merge any provided flagd specs
141-
flagdConfigSpec := corev1alpha1.NewFlagSourceConfigurationSpec()
141+
flagSourceConfigurationSpec := corev1alpha1.NewFlagSourceConfigurationSpec()
142142
for _, fcName := range fcNames {
143143
ns, name := parseAnnotation(fcName, req.Namespace)
144144
if err != nil {
@@ -150,7 +150,7 @@ func (m *PodMutator) Handle(ctx context.Context, req admission.Request) admissio
150150
m.Log.V(1).Info(fmt.Sprintf("FlagSourceConfiguration could not be found for %s", fcName))
151151
return admission.Errored(http.StatusBadRequest, err)
152152
}
153-
flagdConfigSpec.Merge(&fc.Spec)
153+
flagSourceConfigurationSpec.Merge(&fc.Spec)
154154
}
155155

156156
ffConfigs := []*corev1alpha1.FeatureFlagConfiguration{}
@@ -166,7 +166,7 @@ func (m *PodMutator) Handle(ctx context.Context, req admission.Request) admissio
166166
m.Log.V(1).Info(fmt.Sprintf("FeatureFlagConfiguration could not be found for %s", ffName))
167167
return admission.Errored(http.StatusBadRequest, err)
168168
}
169-
if ff.Spec.SyncProvider != nil && !ff.Spec.SyncProvider.IsFilepath() {
169+
if ff.Spec.SyncProvider != nil && !ff.Spec.SyncProvider.IsKubernetes() {
170170
// Check for ConfigMap and create it if it doesn't exist (only required if sync provider isn't kubernetes)
171171
cm := corev1.ConfigMap{}
172172
if err := m.Client.Get(ctx, client.ObjectKey{Name: name, Namespace: req.Namespace}, &cm); errors.IsNotFound(err) {
@@ -192,7 +192,7 @@ func (m *PodMutator) Handle(ctx context.Context, req admission.Request) admissio
192192
ffConfigs = append(ffConfigs, &ff)
193193
}
194194

195-
marshaledPod, err := m.injectSidecar(pod, flagdConfigSpec, ffConfigs)
195+
marshaledPod, err := m.injectSidecar(pod, flagSourceConfigurationSpec, ffConfigs)
196196
if err != nil {
197197
return admission.Errored(http.StatusInternalServerError, err)
198198
}

0 commit comments

Comments
 (0)