Skip to content

Commit 942bb7e

Browse files
committed
Correct some issues with shutdown grace period
1 parent fdd797a commit 942bb7e

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

model/src/main/java/oracle/kubernetes/weblogic/domain/model/ServerPod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Shutdown getShutdown() {
146146
return this.shutdown;
147147
}
148148

149-
void setShutdown(String shutdownType, Integer timeoutSeconds, Boolean ignoreSessions) {
149+
void setShutdown(String shutdownType, Long timeoutSeconds, Boolean ignoreSessions) {
150150
this.shutdown
151151
.shutdownType(shutdownType)
152152
.timeoutSeconds(timeoutSeconds)

model/src/main/java/oracle/kubernetes/weblogic/domain/model/Shutdown.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
@Description("Shutdown describes the configuration for shutting down a server instance.")
1818
public class Shutdown {
19-
public static final Integer DEFAULT_TIMEOUT = 30;
19+
// Default timeout must stay 30 seconds to match Kubernetes default
20+
public static final Long DEFAULT_TIMEOUT = 30l;
2021
public static final Boolean DEFAULT_IGNORESESSIONS = Boolean.FALSE;
2122

2223
@Description(
@@ -27,7 +28,7 @@ public class Shutdown {
2728

2829
@Description(
2930
"For graceful shutdown only, number of seconds to wait before aborting in-flight work and shutting down the server. Not required. Defaults to 30 seconds.")
30-
private Integer timeoutSeconds;
31+
private Long timeoutSeconds;
3132

3233
@Description(
3334
"For graceful shutdown only, indicates to ignore pending HTTP sessions during in-flight work handling. Not required. Defaults to false.")
@@ -56,11 +57,11 @@ public Shutdown shutdownType(String shutdownType) {
5657
return this;
5758
}
5859

59-
public Integer getTimeoutSeconds() {
60+
public Long getTimeoutSeconds() {
6061
return Optional.ofNullable(timeoutSeconds).orElse(DEFAULT_TIMEOUT);
6162
}
6263

63-
public Shutdown timeoutSeconds(Integer timeoutSeconds) {
64+
public Shutdown timeoutSeconds(Long timeoutSeconds) {
6465
this.timeoutSeconds = timeoutSeconds;
6566
return this;
6667
}

model/src/test/java/oracle/kubernetes/weblogic/domain/model/DomainV2Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ public void whenDomain2ReadFromYaml_ShutdownIsReadFromSpec() throws IOException
11091109

11101110
Shutdown shutdown = domain.getSpec().getShutdown();
11111111
assertThat(shutdown.getShutdownType(), is("Graceful"));
1112-
assertThat(shutdown.getTimeoutSeconds(), is(45));
1112+
assertThat(shutdown.getTimeoutSeconds(), is(45l));
11131113
}
11141114

11151115
@Test
@@ -1118,7 +1118,7 @@ public void whenDomain2ReadFromYaml_ShutdownIsReadFromClusterSpec() throws IOExc
11181118

11191119
Shutdown shutdown = domain.getCluster("cluster2").getShutdown();
11201120
assertThat(shutdown.getShutdownType(), is("Graceful"));
1121-
assertThat(shutdown.getTimeoutSeconds(), is(45));
1121+
assertThat(shutdown.getTimeoutSeconds(), is(45l));
11221122
assertThat(shutdown.getIgnoreSessions(), is(true));
11231123
}
11241124

@@ -1128,7 +1128,7 @@ public void whenDomain2ReadFromYaml_ShutdownIsReadFromServerSpec() throws IOExce
11281128

11291129
Shutdown shutdown = domain.getServer("server2", "cluster2").getShutdown();
11301130
assertThat(shutdown.getShutdownType(), is("Graceful"));
1131-
assertThat(shutdown.getTimeoutSeconds(), is(60));
1131+
assertThat(shutdown.getTimeoutSeconds(), is(60l));
11321132
assertThat(shutdown.getIgnoreSessions(), is(false));
11331133
}
11341134

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
public class PodHelper {
3838
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
3939

40-
private static final int DEFAULT_ADDITIONAL_DELETE_TIME = 10;
40+
static final long DEFAULT_ADDITIONAL_DELETE_TIME = 10;
4141

4242
private PodHelper() {}
4343

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,18 +587,19 @@ V1Pod withNonHashedElements(V1Pod pod) {
587587
.filter(PodStepContext::isCustomerItem)
588588
.forEach(e -> metadata.putAnnotationsItem(e.getKey(), e.getValue()));
589589

590-
insertShutdownEnvironmentVariables(pod);
590+
updateForShutdown(pod);
591591
return pod;
592592
}
593593

594594
/**
595-
* Inserts into the pod the environment variables related to shutdown behavior.
595+
* Inserts into the pod the environment variables and other configuration related to shutdown
596+
* behavior.
596597
*
597598
* @param pod The pod
598599
*/
599-
final void insertShutdownEnvironmentVariables(V1Pod pod) {
600+
final void updateForShutdown(V1Pod pod) {
600601
String shutdownType = GRACEFUL_SHUTDOWNTYPE;
601-
int timeout = Shutdown.DEFAULT_TIMEOUT;
602+
Long timeout = Shutdown.DEFAULT_TIMEOUT;
602603
boolean ignoreSessions = Shutdown.DEFAULT_IGNORESESSIONS;
603604
String serverName = null;
604605
String clusterName = null;
@@ -633,6 +634,8 @@ final void insertShutdownEnvironmentVariables(V1Pod pod) {
633634
break;
634635
}
635636
}
637+
638+
pod.getSpec().terminationGracePeriodSeconds(timeout + PodHelper.DEFAULT_ADDITIONAL_DELETE_TIME);
636639
}
637640

638641
private static boolean isCustomerItem(Map.Entry<String, String> entry) {

0 commit comments

Comments
 (0)