Skip to content

Commit a288add

Browse files
authored
Merge pull request #1041 from oracle/specify-no-version-samples
Add operator readiness probe and ensure that operator will not be alive or ready if initialization fails
2 parents 628b816 + f39cfab commit a288add

File tree

7 files changed

+69
-15
lines changed

7 files changed

+69
-15
lines changed

docs/charts/index.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
apiVersion: v1
22
entries:
33
weblogic-operator:
4-
- created: 2019-04-04T14:48:45.073688-04:00
4+
- created: 2019-04-19T18:49:45.158227-04:00
55
description: Helm chart for configuring the WebLogic operator.
6-
digest: c505f999cd43fdf9cd7a52d8e2db47a96e22e68f5116e47fb6dafee0bb31fa0e
6+
digest: 83193bfdea8a9643428bc85cd154584bd80742d0f8c92b502039e939fd2884c4
77
name: weblogic-operator
88
urls:
99
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.2.tgz
1010
version: "2.2"
11-
- created: 2019-04-04T14:48:45.071125-04:00
11+
- created: 2019-04-19T18:49:45.156092-04:00
1212
description: Helm chart for configuring the WebLogic operator.
1313
digest: 391e23c0969ada5f0cd2a088ddc6f11f237f57521801ed3925db2149a8437a0d
1414
name: weblogic-operator
1515
urls:
1616
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.1.tgz
1717
version: "2.1"
18-
- created: 2019-04-04T14:48:45.06358-04:00
18+
- created: 2019-04-19T18:49:45.153902-04:00
1919
description: Helm chart for configuring the WebLogic operator.
2020
digest: 298acda78ab73db6b7ba6f2752311bfa40c65874e03fb196b70976192211c1a5
2121
name: weblogic-operator
2222
urls:
2323
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.0.1.tgz
2424
version: 2.0.1
25-
generated: 2019-04-04T14:48:45.054609-04:00
25+
generated: 2019-04-19T18:49:45.149858-04:00

docs/charts/weblogic-operator-2.2.tgz

14 Bytes
Binary file not shown.

kubernetes/charts/weblogic-operator/templates/_operator-dep.tpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ spec:
6666
command:
6767
- "bash"
6868
- "/operator/livenessProbe.sh"
69-
initialDelaySeconds: 120
69+
initialDelaySeconds: 20
7070
periodSeconds: 5
71+
readinessProbe:
72+
exec:
73+
command:
74+
- "bash"
75+
- "/operator/readinessProbe.sh"
76+
initialDelaySeconds: 2
77+
periodSeconds: 10
7178
{{- if .elkIntegrationEnabled }}
7279
- name: "logstash"
7380
image: {{ .logStashImage | quote }}

kubernetes/src/test/java/oracle/kubernetes/operator/create/CreateOperatorGeneratedFilesTestBase.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,22 @@ protected ExtensionsV1beta1Deployment getExpectedWeblogicOperatorDeployment() {
232232
.readOnly(true))
233233
.livenessProbe(
234234
newProbe()
235-
.initialDelaySeconds(120)
235+
.initialDelaySeconds(20)
236236
.periodSeconds(5)
237237
.exec(
238238
newExecAction()
239239
.addCommandItem("bash")
240240
.addCommandItem(
241-
"/operator/livenessProbe.sh"))))
241+
"/operator/livenessProbe.sh")))
242+
.readinessProbe(
243+
newProbe()
244+
.initialDelaySeconds(2)
245+
.periodSeconds(10)
246+
.exec(
247+
newExecAction()
248+
.addCommandItem("bash")
249+
.addCommandItem(
250+
"/operator/readinessProbe.sh"))))
242251
.addVolumesItem(
243252
newVolume()
244253
.name("weblogic-operator-cm-volume")

operator/src/main/java/oracle/kubernetes/operator/Main.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ public static void main(String[] args) {
174174
LOGGER.warning(MessageKeys.EXCEPTION, e);
175175
}
176176

177-
// start liveness thread
178-
startLivenessThread();
179-
180177
try {
181178
engine.getExecutor().execute(Main::begin);
182179

@@ -226,6 +223,12 @@ private static void completeBegin() {
226223
.scheduleWithFixedDelay(
227224
recheckDomains(), recheckInterval, recheckInterval, TimeUnit.SECONDS);
228225

226+
// Wait until all other initialization is done before marking ready and
227+
// starting liveness thread
228+
229+
// mark ready and start liveness thread
230+
markReadyAndStartLivenessThread();
231+
229232
} catch (Throwable e) {
230233
LOGGER.warning(MessageKeys.EXCEPTION, e);
231234
}
@@ -429,10 +432,16 @@ private static void stopRestServer() {
429432
RestServer.destroy();
430433
}
431434

432-
private static void startLivenessThread() {
433-
LOGGER.info(MessageKeys.STARTING_LIVENESS_THREAD);
434-
// every five seconds we need to update the last modified time on the liveness file
435-
wrappedExecutorService.scheduleWithFixedDelay(new OperatorLiveness(), 5, 5, TimeUnit.SECONDS);
435+
private static void markReadyAndStartLivenessThread() {
436+
try {
437+
OperatorReady.create();
438+
439+
LOGGER.info(MessageKeys.STARTING_LIVENESS_THREAD);
440+
// every five seconds we need to update the last modified time on the liveness file
441+
wrappedExecutorService.scheduleWithFixedDelay(new OperatorLiveness(), 5, 5, TimeUnit.SECONDS);
442+
} catch (IOException io) {
443+
LOGGER.severe(MessageKeys.EXCEPTION, io);
444+
}
436445
}
437446

438447
private static final Semaphore shutdownSignal = new Semaphore(0);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
10+
/** This task creates the "readiness" indicator so that Kubernetes knows the Operator is ready */
11+
public class OperatorReady {
12+
13+
private static final File readinessFile = new File("/operator/.ready");
14+
15+
public static void create() throws IOException {
16+
if (!readinessFile.exists()) {
17+
readinessFile.createNewFile();
18+
}
19+
}
20+
}

src/scripts/readinessProbe.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
5+
if [ ! -f /operator/.ready ]; then
6+
exit 1;
7+
fi
8+
9+
exit 0

0 commit comments

Comments
 (0)