Skip to content

Commit 089ab3c

Browse files
authored
fix: mount dirs not files (#326)
Signed-off-by: Todd Baert <[email protected]>
1 parent 256894f commit 089ab3c

8 files changed

+32
-24
lines changed

apis/core/v1alpha1/featureflagconfiguration_types.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,17 @@ func GenerateFfConfigMap(name string, namespace string, references []metav1.Owne
128128
OwnerReferences: references,
129129
},
130130
Data: map[string]string{
131-
FeatureFlagConfigurationConfigMapDataKeyName(namespace, name): spec.FeatureFlagSpec,
131+
FeatureFlagConfigurationConfigMapKey(namespace, name): spec.FeatureFlagSpec,
132132
},
133133
}
134134
}
135135

136-
func FeatureFlagConfigurationConfigMapDataKeyName(namespace, name string) string {
137-
return fmt.Sprintf("%s_%s.json", namespace, name)
136+
// unique string used to create unique volume mount and file name
137+
func FeatureFlagConfigurationId(namespace, name string) string {
138+
return fmt.Sprintf("%s_%s", namespace, name)
139+
}
140+
141+
// unique key (and filename) for configMap data
142+
func FeatureFlagConfigurationConfigMapKey(namespace, name string) string {
143+
return fmt.Sprintf("%s.json", FeatureFlagConfigurationId(namespace, name))
138144
}

apis/core/v1alpha1/flagsourceconfiguration_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type FlagSourceConfigurationSpec struct {
7272
// +optional
7373
SocketPath string `json:"socketPath"`
7474

75-
//SyncProviderArgs are string arguments passed to all sync providers, defined as key values separated by =
75+
// SyncProviderArgs are string arguments passed to all sync providers, defined as key values separated by =
7676
// +optional
7777
SyncProviderArgs []string `json:"syncProviderArgs"`
7878

apis/core/v1alpha2/flagsourceconfiguration_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type FlagSourceConfigurationSpec struct {
4040
// +optional
4141
SocketPath string `json:"socketPath"`
4242

43-
//SyncProviderArgs are string arguments passed to all sync providers, defined as key values separated by =
43+
// SyncProviderArgs are string arguments passed to all sync providers, defined as key values separated by =
4444
// +optional
4545
SyncProviderArgs []string `json:"syncProviderArgs"`
4646

controllers/featureflagconfiguration_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (r *FeatureFlagConfigurationReconciler) Reconcile(ctx context.Context, req
150150
// Update ConfigMap Spec
151151
r.Log.Info("Updating ConfigMap Spec " + cm.Name)
152152
cm.Data = map[string]string{
153-
corev1alpha1.FeatureFlagConfigurationConfigMapDataKeyName(cm.Namespace, cm.Name): ffconf.Spec.FeatureFlagSpec,
153+
corev1alpha1.FeatureFlagConfigurationConfigMapKey(cm.Namespace, cm.Name): ffconf.Spec.FeatureFlagSpec,
154154
}
155155
err := r.Client.Update(ctx, &cm)
156156
if err != nil {

webhooks/featureflagconfiguration_webhook_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ const (
1313
featureFlagConfigurationNamespace = "test-validate-featureflagconfiguration"
1414
)
1515

16-
var (
17-
featureFlagSpec = `
16+
var featureFlagSpec = `
1817
{
1918
"flags": {
2019
"new-welcome-message": {
@@ -28,7 +27,6 @@ var (
2827
}
2928
}
3029
`
31-
)
3230

3331
func setupValidateFeatureFlagConfigurationResources() {
3432
ns := &corev1.Namespace{}

webhooks/pod_webhook.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,10 @@ func podOwnerIsOwner(pod *corev1.Pod, cm corev1.ConfigMap) bool {
247247
}
248248

249249
func (m *PodMutator) enableClusterRoleBinding(ctx context.Context, pod *corev1.Pod) error {
250-
var serviceAccount = client.ObjectKey{Name: pod.Spec.ServiceAccountName,
251-
Namespace: pod.Namespace}
250+
serviceAccount := client.ObjectKey{
251+
Name: pod.Spec.ServiceAccountName,
252+
Namespace: pod.Namespace,
253+
}
252254
if pod.Spec.ServiceAccountName == "" {
253255
serviceAccount.Name = "default"
254256
}
@@ -266,7 +268,7 @@ func (m *PodMutator) enableClusterRoleBinding(ctx context.Context, pod *corev1.P
266268
m.Log.V(1).Info(fmt.Sprintf("ClusterRoleBinding not found: %s", clusterRoleBindingName))
267269
return err
268270
}
269-
var found = false
271+
found := false
270272
for _, subject := range crb.Subjects {
271273
if subject.Kind == "ServiceAccount" && subject.Name == serviceAccount.Name && subject.Namespace == serviceAccount.Namespace {
272274
m.Log.V(1).Info(fmt.Sprintf("ClusterRoleBinding already exists for service account: %s/%s", serviceAccount.Namespace, serviceAccount.Name))
@@ -385,7 +387,9 @@ func (m *PodMutator) injectSidecar(
385387
commandSequence = append(
386388
commandSequence,
387389
"--uri",
388-
fmt.Sprintf("file:%s", fileSyncMountPath(featureFlag)),
390+
fmt.Sprintf("file:%s/%s",
391+
fileSyncMountPath(featureFlag),
392+
corev1alpha1.FeatureFlagConfigurationConfigMapKey(featureFlag.Namespace, featureFlag.Name)),
389393
)
390394
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
391395
Name: featureFlag.Name,
@@ -398,9 +402,10 @@ func (m *PodMutator) injectSidecar(
398402
},
399403
})
400404
volumeMounts = append(volumeMounts, corev1.VolumeMount{
401-
Name: featureFlag.Name,
405+
Name: featureFlag.Name,
406+
// create a directory mount per featureFlag spec
407+
// file mounts will not work
402408
MountPath: fileSyncMountPath(featureFlag),
403-
SubPath: corev1alpha1.FeatureFlagConfigurationConfigMapDataKeyName(featureFlag.Namespace, featureFlag.Name),
404409
})
405410
default:
406411
err := fmt.Errorf(
@@ -475,9 +480,7 @@ func setSecurityContext() *corev1.SecurityContext {
475480
}
476481

477482
func fileSyncMountPath(featureFlag *corev1alpha1.FeatureFlagConfiguration) string {
478-
return fmt.Sprintf("%s/%s", rootFileSyncMountPath,
479-
corev1alpha1.FeatureFlagConfigurationConfigMapDataKeyName(featureFlag.Namespace, featureFlag.Name),
480-
)
483+
return fmt.Sprintf("%s/%s", rootFileSyncMountPath, corev1alpha1.FeatureFlagConfigurationId(featureFlag.Namespace, featureFlag.Name))
481484
}
482485

483486
func OpenFeatureEnabledAnnotationIndex(o client.Object) []string {

webhooks/pod_webhook_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ func podMutationWebhookCleanup() {
167167
}
168168

169169
var _ = Describe("pod mutation webhook", func() {
170-
171170
It("should backfill role binding subjects when annotated pods already exist in the cluster", func() {
172171
// this integration test confirms the proper execution of the podMutator.BackfillPermissions method
173172
// this method is responsible for backfilling the subjects of the open-feature-operator-flagd-kubernetes-sync
@@ -456,7 +455,7 @@ var _ = Describe("pod mutation webhook", func() {
456455
Expect(pod.Spec.Containers[1].Args).To(Equal([]string{
457456
"start",
458457
"--uri",
459-
"file:/etc/flagd/test-mutate-pod_test-feature-flag-configuration.json",
458+
"file:/etc/flagd/test-mutate-pod_test-feature-flag-configuration/test-mutate-pod_test-feature-flag-configuration.json",
460459
"--sync-provider-args",
461460
"key=value",
462461
"--sync-provider-args",

webhooks/suite_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ import (
3232
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
3333
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
3434

35-
var cfg *rest.Config
36-
var k8sClient client.Client
37-
var testEnv *envtest.Environment
38-
var testCtx, testCancel = context.WithCancel(context.Background())
35+
var (
36+
cfg *rest.Config
37+
k8sClient client.Client
38+
testEnv *envtest.Environment
39+
testCtx, testCancel = context.WithCancel(context.Background())
40+
)
3941

4042
const (
4143
podMutatingWebhookPath = "/mutate-v1-pod"

0 commit comments

Comments
 (0)