Skip to content

Commit 618794c

Browse files
committed
More work in progress
1 parent 4a69d40 commit 618794c

File tree

10 files changed

+281
-240
lines changed

10 files changed

+281
-240
lines changed

kubernetes/internal/domain-job-template.yaml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -208,37 +208,6 @@ data:
208208
209209
checkFileExists ${pyFile}
210210
211-
# Create a liveness probe script. It checks a WL server state file maintained by the node manager.
212-
# The script and 'EOF' on the following lines must not be indented!
213-
214-
scriptFile=${nmdir}/livenessProbe.sh
215-
216-
cat << EOF > $scriptFile
217-
#!/bin/bash
218-
219-
# Kubernetes periodically calls this liveness probe script to determine whether
220-
# the pod should be restarted. The script checks a WebLogic Server state file which
221-
# is updated by the node manager.
222-
223-
STATEFILE=${stateFile}
224-
225-
if [ \`jps -l | grep -c " weblogic.NodeManager"\` -eq 0 ]; then
226-
echo "Error: WebLogic NodeManager process not found."
227-
exit 1
228-
fi
229-
230-
if [ -f \${STATEFILE} ] && [ \`grep -c "FAILED_NOT_RESTARTABLE" \${STATEFILE}\` -eq 1 ]; then
231-
echo "Error: WebLogic Server FAILED_NOT_RESTARTABLE."
232-
exit 1
233-
fi
234-
235-
echo "Info: Probe check passed."
236-
exit 0
237-
EOF
238-
239-
checkFileExists ${scriptFile}
240-
chmod +x ${scriptFile}
241-
242211
}
243212
244213
# Function to create script for stopping a server

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ public interface KubernetesConstants {
2121
public static final String DOMAIN_PLURAL = "domains";
2222
public static final String DOMAIN_SINGULAR = "domain";
2323
public static final String DOMAIN_SHORT = "dom";
24+
25+
public static final String DOMAIN_CONFIG_MAP_NAME = "weblogic-domain-config-map";
2426

2527
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import oracle.kubernetes.operator.helpers.ClientHelper;
4040
import oracle.kubernetes.operator.helpers.ClientHolder;
4141
import oracle.kubernetes.operator.helpers.ConfigMapConsumer;
42+
import oracle.kubernetes.operator.helpers.ConfigMapHelper;
4243
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
4344
import oracle.kubernetes.operator.helpers.DomainPresenceInfo.ServerStartupInfo;
4445
import oracle.kubernetes.operator.helpers.HealthCheckHelper.KubernetesVersion;
@@ -205,7 +206,8 @@ public NextAction onSuccess(Packet packet, DomainList result, int statusCode,
205206
}
206207
});
207208

208-
Step initialize = CallBuilder.create().with($ -> {
209+
Step initialize = ConfigMapHelper.createScriptConfigMapStep(ns,
210+
CallBuilder.create().with($ -> {
209211
$.labelSelector = LabelConstants.DOMAINUID_LABEL
210212
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
211213
}).listPodAsync(ns, new ResponseStep<V1PodList>(
@@ -317,7 +319,7 @@ public NextAction onSuccess(Packet packet, V1PodList result, int statusCode,
317319
podWatchers.put(ns, createPodWatcher(ns, result != null ? result.getMetadata().getResourceVersion() : ""));
318320
return doNext(packet);
319321
}
320-
});
322+
}));
321323

322324
engine.createFiber().start(initialize, new Packet(), new CompletionCallback() {
323325
@Override

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,22 @@
66
import java.util.Objects;
77

88
import io.kubernetes.client.models.V1ObjectMeta;
9-
import oracle.kubernetes.weblogic.domain.v1.Domain;
109

1110
/**
1211
* Annotates pods, services with details about the Domain instance and checks these annotations.
1312
*
1413
*/
1514
public class AnnotationHelper {
1615

17-
private static final String DOMAIN_RESOURCE_VERSION = "weblogic.oracle/domain-resourceVersion";
16+
private static final String FORMAT_ANNOTATION = "weblogic.oracle/operator-formatVersion";
17+
private static final String FORMAT_VERSION = "1";
1818

1919
/**
20-
* Marks metadata object with an annotation saying that it was created for this domain and resource version
20+
* Marks metadata object with an annotation saying that it was created for this format version
2121
* @param meta Metadata object that will be included in a newly created resource, e.g. pod or service
22-
* @param domain The domain
2322
*/
24-
public static void annotateWithDomain(V1ObjectMeta meta, Domain domain) {
25-
String domainResourceVersion = domain.getMetadata().getResourceVersion();
26-
if (domainResourceVersion != null) {
27-
meta.putAnnotationsItem(DOMAIN_RESOURCE_VERSION, domainResourceVersion);
28-
}
23+
public static void annotateWithFormat(V1ObjectMeta meta) {
24+
meta.putAnnotationsItem(FORMAT_ANNOTATION, FORMAT_VERSION);
2925
}
3026

3127

@@ -43,14 +39,12 @@ public static void annotateForPrometheus(V1ObjectMeta meta, int httpPort) {
4339
}
4440

4541
/**
46-
* Check the metadata object for the presence of an annotation matching the domain and resource version.l
42+
* Check the metadata object for the presence of an annotation matching the expected format version.
4743
* @param meta The metadata object
48-
* @param domain The domain
49-
* @return true, if the metadata includes an annotation matching this domain
44+
* @return true, if the metadata includes an annotation matching the expected format version
5045
*/
51-
public static boolean checkDomainAnnotation(V1ObjectMeta meta, Domain domain) {
52-
String domainResourceVersion = domain.getMetadata().getResourceVersion();
53-
String metaResourceVersion = meta.getAnnotations().get(DOMAIN_RESOURCE_VERSION);
54-
return Objects.equals(domainResourceVersion, metaResourceVersion);
46+
public static boolean checkFormatAnnotation(V1ObjectMeta meta) {
47+
String metaResourceVersion = meta.getAnnotations().get(FORMAT_ANNOTATION);
48+
return Objects.equals(FORMAT_VERSION, metaResourceVersion);
5549
}
5650
}

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

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import io.kubernetes.client.ApiException;
1111
import io.kubernetes.client.models.V1ConfigMap;
1212
import io.kubernetes.client.models.V1ObjectMeta;
13-
import io.kubernetes.client.models.V1Pod;
13+
import oracle.kubernetes.operator.KubernetesConstants;
14+
import oracle.kubernetes.operator.LabelConstants;
1415
import oracle.kubernetes.operator.logging.LoggingFacade;
1516
import oracle.kubernetes.operator.logging.LoggingFactory;
1617
import oracle.kubernetes.operator.logging.MessageKeys;
@@ -43,37 +44,54 @@ public ScriptConfigMapStep(String namespace, Step next) {
4344

4445
@Override
4546
public NextAction apply(Packet packet) {
46-
String name = "weblogic-domain-config-map";
47+
String name = KubernetesConstants.DOMAIN_CONFIG_MAP_NAME;
4748
V1ConfigMap cm = new V1ConfigMap();
4849

4950
V1ObjectMeta metadata = new V1ObjectMeta();
5051
metadata.setName(name);
5152
metadata.setNamespace(namespace);
53+
54+
AnnotationHelper.annotateWithFormat(metadata);
55+
56+
Map<String, String> labels = new HashMap<>();
57+
labels.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
58+
metadata.setLabels(labels);
59+
5260
cm.setMetadata(metadata);
5361

5462
Map<String, String> data = new HashMap<>();
5563

56-
// HERE
5764
data.put("livenessProbe.sh",
5865
"#!/bin/bash\n" +
59-
"\n" +
6066
"# Kubernetes periodically calls this liveness probe script to determine whether\n" +
6167
"# the pod should be restarted. The script checks a WebLogic Server state file which\n" +
6268
"# is updated by the node manager.\n" +
69+
"STATEFILE=/shared/domain/$1/servers/$2/data/nodemanager/$2.state\n" +
70+
"if [ \\`jps -l | grep -c \" weblogic.NodeManager\"\\` -eq 0 ]; then\n" +
71+
" exit 1\n" +
72+
"fi\n" +
73+
"if [ -f \\${STATEFILE} ] && [ \\`grep -c \"FAILED_NOT_RESTARTABLE\" \\${STATEFILE}\\` -eq 1 ]; then\n" +
74+
" exit 1\n" +
75+
"fi\n" +
76+
"exit 0");
77+
78+
data.put("readinessProbe.sh",
79+
"#!/bin/bash\n" +
80+
"\n" +
81+
"# Kubernetes periodically calls this readiness probe script to determine whether\n" +
82+
"# the pod should be included in load balancing. The script checks a WebLogic Server state\n" +
83+
"# file which is updated by the node manager.\n" +
6384
"\n" +
64-
"STATEFILE=${DOMAIN_HOME}/servers/${SERVER_NAME}/data/nodemanager/${SERVER_NAME}.state\n" +
85+
"STATEFILE=/shared/domain/$1/servers/$2/data/nodemanager/$2.state\n" +
6586
"\n" +
6687
"if [ \\`jps -l | grep -c \" weblogic.NodeManager\"\\` -eq 0 ]; then\n" +
67-
" echo \"Error: WebLogic NodeManager process not found.\"\n" +
6888
" exit 1\n" +
6989
"fi\n" +
7090
"\n" +
71-
"if [ -f \\${STATEFILE} ] && [ \\`grep -c \"FAILED_NOT_RESTARTABLE\" \\${STATEFILE}\\` -eq 1 ]; then\n" +
72-
" echo \"Error: WebLogic Server FAILED_NOT_RESTARTABLE.\"\n" +
91+
"if [ -f \\${STATEFILE} ] && [ \\`grep -c \"RUNNING\" \\${STATEFILE}\\` -ne 1 ]; then\n" +
7392
" exit 1\n" +
7493
"fi\n" +
7594
"\n" +
76-
"echo \"Info: Probe check passed.\"\n" +
7795
"exit 0");
7896

