Skip to content

Commit dbd436d

Browse files
committed
Start idolate domain presence logic
1 parent c95e6c2 commit dbd436d

File tree

6 files changed

+325
-97
lines changed

6 files changed

+325
-97
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
package oracle.kubernetes.operator;
5+
6+
import java.util.ArrayList;
7+
import java.util.concurrent.ScheduledFuture;
8+
9+
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
10+
import oracle.kubernetes.weblogic.domain.v1.ClusterStartup;
11+
import oracle.kubernetes.weblogic.domain.v1.DomainSpec;
12+
import oracle.kubernetes.weblogic.domain.v1.ServerStartup;
13+
14+
class DomainPresenceControl {
15+
16+
// This method fills in null values which would interfere with the general DomainSpec.equals() method
17+
static void normalizeDomainSpec(DomainSpec spec) {
18+
normalizeImage(spec);
19+
normalizeImagePullPolicy(spec);
20+
normalizeExportT3Channels(spec);
21+
normalizeStartupControl(spec);
22+
normalizeServerStartup(spec);
23+
normalizeClusterStartup(spec);
24+
normalizeReplicas(spec);
25+
}
26+
27+
private static void normalizeImage(DomainSpec spec) {
28+
if (isNotDefined(spec.getImage())) spec.setImage(KubernetesConstants.DEFAULT_IMAGE);
29+
}
30+
31+
private static void normalizeImagePullPolicy(DomainSpec spec) {
32+
if (isNotDefined(spec.getImagePullPolicy())) {
33+
spec.setImagePullPolicy((spec.getImage().endsWith(KubernetesConstants.LATEST_IMAGE_SUFFIX))
34+
? KubernetesConstants.ALWAYS_IMAGEPULLPOLICY
35+
: KubernetesConstants.IFNOTPRESENT_IMAGEPULLPOLICY);
36+
}
37+
}
38+
39+
private static void normalizeExportT3Channels(DomainSpec spec) {
40+
if (spec.getExportT3Channels() == null)
41+
spec.setExportT3Channels(new ArrayList<>());
42+
}
43+
44+
private static void normalizeStartupControl(DomainSpec spec) {
45+
if (isNotDefined(spec.getStartupControl()))
46+
spec.setStartupControl(StartupControlConstants.AUTO_STARTUPCONTROL);
47+
}
48+
49+
private static void normalizeServerStartup(DomainSpec spec) {
50+
if (spec.getServerStartup() == null)
51+
spec.setServerStartup(new ArrayList<>());
52+
else
53+
for (ServerStartup ss : spec.getServerStartup()) {
54+
if (ss.getDesiredState() == null) ss.setDesiredState(WebLogicConstants.RUNNING_STATE);
55+
if (ss.getEnv() == null) ss.setEnv(new ArrayList<>());
56+
}
57+
}
58+
59+
private static void normalizeClusterStartup(DomainSpec spec) {
60+
if (spec.getClusterStartup() == null)
61+
spec.setClusterStartup(new ArrayList<>());
62+
else
63+
for (ClusterStartup cs : spec.getClusterStartup()) {
64+
if (cs.getDesiredState() == null) cs.setDesiredState(WebLogicConstants.RUNNING_STATE);
65+
if (cs.getEnv() == null) cs.setEnv(new ArrayList<>());
66+
if (cs.getReplicas() == null) cs.setReplicas(1);
67+
}
68+
}
69+
70+
private static void normalizeReplicas(DomainSpec spec) {
71+
if (spec.getReplicas() == null) spec.setReplicas(1);
72+
}
73+
74+
private static boolean isNotDefined(String value) {
75+
return value == null || value.length() == 0;
76+
}
77+
78+
static void cancelDomainStatusUpdating(DomainPresenceInfo info) {
79+
ScheduledFuture<?> statusUpdater = info.getStatusUpdater().getAndSet(null);
80+
if (statusUpdater != null) {
81+
statusUpdater.cancel(true);
82+
}
83+
}
84+
}

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

