Skip to content

Commit bbd1a94

Browse files
committed
Merge branch 'owls-125094' into 'main'
Create default startup probe See merge request weblogic-cloud/weblogic-kubernetes-operator!4963
2 parents 4c2eab1 + e077a19 commit bbd1a94

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
@@ -742,11 +742,12 @@ private List<V1Volume> getVolumes(String domainUid) {
742742
@Override
743743
protected V1Container createPrimaryContainer() {
744744
final PodTuning podTuning = TuningParameters.getInstance().getPodTuning();
745+
Pair<V1Probe, V1Probe> probes = createLivenessAndStartupProbe(podTuning);
745746
V1Container v1Container = super.createPrimaryContainer()
746747
.ports(getContainerPorts())
747748
.lifecycle(createLifecycle())
748-
.livenessProbe(createLivenessProbe(podTuning))
749-
.startupProbe(getStartupProbe());
749+
.livenessProbe(probes.left())
750+
.startupProbe(probes.right());
750751

751752
if (!mockWls()) {
752753
v1Container.readinessProbe(createReadinessProbe(podTuning));
@@ -961,6 +962,11 @@ private V1Probe getReadinessProbe() {
961962
.map(V1ProbeBuilder::new).map(V1ProbeBuilder::build).orElse(new V1Probe());
962963
}
963964

965+
private Pair<V1Probe, V1Probe> createLivenessAndStartupProbe(PodTuning tuning) {
966+
V1Probe livenessProbe = createLivenessProbe(tuning);
967+
return new Pair<>(livenessProbe, createStartupProbe(livenessProbe, tuning));
968+
}
969+
964970
private V1Probe createLivenessProbe(PodTuning tuning) {
965971
V1Probe livenessProbe = getLivenessProbe();
966972

@@ -981,21 +987,12 @@ private V1Probe createLivenessProbe(PodTuning tuning) {
981987
livenessProbe.setSuccessThreshold(tuning.getLivenessProbeSuccessThreshold());
982988
}
983989

984-
try {
985-
V1HTTPGetAction httpGetAction = livenessProbe.getHttpGet();
986-
if (httpGetAction != null) {
987-
if (httpGetAction.getPort() == null) {
988-
httpGetAction.setPort(new IntOrString(getLocalAdminProtocolChannelPort()));
989-
}
990-
if (httpGetAction.getScheme() == null && isLocalAdminProtocolChannelSecure()) {
991-
httpGetAction.setScheme("HTTPS");
992-
}
993-
} else if (livenessProbe.getExec() == null
994-
&& livenessProbe.getTcpSocket() == null && livenessProbe.getGrpc() == null) {
995-
livenessProbe.setExec(execAction(LIVENESS_PROBE));
996-
}
997-
} catch (Exception e) {
998-
// do nothing
990+
V1HTTPGetAction httpGetAction = livenessProbe.getHttpGet();
991+
if (httpGetAction != null) {
992+
initializeHttpGetAction(httpGetAction);
993+
} else if (livenessProbe.getExec() == null
994+
&& livenessProbe.getTcpSocket() == null && livenessProbe.getGrpc() == null) {
995+
livenessProbe.setExec(execAction(LIVENESS_PROBE));
999996
}
1000997

1001998
return livenessProbe;
@@ -1006,8 +1003,52 @@ private V1Probe getLivenessProbe() {
10061003
.map(V1ProbeBuilder::new).map(V1ProbeBuilder::build).orElse(new V1Probe());
10071004
}
10081005

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

10131054
private boolean mockWls() {
@@ -1359,6 +1400,15 @@ private void restoreSecurityContextEmptyInitContainer(V1Pod recipe, V1Pod curren
13591400
}));
13601401
}
13611402

1403+
private void restoreNoStartupProbe(V1Pod recipe, V1Pod currentPod) {
1404+
Optional.ofNullable(recipe.getSpec().getContainers())
1405+
.ifPresent(containers ->
1406+
containers.forEach(container -> Optional.ofNullable(currentPod.getSpec().getContainers())
1407+
.flatMap(currentContainers -> currentContainers.stream()
1408+
.filter(cc -> cc.getName().equals(container.getName())).findFirst())
1409+
.ifPresent(match -> container.setStartupProbe(match.getStartupProbe()))));
1410+
}
1411+
13621412
private boolean canAdjustRecentOperatorMajorVersion3HashToMatch(V1Pod currentPod, String requiredHash) {
13631413
// start with list of adjustment methods
13641414
// generate stream of combinations
@@ -1374,7 +1424,8 @@ private boolean canAdjustRecentOperatorMajorVersion3HashToMatch(V1Pod currentPod
13741424
Pair.of("restoreFluentdVolume", this::restoreFluentdVolume),
13751425
Pair.of("restoreSecurityContext", this::restoreSecurityContext),
13761426
Pair.of("restoreSecurityContextEmpty", this::restoreSecurityContextEmpty),
1377-
Pair.of("restoreSecurityContextEmptyInitContainer", this::restoreSecurityContextEmptyInitContainer));
1427+
Pair.of("restoreSecurityContextEmptyInitContainer", this::restoreSecurityContextEmptyInitContainer),
1428+
Pair.of("restoreNoStartupProbe", this::restoreNoStartupProbe));
13781429
return Combinations.of(adjustments)
13791430
.map(adjustment -> adjustedHash(currentPod, adjustment))
13801431
.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
@@ -1568,6 +1568,13 @@ void whenPodCreated_livenessProbeHasLivenessCommand() {
15681568
contains("/weblogic-operator/scripts/livenessProbe.sh"));
15691569
}
15701570

1571+
@Test
1572+
void whenPodCreated_startupProbeHasLivenessCommand() {
1573+
assertThat(
1574+
getCreatedPodSpecContainer().getStartupProbe().getExec().getCommand(),
1575+
contains("/weblogic-operator/scripts/livenessProbe.sh"));
1576+
}
1577+
15711578
@Test
15721579
void whenPodCreated_livenessProbeHasDefinedTuning() {
15731580
assertThat(

0 commit comments

Comments
 (0)