7997
cm.setData(data);
@@ -97,14 +115,14 @@ public NextAction onSuccess(Packet packet, V1ConfigMap result, int statusCode,
97115
public NextAction onSuccess(Packet packet, V1ConfigMap result, int statusCode,
98116
Map<String, List<String>> responseHeaders) {
99117

100-
LOGGER.info(MessageKeys.ADMIN_POD_CREATED, weblogicDomainUID, spec.getAsName());
118+
LOGGER.info(MessageKeys.CM_CREATED, namespace);
101119
return doNext(packet);
102120
}
103121
});
104122
return doNext(create, packet);
105-
} else if (result.getData().entrySet().containsAll(data.entrySet())) {
123+
} else if (AnnotationHelper.checkFormatAnnotation(result.getMetadata()) && result.getData().entrySet().containsAll(data.entrySet())) {
106124
// existing config map has correct data
107-
LOGGER.fine(MessageKeys.ADMIN_POD_EXISTS, weblogicDomainUID, spec.getAsName());
125+
LOGGER.fine(MessageKeys.CM_EXISTS, namespace);
108126
return doNext(packet);
109127
} else {
110128
// we need to update the config map
@@ -115,7 +133,7 @@ public NextAction onSuccess(Packet packet, V1ConfigMap result, int statusCode,
115133
@Override
116134
public NextAction onSuccess(Packet packet, V1ConfigMap result, int statusCode,
117135
Map<String, List<String>> responseHeaders) {
118-
LOGGER.info(MessageKeys.ADMIN_POD_REPLACED, weblogicDomainUID, spec.getAsName());
136+
LOGGER.info(MessageKeys.CM_REPLACED, namespace);
119137
return doNext(packet);
120138
}
121139
});

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ public NextAction apply(Packet packet) {
7575
v1ObjectMeta.setName(ingressName);
7676
v1ObjectMeta.setNamespace(namespace);
7777

78-
Map<String, String> annotations = new HashMap<>();
79-
annotations.put(KubernetesConstants.CLASS_INGRESS, KubernetesConstants.CLASS_INGRESS_VALUE);
80-
v1ObjectMeta.setAnnotations(annotations);
78+
v1ObjectMeta.putAnnotationsItem(KubernetesConstants.CLASS_INGRESS, KubernetesConstants.CLASS_INGRESS_VALUE);
79+
AnnotationHelper.annotateWithFormat(v1ObjectMeta);
8180

8281
Map<String, String> labels = new HashMap<>();
8382
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
@@ -139,7 +138,7 @@ public NextAction onSuccess(Packet packet, V1beta1Ingress result, int statusCode
139138
}
140139
}), packet);
141140
} else {
142-
if (v1beta1Ingress.getSpec().equals(result.getSpec())) {
141+
if (AnnotationHelper.checkFormatAnnotation(result.getMetadata()) && v1beta1Ingress.getSpec().equals(result.getSpec())) {
143142
return doNext(packet);
144143
}
145144
return doNext(CallBuilder.create().replaceIngressAsync(ingressName, meta.getNamespace(),

0 commit comments

Comments
 (0)