Lines changed: 27 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@
7575
import oracle.kubernetes.operator.work.NextAction;
7676
import oracle.kubernetes.operator.work.Packet;
7777
import oracle.kubernetes.operator.work.Step;
78-
import oracle.kubernetes.weblogic.domain.v1.ClusterStartup;
7978
import oracle.kubernetes.weblogic.domain.v1.Domain;
8079
import oracle.kubernetes.weblogic.domain.v1.DomainList;
8180
import oracle.kubernetes.weblogic.domain.v1.DomainSpec;
82-
import oracle.kubernetes.weblogic.domain.v1.ServerStartup;
8381

8482
/**
8583
* A Kubernetes Operator for WebLogic.
@@ -275,60 +273,6 @@ public void onThrowable(Packet packet, Throwable throwable) {
275273
//
276274
// -----------------------------------------------------------------------------
277275

278-
private static void normalizeDomainSpec(DomainSpec spec) {
279-
// Normalize DomainSpec so that equals() will work correctly
280-
String imageName = spec.getImage();
281-
if (isNotDefined(imageName)) {
282-
spec.setImage(imageName = KubernetesConstants.DEFAULT_IMAGE);
283-
}
284-
if (isNotDefined(spec.getImagePullPolicy())) {
285-
spec.setImagePullPolicy((imageName.endsWith(KubernetesConstants.LATEST_IMAGE_SUFFIX))
286-
? KubernetesConstants.ALWAYS_IMAGEPULLPOLICY
287-
: KubernetesConstants.IFNOTPRESENT_IMAGEPULLPOLICY);
288-
}
289-
if (spec.getExportT3Channels() == null) {
290-
spec.setExportT3Channels(new ArrayList<>());
291-
}
292-
String startupControl = spec.getStartupControl();
293-
if (isNotDefined(startupControl)) {
294-
spec.setStartupControl(StartupControlConstants.AUTO_STARTUPCONTROL);
295-
}
296-
if (spec.getServerStartup() == null) {
297-
spec.setServerStartup(new ArrayList<>());
298-
} else {
299-
for (ServerStartup ss : spec.getServerStartup()) {
300-
if (ss.getDesiredState() == null) {
301-
ss.setDesiredState(WebLogicConstants.RUNNING_STATE);
302-
}
303-
if (ss.getEnv() == null) {
304-
ss.setEnv(new ArrayList<>());
305-
}
306-
}
307-
}
308-
if (spec.getClusterStartup() == null) {
309-
spec.setClusterStartup(new ArrayList<>());
310-
} else {
311-
for (ClusterStartup cs : spec.getClusterStartup()) {
312-
if (cs.getDesiredState() == null) {
313-
cs.setDesiredState(WebLogicConstants.RUNNING_STATE);
314-
}
315-
if (cs.getEnv() == null) {
316-
cs.setEnv(new ArrayList<>());
317-
}
318-
if (cs.getReplicas() == null) {
319-
cs.setReplicas(1);
320-
}
321-
}
322-
}
323-
if (spec.getReplicas() == null) {
324-
spec.setReplicas(1);
325-
}
326-
}
327-
328-
private static boolean isNotDefined(String value) {
329-
return value == null || value.length() == 0;
330-
}
331-
332276
/**
333277
* Restarts the admin server, if already running
334278
*
@@ -454,13 +398,6 @@ public void onThrowable(Packet packet, Throwable throwable) {
454398
}
455399
}
456400

457-
private static void cancelDomainStatusUpdating(DomainPresenceInfo info) {
458-
ScheduledFuture<?> statusUpdater = info.getStatusUpdater().getAndSet(null);
459-
if (statusUpdater != null) {
460-
statusUpdater.cancel(true);
461-
}
462-
}
463-
464401
private static void doCheckAndCreateDomainPresence(Domain dom) {
465402
doCheckAndCreateDomainPresence(dom, false, false, null, null);
466403
}
@@ -477,7 +414,7 @@ private static void doCheckAndCreateDomainPresence(Domain dom, boolean explicitR
477414
|| explicitRestartClusters != null;
478415

479416
DomainSpec spec = dom.getSpec();
480-
normalizeDomainSpec(spec);
417+
DomainPresenceControl.normalizeDomainSpec(spec);
481418
String domainUID = spec.getDomainUID();
482419

483420
DomainPresenceInfo created = new DomainPresenceInfo(dom);
@@ -599,7 +536,7 @@ private static void deleteDomainPresence(String namespace, String domainUID) {
599536

600537
DomainPresenceInfo info = domains.remove(domainUID);
601538
if (info != null) {
602-
cancelDomainStatusUpdating(info);
539+
DomainPresenceControl.cancelDomainStatusUpdating(info);
603540
}
604541
domainUpdaters.startFiber(domainUID, new DeleteDomainStep(namespace, domainUID), new Packet(),
605542
new CompletionCallback() {
@@ -623,7 +560,7 @@ public void onThrowable(Packet packet, Throwable throwable) {
623560
* @return the collection of target namespace names
624561
*/
625562
private static Collection<String> getTargetNamespaces(String namespace) {
626-
Collection<String> targetNamespaces = new ArrayList<String>();
563+
Collection<String> targetNamespaces = new ArrayList<>();
627564

628565
String tnValue = tuningAndConfig.get("targetNamespaces");
629566
if (tnValue != null) {
@@ -678,10 +615,6 @@ public static boolean getStopping() {
678615
return stopping.get();
679616
}
680617

681-
private static DomainWatcher createDomainWatcher(String namespace, String initialResourceVersion) {
682-
return DomainWatcher.create(factory, namespace, initialResourceVersion, Main::dispatchDomainWatch, stopping);
683-
}
684-
685618
private static EventWatcher createEventWatcher(String namespace, String initialResourceVersion) {
686619
return EventWatcher.create(factory, namespace, READINESS_PROBE_FAILURE_EVENT_FILTER, initialResourceVersion,
687620
Main::dispatchEventWatch, stopping);
@@ -958,7 +891,7 @@ private static String getOperatorNamespace() {
958891
private static class V1beta1IngressListResponseStep extends ResponseStep<V1beta1IngressList> {
959892
private final String ns;
960893

961-
public V1beta1IngressListResponseStep(Step domainList, String ns) {
894+
V1beta1IngressListResponseStep(Step domainList, String ns) {
962895
super(domainList);
963896
this.ns = ns;
964897
}
@@ -998,10 +931,10 @@ public NextAction onSuccess(Packet packet, V1beta1IngressList result, int status
998931
private static class V1ServiceListResponseStep extends ResponseStep<V1ServiceList> {
999932
private final String ns;
1000933

1001-
public V1ServiceListResponseStep(String ns, V1beta1IngressListResponseStep ingressListResponseStep) {
1002-
super(Main.callBuilderFactory.create().with($ -> {
1003-
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
1004-
}).listIngressAsync(ns, ingressListResponseStep));
934+
V1ServiceListResponseStep(String ns, V1beta1IngressListResponseStep ingressListResponseStep) {
935+
super(Main.callBuilderFactory.create()
936+
.with($ -> $.labelSelector = LabelConstants.DOMAINUID_LABEL + "," + LabelConstants.CREATEDBYOPERATOR_LABEL)
937+
.listIngressAsync(ns, ingressListResponseStep));
1005938
this.ns = ns;
1006939
}
1007940

@@ -1046,10 +979,10 @@ public NextAction onSuccess(Packet packet, V1ServiceList result, int statusCode,
1046979
private static class V1EventListResponseStep extends ResponseStep<V1EventList> {
1047980
private final String ns;
1048981

1049-
public V1EventListResponseStep(String ns, V1ServiceListResponseStep serviceListResponseStep) {
1050-
super(Main.callBuilderFactory.create().with($ -> {
1051-
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
1052-
}).listServiceAsync(ns, serviceListResponseStep));
982+
V1EventListResponseStep(String ns, V1ServiceListResponseStep serviceListResponseStep) {
983+
super(Main.callBuilderFactory.create()
984+
.with($ -> $.labelSelector = LabelConstants.DOMAINUID_LABEL + "," + LabelConstants.CREATEDBYOPERATOR_LABEL)
985+
.listServiceAsync(ns, serviceListResponseStep));
1053986
this.ns = ns;
1054987
}
1055988

@@ -1079,10 +1012,10 @@ public NextAction onSuccess(Packet packet, V1EventList result, int statusCode,
10791012
private static class V1PodListResponseStep extends ResponseStep<V1PodList> {
10801013
private final String ns;
10811014

1082-
public V1PodListResponseStep(String ns, V1EventListResponseStep eventListResponseStep) {
1083-
super(Main.callBuilderFactory.create().with($ -> {
1084-
$.fieldSelector = Main.READINESS_PROBE_FAILURE_EVENT_FILTER;
1085-
}).listEventAsync(ns, eventListResponseStep));
1015+
V1PodListResponseStep(String ns, V1EventListResponseStep eventListResponseStep) {
1016+
super(Main.callBuilderFactory.create()
1017+
.with($ -> $.fieldSelector = Main.READINESS_PROBE_FAILURE_EVENT_FILTER)
1018+
.listEventAsync(ns, eventListResponseStep));
10861019
this.ns = ns;
10871020
}
10881021

@@ -1122,7 +1055,7 @@ public NextAction onSuccess(Packet packet, V1PodList result, int statusCode,
11221055
private static class ExistingDomainListResponseStep extends ResponseStep<DomainList> {
11231056
private final String ns;
11241057

1125-
public ExistingDomainListResponseStep(String ns) {
1058+
ExistingDomainListResponseStep(String ns) {
11261059
super(null);
11271060
this.ns = ns;
11281061
}
@@ -1137,18 +1070,23 @@ public NextAction onFailure(Packet packet, ApiException e, int statusCode,
11371070
}
11381071

11391072
@Override
1140-
public NextAction onSuccess(Packet packet, DomainList result, int statusCode,
1141-
Map<String, List<String>> responseHeaders) {
1073+
public NextAction onSuccess(Packet packet, DomainList result, int statusCode, Map<String, List<String>> responseHeaders) {
11421074
if (result != null) {
11431075
for (Domain dom : result.getItems()) {
11441076
doCheckAndCreateDomainPresence(dom);
11451077
}
11461078
}
11471079

1148-
// main logic now happens in the watch handlers
1149-
domainWatchers.put(ns,
1150-
createDomainWatcher(ns, result != null ? result.getMetadata().getResourceVersion() : ""));
1080+
domainWatchers.put(ns, createDomainWatcher(ns, getResourceVersion(result)));
11511081
return doNext(packet);
11521082
}
1083+
1084+
String getResourceVersion(DomainList result) {
1085+
return result != null ? result.getMetadata().getResourceVersion() : "";
1086+
}
1087+
1088+
private static DomainWatcher createDomainWatcher(String namespace, String initialResourceVersion) {
1089+
return DomainWatcher.create(factory, namespace, initialResourceVersion, Main::dispatchDomainWatch, stopping);
1090+
}
11531091
}
11541092
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public DomainList listDomain(String namespace) throws ApiException {
174174
String _continue = "";
175175
ApiClient client = helper.take();
176176
try {
177-
return CALL_FACTORY.getDomainList(client, namespace, _continue, pretty, fieldSelector, includeUninitialized, labelSelector,
177+
return CALL_FACTORY.getDomainList(client, namespace, pretty, _continue, fieldSelector, includeUninitialized, labelSelector,
178178
limit, resourceVersion, timeoutSeconds, watch);
179179
} finally {
180180
helper.recycle(client);
@@ -614,7 +614,7 @@ public V1PersistentVolumeList listPersistentVolume() throws ApiException {
614614
String _continue = "";
615615
ApiClient client = helper.take();
616616
try {
617-
return CALL_FACTORY.listPersistentVolumes(_continue, client, pretty, fieldSelector, includeUninitialized,
617+
return CALL_FACTORY.listPersistentVolumes(client, pretty, _continue, fieldSelector, includeUninitialized,
618618
labelSelector, limit, resourceVersion, timeoutSeconds, watch);
619619
} finally {
620620
helper.recycle(client);
@@ -984,7 +984,7 @@ public V1SelfSubjectRulesReview createSelfSubjectRulesReview(ApiClient client, V
984984
}
985985

986986
@Override
987-
public V1PersistentVolumeList listPersistentVolumes(String _continue, ApiClient client, String pretty, String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String resourceVersion, Integer timeoutSeconds, Boolean watch) throws ApiException {
987+
public V1PersistentVolumeList listPersistentVolumes(ApiClient client, String pretty, String _continue, String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String resourceVersion, Integer timeoutSeconds, Boolean watch) throws ApiException {
988988
return new CoreV1Api(client).listPersistentVolume(pretty, _continue, fieldSelector,
989989
includeUninitialized, labelSelector, limit, resourceVersion, timeoutSeconds, watch);
990990
}
@@ -995,7 +995,7 @@ public VersionInfo getVersionCode(ApiClient client) throws ApiException {
995995
}
996996

997997
@Override
998-
public DomainList getDomainList(ApiClient client, String namespace, String _continue, String pretty, String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String resourceVersion, Integer timeoutSeconds, Boolean watch) throws ApiException {
998+
public DomainList getDomainList(ApiClient client, String namespace, String pretty, String _continue, String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String resourceVersion, Integer timeoutSeconds, Boolean watch) throws ApiException {
999999
return new WeblogicApi(client).listWebLogicOracleV1NamespacedDomain(namespace, pretty, _continue,
10001000
fieldSelector, includeUninitialized, labelSelector, limit, resourceVersion, timeoutSeconds, watch);
10011001
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2018 Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
14
package oracle.kubernetes.operator.helpers;
25

36
import io.kubernetes.client.ApiClient;
@@ -8,6 +11,7 @@
811
import io.kubernetes.client.models.VersionInfo;
912
import oracle.kubernetes.weblogic.domain.v1.DomainList;
1013

14+
1115
public interface SynchronousCallFactory {
1216

1317
V1beta1CustomResourceDefinition readCustomResourceDefinition(ApiClient client, String name, String pretty, Boolean exact, Boolean export) throws ApiException;
@@ -16,9 +20,9 @@ public interface SynchronousCallFactory {
1620

1721
V1SelfSubjectRulesReview createSelfSubjectRulesReview(ApiClient client, V1SelfSubjectRulesReview body, String pretty) throws ApiException;
1822

19-
V1PersistentVolumeList listPersistentVolumes(String _continue, ApiClient client, String pretty, String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String resourceVersion, Integer timeoutSeconds, Boolean watch) throws ApiException;
23+
V1PersistentVolumeList listPersistentVolumes(ApiClient client, String pretty, String _continue, String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String resourceVersion, Integer timeoutSeconds, Boolean watch) throws ApiException;
2024

2125
VersionInfo getVersionCode(ApiClient client) throws ApiException;
2226

23-
DomainList getDomainList(ApiClient client, String namespace, String _continue, String pretty, String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String resourceVersion, Integer timeoutSeconds, Boolean watch) throws ApiException;
27+
DomainList getDomainList(ApiClient client, String namespace, String pretty, String _continue, String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String resourceVersion, Integer timeoutSeconds, Boolean watch) throws ApiException;
2428
}

0 commit comments

Comments
 (0)