@@ -166,10 +166,22 @@ static String getServerName(@Nullable V1Pod pod) {
166
166
.orElse (null );
167
167
}
168
168
169
+
169
170
private static String getServerName (@ Nonnull Map <String ,String > labels ) {
170
171
return labels .get (SERVERNAME_LABEL );
171
172
}
172
173
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
+
173
185
/**
174
186
* get if pod is in ready state.
175
187
* @param pod pod
@@ -575,7 +587,10 @@ EffectiveServerSpec getServerSpec() {
575
587
576
588
@ Override
577
589
V1SecurityContext getInitContainerSecurityContext () {
578
- return PodSecurityHelper .getDefaultContainerSecurityContext ();
590
+ if (getPodSecurityContext ().equals (PodSecurityHelper .getDefaultPodSecurityContext ())) {
591
+ return PodSecurityHelper .getDefaultContainerSecurityContext ();
592
+ }
593
+ return getEffectiveSecurityContext (getPodSecurityContext ());
579
594
}
580
595
581
596
@ Override
@@ -880,7 +895,10 @@ protected List<String> getContainerCommand() {
880
895
881
896
@ Override
882
897
V1SecurityContext getInitContainerSecurityContext () {
883
- return PodSecurityHelper .getDefaultContainerSecurityContext ();
898
+ if (getPodSecurityContext ().equals (PodSecurityHelper .getDefaultPodSecurityContext ())) {
899
+ return PodSecurityHelper .getDefaultContainerSecurityContext ();
900
+ }
901
+ return getEffectiveSecurityContext (getPodSecurityContext ());
884
902
}
885
903
886
904
@ Override
0 commit comments