@@ -166,10 +166,22 @@ static String getServerName(@Nullable V1Pod pod) {
166166 .orElse (null );
167167 }
168168
169+
169170 private static String getServerName (@ Nonnull Map <String ,String > labels ) {
170171 return labels .get (SERVERNAME_LABEL );
171172 }
172173
174+ private static V1SecurityContext getEffectiveSecurityContext (V1PodSecurityContext ctx ) {
175+ return new V1SecurityContext ()
176+ .runAsUser (ctx .getRunAsUser ())
177+ .runAsGroup (ctx .getRunAsGroup ())
178+ .runAsNonRoot (ctx .getRunAsNonRoot ())
179+ .seccompProfile (ctx .getSeccompProfile ())
180+ .seLinuxOptions (ctx .getSeLinuxOptions ())
181+ .windowsOptions (ctx .getWindowsOptions ());
182+
183+ }
184+
173185 /**
174186 * get if pod is in ready state.
175187 * @param pod pod
@@ -575,7 +587,10 @@ EffectiveServerSpec getServerSpec() {
575587
576588 @ Override
577589 V1SecurityContext getInitContainerSecurityContext () {
578- return PodSecurityHelper .getDefaultContainerSecurityContext ();
590+ if (getPodSecurityContext ().equals (PodSecurityHelper .getDefaultPodSecurityContext ())) {
591+ return PodSecurityHelper .getDefaultContainerSecurityContext ();
592+ }
593+ return getEffectiveSecurityContext (getPodSecurityContext ());
579594 }
580595
581596 @ Override
@@ -880,7 +895,10 @@ protected List<String> getContainerCommand() {
880895
881896 @ Override
882897 V1SecurityContext getInitContainerSecurityContext () {
883- return PodSecurityHelper .getDefaultContainerSecurityContext ();
898+ if (getPodSecurityContext ().equals (PodSecurityHelper .getDefaultPodSecurityContext ())) {
899+ return PodSecurityHelper .getDefaultContainerSecurityContext ();
900+ }
901+ return getEffectiveSecurityContext (getPodSecurityContext ());
884902 }
885903
886904 @ Override
0 commit comments