Skip to content

Commit bbdaa8d

Browse files
committed
Merge branch 'owls-125094' into 'main'
Create default startup probe See merge request weblogic-cloud/weblogic-kubernetes-operator!4963 (cherry picked from commit bbd1a94) d92e8e1 Work in progress af9071a Create default startup probe
1 parent 35ddb0f commit bbdaa8d

File tree

4 files changed

+119
-21
lines changed

4 files changed

+119
-21
lines changed

operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,12 @@ private List<V1Volume> getVolumes(String domainUid) {
749749
@Override
750750
protected V1Container createPrimaryContainer() {
751751
final PodTuning podTuning = TuningParameters.getInstance().getPodTuning();
752+
Pair<V1Probe, V1Probe> probes = createLivenessAndStartupProbe(podTuning);
752753
V1Container v1Container = super.createPrimaryContainer()
753754
.ports(getContainerPorts())
754755
.lifecycle(createLifecycle())
755-
.livenessProbe(createLivenessProbe(podTuning))
756-
.startupProbe(getStartupProbe());
756+
.livenessProbe(probes.left())
757+
.startupProbe(probes.right());
757758

758759
if (!mockWls()) {
759760
v1Container.readinessProbe(createReadinessProbe(podTuning));
@@ -968,6 +969,11 @@ private V1Probe getReadinessProbe() {
968969
.map(V1ProbeBuilder::new).map(V1ProbeBuilder::build).orElse(new V1Probe());
969970
}
970971

972+
private Pair<V1Probe, V1Probe> createLivenessAndStartupProbe(PodTuning tuning) {
973+
V1Probe livenessProbe = createLivenessProbe(tuning);
974+
return new Pair<>(livenessProbe, createStartupProbe(livenessProbe, tuning));
975+
}
976+
971977
private V1Probe createLivenessProbe(PodTuning tuning) {
972978
V1Probe livenessProbe = getLivenessProbe();
973979

@@ -988,21 +994,12 @@ private V1Probe createLivenessProbe(PodTuning tuning) {
988994
livenessProbe.setSuccessThreshold(tuning.getLivenessProbeSuccessThreshold());
989995
}
990996

991-
try {
992-
V1HTTPGetAction httpGetAction = livenessProbe.getHttpGet();
993-
if (httpGetAction != null) {
994-
if (httpGetAction.getPort() == null) {
995-
httpGetAction.setPort(new IntOrString(getLocalAdminProtocolChannelPort()));
996-
}
997-
if (httpGetAction.getScheme() == null && isLocalAdminProtocolChannelSecure()) {
998-
httpGetAction.setScheme("HTTPS");
999-
}
1000-
} else if (livenessProbe.getExec() == null
1001-
&& livenessProbe.getTcpSocket() == null && livenessProbe.getGrpc() == null) {
1002-
livenessProbe.setExec(execAction(LIVENESS_PROBE));
1003-
}
1004-
} catch (Exception e) {
1005-
// do nothing
997+
V1HTTPGetAction httpGetAction = livenessProbe.getHttpGet();
998+
if (httpGetAction != null) {
999+
initializeHttpGetAction(httpGetAction);
1000+
} else if (livenessProbe.getExec() == null
1001+
&& livenessProbe.getTcpSocket() == null && livenessProbe.getGrpc() == null) {
1002+
livenessProbe.setExec(execAction(LIVENESS_PROBE));
10061003
}
10071004

10081005
return livenessProbe;
@@ -1013,8 +1010,52 @@ private V1Probe getLivenessProbe() {
10131010
.map(V1ProbeBuilder::new).map(V1ProbeBuilder::build).orElse(new V1Probe());
10141011
}
10151012

1013+
private V1Probe createStartupProbe(V1Probe livenessProbe, PodTuning tuning) {
1014+
V1Probe startupProbe = getStartupProbe();
1015+
1016+
if (startupProbe.getInitialDelaySeconds() == null && tuning.getStartupProbeInitialDelaySeconds() > 0) {
1017+
startupProbe.setInitialDelaySeconds(tuning.getStartupProbeInitialDelaySeconds());
1018+
}
1019+
if (startupProbe.getTimeoutSeconds() == null) {
1020+
startupProbe.setTimeoutSeconds(tuning.getStartupProbeTimeoutSeconds());
1021+
}
1022+
if (startupProbe.getPeriodSeconds() == null) {
1023+
startupProbe.setPeriodSeconds(tuning.getStartupProbePeriodSeconds());
1024+
}
1025+
if (startupProbe.getFailureThreshold() == null) {
1026+
startupProbe.setFailureThreshold(tuning.getStartupProbeFailureThreshold());
1027+
}
1028+
if (startupProbe.getSuccessThreshold() == null
1029+
&& tuning.getStartupProbeSuccessThreshold() != DEFAULT_SUCCESS_THRESHOLD) {
1030+
startupProbe.setSuccessThreshold(tuning.getStartupProbeSuccessThreshold());
1031+
}
1032+
1033+
V1HTTPGetAction httpGetAction = startupProbe.getHttpGet();
1034+
if (httpGetAction != null) {
1035+
initializeHttpGetAction(httpGetAction);
1036+
} else if (startupProbe.getExec() == null
1037+
&& startupProbe.getTcpSocket() == null && startupProbe.getGrpc() == null) {
1038+
startupProbe.setHttpGet(livenessProbe.getHttpGet());
1039+
startupProbe.setExec(livenessProbe.getExec());
1040+
startupProbe.setTcpSocket(livenessProbe.getTcpSocket());
1041+
startupProbe.setGrpc(livenessProbe.getGrpc());
1042+
}
1043+
1044+
return startupProbe;
1045+
}
1046+
10161047
private V1Probe getStartupProbe() {
1017-
return getServerSpec().getStartupProbe();
1048+
return Optional.ofNullable(getServerSpec().getStartupProbe())
1049+
.map(V1ProbeBuilder::new).map(V1ProbeBuilder::build).orElse(new V1Probe());
1050+
}
1051+
1052+
private void initializeHttpGetAction(@Nonnull V1HTTPGetAction httpGetAction) {
1053+
if (httpGetAction.getPort() == null) {
1054+
httpGetAction.setPort(new IntOrString(getLocalAdminProtocolChannelPort()));
1055+
}
1056+
if (httpGetAction.getScheme() == null && isLocalAdminProtocolChannelSecure()) {
1057+
httpGetAction.setScheme("HTTPS");
1058+
}
10181059
}
10191060

10201061
private boolean mockWls() {
@@ -1381,6 +1422,15 @@ private void restoreSecurityContextEmptyInitContainer(V1Pod recipe, V1Pod curren
13811422
}));
13821423
}
13831424

1425+
private void restoreNoStartupProbe(V1Pod recipe, V1Pod currentPod) {
1426+
Optional.ofNullable(recipe.getSpec().getContainers())
1427+
.ifPresent(containers ->
1428+
containers.forEach(container -> Optional.ofNullable(currentPod.getSpec().getContainers())
1429+
.flatMap(currentContainers -> currentContainers.stream()
1430+
.filter(cc -> cc.getName().equals(container.getName())).findFirst())
1431+
.ifPresent(match -> container.setStartupProbe(match.getStartupProbe()))));
1432+
}
1433+
13841434
private boolean canAdjustRecentOperatorMajorVersion3HashToMatch(V1Pod currentPod, String requiredHash) {
13851435
// start with list of adjustment methods
13861436
// generate stream of combinations
@@ -1396,7 +1446,8 @@ private boolean canAdjustRecentOperatorMajorVersion3HashToMatch(V1Pod currentPod
13961446
Pair.of("restoreFluentdVolume", this::restoreFluentdVolume),
13971447
Pair.of("restoreSecurityContext", this::restoreSecurityContext),
13981448
Pair.of("restoreSecurityContextEmpty", this::restoreSecurityContextEmpty),
1399-
Pair.of("restoreSecurityContextEmptyInitContainer", this::restoreSecurityContextEmptyInitContainer));
1449+
Pair.of("restoreSecurityContextEmptyInitContainer", this::restoreSecurityContextEmptyInitContainer),
1450+
Pair.of("restoreNoStartupProbe", this::restoreNoStartupProbe));
14001451
return Combinations.of(adjustments)
14011452
.map(adjustment -> adjustedHash(currentPod, adjustment))
14021453
.anyMatch(requiredHash::equals);

operator/src/main/java/oracle/kubernetes/operator/tuning/PodTuning.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.tuning;
@@ -27,4 +27,14 @@ public interface PodTuning {
2727
int getLivenessProbeSuccessThreshold();
2828

2929
int getLivenessProbeFailureThreshold();
30+
31+
int getStartupProbeInitialDelaySeconds();
32+
33+
int getStartupProbeTimeoutSeconds();
34+
35+
int getStartupProbePeriodSeconds();
36+
37+
int getStartupProbeSuccessThreshold();
38+
39+
int getStartupProbeFailureThreshold();
3040
}

operator/src/main/java/oracle/kubernetes/operator/tuning/TuningParameters.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.tuning;
@@ -56,6 +56,11 @@ public class TuningParameters {
5656
public static final String LIVENESS_PERIOD_SECONDS = "livenessProbePeriodSeconds";
5757
public static final String LIVENESS_SUCCESS_COUNT_THRESHOLD = "livenessProbeSuccessThreshold";
5858
public static final String LIVENESS_FAILURE_COUNT_THRESHOLD = "livenessProbeFailureThreshold";
59+
public static final String STARTUP_INITIAL_DELAY_SECONDS = "startupProbeInitialDelaySeconds";
60+
public static final String STARTUP_TIMEOUT_SECONDS = "startupProbeTimeoutSeconds";
61+
public static final String STARTUP_PERIOD_SECONDS = "startupProbePeriodSeconds";
62+
public static final String STARTUP_SUCCESS_COUNT_THRESHOLD = "startupProbeSuccessThreshold";
63+
public static final String STARTUP_FAILURE_COUNT_THRESHOLD = "startupProbeFailureThreshold";
5964

6065
public static final String INITIALIZATION_RETRY_DELAY_SECONDS = "initializationRetryDelaySeconds";
6166
public static final String UNCHANGED_COUNT_TO_DELAY_STATUS_RECHECK = "statusUpdateUnchangedCountToDelayStatusRecheck";
@@ -424,6 +429,31 @@ public int getLivenessProbeSuccessThreshold() {
424429
public int getLivenessProbeFailureThreshold() {
425430
return getParameter(LIVENESS_FAILURE_COUNT_THRESHOLD, 1);
426431
}
432+
433+
@Override
434+
public int getStartupProbeInitialDelaySeconds() {
435+
return getParameter(STARTUP_INITIAL_DELAY_SECONDS, 0);
436+
}
437+
438+
@Override
439+
public int getStartupProbeTimeoutSeconds() {
440+
return getParameter(STARTUP_TIMEOUT_SECONDS, 5);
441+
}
442+
443+
@Override
444+
public int getStartupProbePeriodSeconds() {
445+
return getParameter(STARTUP_PERIOD_SECONDS, 5);
446+
}
447+
448+
@Override
449+
public int getStartupProbeSuccessThreshold() {
450+
return getParameter(STARTUP_SUCCESS_COUNT_THRESHOLD, 1);
451+
}
452+
453+
@Override
454+
public int getStartupProbeFailureThreshold() {
455+
return getParameter(STARTUP_FAILURE_COUNT_THRESHOLD, 20);
456+
}
427457
}
428458

429459
private class FeatureGatesImpl implements FeatureGates {

operator/src/test/java/oracle/kubernetes/operator/helpers/PodHelperTestBase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,13 @@ void whenPodCreated_livenessProbeHasLivenessCommand() {
15501550
contains("/weblogic-operator/scripts/livenessProbe.sh"));
15511551
}
15521552

1553+
@Test
1554+
void whenPodCreated_startupProbeHasLivenessCommand() {
1555+
assertThat(
1556+
getCreatedPodSpecContainer().getStartupProbe().getExec().getCommand(),
1557+
contains("/weblogic-operator/scripts/livenessProbe.sh"));
1558+
}
1559+
15531560
@Test
15541561
void whenPodCreated_livenessProbeHasDefinedTuning() {
15551562
assertThat(

0 commit comments

Comments
 (0)