@@ -169,6 +169,17 @@ private static String getServerName(@Nonnull Map<String,String> labels) {
169
169
return labels .get (SERVERNAME_LABEL );
170
170
}
171
171
172
+ private static V1SecurityContext getEffectiveSecurityContext (V1PodSecurityContext ctx ) {
173
+ return new V1SecurityContext ()
174
+ .runAsUser (ctx .getRunAsUser ())
175
+ .runAsGroup (ctx .getRunAsGroup ())
176
+ .runAsNonRoot (ctx .getRunAsNonRoot ())
177
+ .seccompProfile (ctx .getSeccompProfile ())
178
+ .seLinuxOptions (ctx .getSeLinuxOptions ())
179
+ .windowsOptions (ctx .getWindowsOptions ());
180
+
181
+ }
182
+
172
183
/**
173
184
* get if pod is in ready state.
174
185
* @param pod pod
@@ -474,7 +485,10 @@ EffectiveServerSpec getServerSpec() {
474
485
475
486
@ Override
476
487
V1SecurityContext getInitContainerSecurityContext () {
477
- return PodSecurityHelper .getDefaultContainerSecurityContext ();
488
+ if (getPodSecurityContext ().equals (PodSecurityHelper .getDefaultPodSecurityContext ())) {
489
+ return PodSecurityHelper .getDefaultContainerSecurityContext ();
490
+ }
491
+ return getEffectiveSecurityContext (getPodSecurityContext ());
478
492
}
479
493
480
494
@ Override
@@ -757,7 +771,10 @@ protected List<String> getContainerCommand() {
757
771
758
772
@ Override
759
773
V1SecurityContext getInitContainerSecurityContext () {
760
- return PodSecurityHelper .getDefaultContainerSecurityContext ();
774
+ if (getPodSecurityContext ().equals (PodSecurityHelper .getDefaultPodSecurityContext ())) {
775
+ return PodSecurityHelper .getDefaultContainerSecurityContext ();
776
+ }
777
+ return getEffectiveSecurityContext (getPodSecurityContext ());
761
778
}
762
779
763
780
@ Override
0 commit comments