@@ -22,6 +22,7 @@ import (
2222 "github.com/open-feature/open-feature-operator/pkg/utils"
2323 corev1 "k8s.io/api/core/v1"
2424 "k8s.io/apimachinery/pkg/api/errors"
25+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526 "k8s.io/client-go/tools/record"
2627 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2728 "time"
@@ -109,11 +110,13 @@ func (r *FeatureFlagConfigurationReconciler) Reconcile(ctx context.Context, req
109110 return r .finishReconcile (err , false )
110111 }
111112
113+ cmExists := false
112114 // Get list of configmaps with annotation
113115 for _ , cm := range configMapList .Items {
114116 val , ok := cm .GetAnnotations ()["openfeature.dev/featureflagconfiguration" ]
115117 if ok && val == ffconf .Name {
116118 ffConfigMapList = append (ffConfigMapList , cm )
119+ cmExists = true
117120 }
118121 }
119122
@@ -143,6 +146,32 @@ func (r *FeatureFlagConfigurationReconciler) Reconcile(ctx context.Context, req
143146 }
144147 }
145148
149+ if ! cmExists {
150+ ffOwnerRefs := []metav1.OwnerReference {
151+ utils .GetFfReference (ffconf ),
152+ }
153+ cm := utils .GenerateFfConfigMap (ffconf .Name , ffconf .Namespace , ffOwnerRefs , ffconf .Spec )
154+
155+ podList := & corev1.PodList {}
156+ if err := r .List (ctx , podList ); err != nil {
157+ return r .finishReconcile (err , false )
158+ }
159+ for _ , pod := range podList .Items {
160+ val , ok := pod .GetAnnotations ()["openfeature.dev/featureflagconfiguration" ]
161+ if ok && val == ffconf .Name {
162+ reference := pod .OwnerReferences [0 ]
163+ reference .Controller = utils .FalseVal ()
164+ cm .OwnerReferences = append (cm .OwnerReferences , reference )
165+ }
166+ }
167+ // Create ConfigMap only if there is a pod which uses it
168+ if len (cm .OwnerReferences ) > 1 {
169+ err := r .Client .Create (ctx , & cm )
170+ return r .finishReconcile (err , true )
171+ }
172+
173+ }
174+
146175 return r .finishReconcile (nil , false )
147176}
148177
0 commit comments