@@ -2100,9 +2100,9 @@ func (r *ValkeyReconciler) exporter(valkey *hyperv1.Valkey) corev1.Container {
21002100 Privileged : func (b bool ) * bool { return & b }(false ),
21012101 ReadOnlyRootFilesystem : func (b bool ) * bool { return & b }(true ),
21022102 RunAsNonRoot : func (b bool ) * bool { return & b }(true ),
2103- RunAsUser : func ( i int64 ) * int64 { return & i }( 1001 ),
2104- RunAsGroup : func ( i int64 ) * int64 { return & i }( 1001 ),
2105- SELinuxOptions : & corev1. SELinuxOptions {} ,
2103+ RunAsUser : getRunAsUser ( valkey ),
2104+ RunAsGroup : getRunAsGroup ( valkey ),
2105+ SELinuxOptions : getSELinuxOptions ( valkey ) ,
21062106 SeccompProfile : & corev1.SeccompProfile {
21072107 Type : "RuntimeDefault" ,
21082108 },
@@ -2254,6 +2254,54 @@ func getInitContainerResourceRequirements() corev1.ResourceRequirements {
22542254 }
22552255}
22562256
2257+ func getRunAsUser (valkey * hyperv1.Valkey ) * int64 {
2258+ if valkey .Spec .PlatformManagedSecurityContext {
2259+ return nil
2260+ }
2261+ // Default to 1001
2262+ return func (i int64 ) * int64 { return & i }(1001 )
2263+ }
2264+
2265+ func getRunAsGroup (valkey * hyperv1.Valkey ) * int64 {
2266+ if valkey .Spec .PlatformManagedSecurityContext {
2267+ return nil
2268+ }
2269+ // Default to 1001
2270+ return func (i int64 ) * int64 { return & i }(1001 )
2271+ }
2272+
2273+ func getFSGroup (valkey * hyperv1.Valkey ) * int64 {
2274+ if valkey .Spec .PlatformManagedSecurityContext {
2275+ return nil
2276+ }
2277+ // Default to 1001
2278+ return func (i int64 ) * int64 { return & i }(1001 )
2279+ }
2280+
2281+ func getFSGroupChangePolicy (valkey * hyperv1.Valkey ) * corev1.PodFSGroupChangePolicy {
2282+ if valkey .Spec .PlatformManagedSecurityContext {
2283+ return nil
2284+ }
2285+ // Default to Always
2286+ return func (s corev1.PodFSGroupChangePolicy ) * corev1.PodFSGroupChangePolicy { return & s }(corev1 .FSGroupChangeAlways )
2287+ }
2288+
2289+ func getSupplementalGroups (valkey * hyperv1.Valkey ) []int64 {
2290+ if valkey .Spec .PlatformManagedSecurityContext {
2291+ return nil
2292+ }
2293+ // Default to empty array
2294+ return []int64 {}
2295+ }
2296+
2297+ func getSELinuxOptions (valkey * hyperv1.Valkey ) * corev1.SELinuxOptions {
2298+ if valkey .Spec .PlatformManagedSecurityContext {
2299+ return nil
2300+ }
2301+ // Default to empty options
2302+ return & corev1.SELinuxOptions {}
2303+ }
2304+
22572305func (r * ValkeyReconciler ) upsertStatefulSet (ctx context.Context , valkey * hyperv1.Valkey ) error { // nolint:gocyclo
22582306 logger := log .FromContext (ctx )
22592307
@@ -2294,9 +2342,11 @@ func (r *ValkeyReconciler) upsertStatefulSet(ctx context.Context, valkey *hyperv
22942342 EnableServiceLinks : func (b bool ) * bool { return & b }(false ),
22952343 HostNetwork : false ,
22962344 SecurityContext : & corev1.PodSecurityContext {
2297- FSGroup : func (i int64 ) * int64 { return & i }(1001 ),
2298- FSGroupChangePolicy : func (s corev1.PodFSGroupChangePolicy ) * corev1.PodFSGroupChangePolicy { return & s }(corev1 .FSGroupChangeAlways ),
2299- SupplementalGroups : []int64 {},
2345+ RunAsUser : getRunAsUser (valkey ),
2346+ RunAsGroup : getRunAsGroup (valkey ),
2347+ FSGroup : getFSGroup (valkey ),
2348+ FSGroupChangePolicy : getFSGroupChangePolicy (valkey ),
2349+ SupplementalGroups : getSupplementalGroups (valkey ),
23002350 Sysctls : []corev1.Sysctl {},
23012351 },
23022352 AutomountServiceAccountToken : func (b bool ) * bool { return & b }(false ),
@@ -2330,9 +2380,9 @@ func (r *ValkeyReconciler) upsertStatefulSet(ctx context.Context, valkey *hyperv
23302380 Privileged : func (b bool ) * bool { return & b }(false ),
23312381 ReadOnlyRootFilesystem : func (b bool ) * bool { return & b }(true ),
23322382 RunAsNonRoot : func (b bool ) * bool { return & b }(true ),
2333- RunAsUser : func ( i int64 ) * int64 { return & i }( 1001 ),
2334- RunAsGroup : func ( i int64 ) * int64 { return & i }( 1001 ),
2335- SELinuxOptions : & corev1. SELinuxOptions {} ,
2383+ RunAsUser : getRunAsUser ( valkey ),
2384+ RunAsGroup : getRunAsGroup ( valkey ),
2385+ SELinuxOptions : getSELinuxOptions ( valkey ) ,
23362386 SeccompProfile : & corev1.SeccompProfile {
23372387 Type : "RuntimeDefault" ,
23382388 },
0 commit comments