Skip to content

Commit

Permalink
fix: uniqueness of featureflagconfiguration file path (#323)
Browse files Browse the repository at this point in the history
Signed-off-by: Skye Gill <gill.skye95@gmail.com>
  • Loading branch information
skyerus authored Jan 27, 2023
1 parent 2ec454c commit 2b10945
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
6 changes: 5 additions & 1 deletion apis/core/v1alpha1/featureflagconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ func GenerateFfConfigMap(name string, namespace string, references []metav1.Owne
OwnerReferences: references,
},
Data: map[string]string{
fmt.Sprintf("%s.json", name): spec.FeatureFlagSpec,
FeatureFlagConfigurationConfigMapDataKeyName(namespace, name): spec.FeatureFlagSpec,
},
}
}

func FeatureFlagConfigurationConfigMapDataKeyName(namespace, name string) string {
return fmt.Sprintf("%s_%s.json", namespace, name)
}
3 changes: 1 addition & 2 deletions controllers/featureflagconfiguration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controllers

import (
"context"
"fmt"
"time"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -151,7 +150,7 @@ func (r *FeatureFlagConfigurationReconciler) Reconcile(ctx context.Context, req
// Update ConfigMap Spec
r.Log.Info("Updating ConfigMap Spec " + cm.Name)
cm.Data = map[string]string{
fmt.Sprintf("%s.json", cm.Name): ffconf.Spec.FeatureFlagSpec,
corev1alpha1.FeatureFlagConfigurationConfigMapDataKeyName(cm.Namespace, cm.Name): ffconf.Spec.FeatureFlagSpec,
}
err := r.Client.Update(ctx, &cm)
if err != nil {
Expand Down
10 changes: 4 additions & 6 deletions webhooks/pod_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (m *PodMutator) injectSidecar(
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: featureFlag.Name,
MountPath: fileSyncMountPath(featureFlag),
SubPath: fileSyncFileName(featureFlag),
SubPath: corev1alpha1.FeatureFlagConfigurationConfigMapDataKeyName(featureFlag.Namespace, featureFlag.Name),
})
default:
err := fmt.Errorf(
Expand Down Expand Up @@ -475,11 +475,9 @@ func setSecurityContext() *corev1.SecurityContext {
}

func fileSyncMountPath(featureFlag *corev1alpha1.FeatureFlagConfiguration) string {
return fmt.Sprintf("%s/%s", rootFileSyncMountPath, fileSyncFileName(featureFlag))
}

func fileSyncFileName(featureFlag *corev1alpha1.FeatureFlagConfiguration) string {
return fmt.Sprintf("%s.json", featureFlag.Name)
return fmt.Sprintf("%s/%s", rootFileSyncMountPath,
corev1alpha1.FeatureFlagConfigurationConfigMapDataKeyName(featureFlag.Namespace, featureFlag.Name),
)
}

func OpenFeatureEnabledAnnotationIndex(o client.Object) []string {
Expand Down
4 changes: 2 additions & 2 deletions webhooks/pod_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ var _ = Describe("pod mutation webhook", func() {
}))
Expect(len(cm.OwnerReferences)).To(Equal(2))
Expect(cm.Data).To(Equal(map[string]string{
fmt.Sprintf("%s.json", featureFlagConfigurationName): ffConfig.Spec.FeatureFlagSpec,
fmt.Sprintf("%s_%s.json", mutatePodNamespace, featureFlagConfigurationName): ffConfig.Spec.FeatureFlagSpec,
}))

podMutationWebhookCleanup()
Expand Down Expand Up @@ -456,7 +456,7 @@ var _ = Describe("pod mutation webhook", func() {
Expect(pod.Spec.Containers[1].Args).To(Equal([]string{
"start",
"--uri",
"file:/etc/flagd/test-feature-flag-configuration.json",
"file:/etc/flagd/test-mutate-pod_test-feature-flag-configuration.json",
"--sync-provider-args",
"key=value",
"--sync-provider-args",
Expand Down

0 comments on commit 2b10945

Please sign in to comment.