@@ -94,7 +94,7 @@ func (m *PodMutator) InjectDecoder(d *admission.Decoder) error {
9494func CheckOwnerReference (pod * corev1.Pod , cm corev1.ConfigMap ) bool {
9595 for _ , cmOwner := range cm .OwnerReferences {
9696 for _ , podOwner := range pod .OwnerReferences {
97- if cmOwner == podOwner {
97+ if cmOwner . UID == podOwner . UID {
9898 return true
9999 }
100100 }
@@ -104,34 +104,37 @@ func CheckOwnerReference(pod *corev1.Pod, cm corev1.ConfigMap) bool {
104104
105105func (m * PodMutator ) CreateConfigMap (ctx context.Context , name string , namespace string , pod * corev1.Pod ) error {
106106 m .Log .V (1 ).Info (fmt .Sprintf ("Creating configmap %s" , name ))
107- reference := pod .OwnerReferences [0 ]
108- reference .Controller = m .falseVal ()
107+ references := []metav1.OwnerReference {
108+ pod .OwnerReferences [0 ],
109+ }
110+ references [0 ].Controller = m .falseVal ()
111+ ff := m .GetFeatureFlag (ctx , name , namespace )
112+ if ff .Name != "" {
113+ references = append (references , m .GetFfReference (& ff ))
114+ }
109115
110- spec := m .GetFeatureFlagSpec (ctx , name , namespace )
111116 cm := corev1.ConfigMap {
112117 ObjectMeta : metav1.ObjectMeta {
113118 Name : name ,
114119 Namespace : namespace ,
115120 Annotations : map [string ]string {
116121 "openfeature.dev/featureflagconfiguration" : name ,
117122 },
118- OwnerReferences : []metav1.OwnerReference {
119- reference ,
120- },
123+ OwnerReferences : references ,
121124 },
122125 Data : map [string ]string {
123- "config.yaml" : spec .FeatureFlagSpec ,
126+ "config.yaml" : ff . Spec .FeatureFlagSpec ,
124127 },
125128 }
126129 return m .Client .Create (ctx , & cm )
127130}
128131
129- func (m * PodMutator ) GetFeatureFlagSpec (ctx context.Context , name string , namespace string ) configv1alpha1.FeatureFlagConfigurationSpec {
132+ func (m * PodMutator ) GetFeatureFlag (ctx context.Context , name string , namespace string ) configv1alpha1.FeatureFlagConfiguration {
130133 ffConfig := configv1alpha1.FeatureFlagConfiguration {}
131134 if err := m .Client .Get (ctx , client.ObjectKey {Name : name , Namespace : namespace }, & ffConfig ); errors .IsNotFound (err ) {
132- return configv1alpha1.FeatureFlagConfigurationSpec {}
135+ return configv1alpha1.FeatureFlagConfiguration {}
133136 }
134- return ffConfig . Spec
137+ return ffConfig
135138}
136139
137140func (m * PodMutator ) InjectSidecar (pod * corev1.Pod , configMap string ) ([]byte , error ) {
@@ -163,6 +166,21 @@ func (m *PodMutator) InjectSidecar(pod *corev1.Pod, configMap string) ([]byte, e
163166 return json .Marshal (pod )
164167}
165168
169+ func (m * PodMutator ) GetFfReference (ff * configv1alpha1.FeatureFlagConfiguration ) metav1.OwnerReference {
170+ return metav1.OwnerReference {
171+ APIVersion : ff .APIVersion ,
172+ Kind : ff .Kind ,
173+ Name : ff .Name ,
174+ UID : ff .UID ,
175+ Controller : m .trueVal (),
176+ }
177+ }
178+
179+ func (m * PodMutator ) trueVal () * bool {
180+ b := true
181+ return & b
182+ }
183+
166184func (m * PodMutator ) falseVal () * bool {
167185 b := false
168186 return & b
0 commit comments