Skip to content

Commit

Permalink
fix: gave configmaps volume mounts a subpath to allow for multiple mo…
Browse files Browse the repository at this point in the history
…unts (#321)

Signed-off-by: Skye Gill <gill.skye95@gmail.com>
  • Loading branch information
skyerus authored Jan 27, 2023
1 parent 7cba7e1 commit 2ec454c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions webhooks/pod_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
FlagDImagePullPolicy corev1.PullPolicy = "Always"
clusterRoleBindingName string = "open-feature-operator-flagd-kubernetes-sync"
flagdMetricPortEnvVar string = "FLAGD_METRICS_PORT"
fileSyncMountPath string = "/etc/flagd/"
rootFileSyncMountPath string = "/etc/flagd"
OpenFeatureEnabledAnnotationPath = "metadata.annotations.openfeature.dev/enabled"
)

Expand Down Expand Up @@ -385,7 +385,7 @@ func (m *PodMutator) injectSidecar(
commandSequence = append(
commandSequence,
"--uri",
fmt.Sprintf("file:%s%s.json", fileSyncMountPath, featureFlag.Name),
fmt.Sprintf("file:%s", fileSyncMountPath(featureFlag)),
)
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
Name: featureFlag.Name,
Expand All @@ -399,7 +399,8 @@ func (m *PodMutator) injectSidecar(
})
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: featureFlag.Name,
MountPath: fileSyncMountPath,
MountPath: fileSyncMountPath(featureFlag),
SubPath: fileSyncFileName(featureFlag),
})
default:
err := fmt.Errorf(
Expand Down Expand Up @@ -473,6 +474,14 @@ 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)
}

func OpenFeatureEnabledAnnotationIndex(o client.Object) []string {
pod := o.(*corev1.Pod)
if pod.ObjectMeta.Annotations == nil {
Expand Down

0 comments on commit 2ec454c

Please sign in to comment.