Skip to content

Commit 9395343

Browse files
author
Tom Barnes
committed
Teach operator to leave other peoples stuff alone (add weblogic.CreatedByOperator label to operator owned domain resources, and modify its selectors to look for this label). Plus modify run.sh domain liefecycle test to verify webapp is still OK after a cycling.
1 parent 38336e0 commit 9395343

File tree

10 files changed

+34
-11
lines changed

10 files changed

+34
-11
lines changed

src/integration-tests/bash/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,7 @@ function test_domain_lifecycle {
20642064
shutdown_domain $DOM_KEY
20652065
startup_domain $DOM_KEY
20662066
verify_domain_exists_via_oper_rest $DOM_KEY
2067+
verify_domain $DOM_KEY
20672068

20682069
# verify that scaling $DOM_KEY had no effect on another domain
20692070
if [ ! "$VERIFY_DOM_KEY" = "" ]; then

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ protected Watching<V1beta1Ingress> createWatching(ClientHolder client) {
7777
public WatchI<V1beta1Ingress> initiateWatch(String resourceVersion) throws ApiException {
7878
return new WatchBuilder(client)
7979
.withResourceVersion(resourceVersion)
80-
.withLabelSelector(LabelConstants.DOMAINUID_LABEL) // Any Ingress with a domainUID label
80+
.withLabelSelector(LabelConstants.DOMAINUID_LABEL
81+
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL)
8182
.createIngressWatch(ns);
8283
}
8384

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public interface LabelConstants {
1010
public static final String SERVERNAME_LABEL = "weblogic.serverName";
1111
public static final String CHANNELNAME_LABEL = "weblogic.channelName";
1212
public static final String CLUSTERNAME_LABEL = "weblogic.clusterName";
13+
public static final String CREATEDBYOPERATOR_LABEL = "weblogic.createdByOperator";
1314

1415
}

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,16 @@ public NextAction onSuccess(Packet packet, DomainList result, int statusCode,
207207
});
208208

209209
Step initialize = CallBuilder.create().with($ -> {
210-
$.labelSelector = LabelConstants.DOMAINUID_LABEL; // Any with a domainUID label
210+
$.labelSelector = LabelConstants.DOMAINUID_LABEL
211+
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
211212
}).listPodAsync(ns, new ResponseStep<V1PodList>(
212213
CallBuilder.create().with($ -> {
213-
$.labelSelector = LabelConstants.DOMAINUID_LABEL; // Any with a domainUID label
214+
$.labelSelector = LabelConstants.DOMAINUID_LABEL
215+
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
214216
}).listServiceAsync(ns, new ResponseStep<V1ServiceList>(
215217
CallBuilder.create().with($ -> {
216-
$.labelSelector = LabelConstants.DOMAINUID_LABEL; // Any with a domainUID label
218+
$.labelSelector = LabelConstants.DOMAINUID_LABEL
219+
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
217220
}).listIngressAsync(ns, new ResponseStep<V1beta1IngressList>(domainList) {
218221
@Override
219222
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
@@ -1267,7 +1270,8 @@ public DeleteDomainStep(String namespace, String domainUID) {
12671270
@Override
12681271
public NextAction apply(Packet packet) {
12691272
Step deletePods = CallBuilder.create().with($ -> {
1270-
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "=" + domainUID;
1273+
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "=" + domainUID
1274+
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
12711275
}).deleteCollectionPodAsync(namespace, new ResponseStep<V1Status>(next) {
12721276
@Override
12731277
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
@@ -1286,7 +1290,8 @@ public NextAction onSuccess(Packet packet, V1Status result, int statusCode,
12861290
});
12871291

12881292
Step serviceList = CallBuilder.create().with($ -> {
1289-
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "=" + domainUID;
1293+
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "=" + domainUID
1294+
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
12901295
}).listServiceAsync(namespace, new ResponseStep<V1ServiceList>(deletePods) {
12911296
@Override
12921297
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
@@ -1309,7 +1314,8 @@ public NextAction onSuccess(Packet packet, V1ServiceList result, int statusCode,
13091314

13101315
LOGGER.finer(MessageKeys.LIST_INGRESS_FOR_DOMAIN, domainUID, namespace);
13111316
Step deleteIngress = CallBuilder.create().with($ -> {
1312-
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "=" + domainUID;
1317+
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "=" + domainUID
1318+
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
13131319
}).listIngressAsync(namespace, new ResponseStep<V1beta1IngressList>(serviceList) {
13141320
@Override
13151321
public NextAction onFailure(Packet packet, ApiException e, int statusCode,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ private Watching<V1Pod> createWatching(ClientHolder client) {
102102
public WatchI<V1Pod> initiateWatch(String resourceVersion) throws ApiException {
103103
return new WatchBuilder(client)
104104
.withResourceVersion(resourceVersion)
105-
.withLabelSelector(LabelConstants.DOMAINUID_LABEL) // Any Pod with a domainUID label
105+
.withLabelSelector(LabelConstants.DOMAINUID_LABEL
106+
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL)
106107
.createPodWatch(ns);
107108
}
108109

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ protected Watching<V1Service> createWatching(ClientHolder client) {
7777
public WatchI<V1Service> initiateWatch(String resourceVersion) throws ApiException {
7878
return new WatchBuilder(client)
7979
.withResourceVersion(resourceVersion)
80-
.withLabelSelector(LabelConstants.DOMAINUID_LABEL) // Any Service with a domainUID label
80+
.withLabelSelector(LabelConstants.DOMAINUID_LABEL
81+
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL)
8182
.createServiceWatch(ns);
8283
}
8384

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public NextAction apply(Packet packet) {
8383
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
8484
labels.put(LabelConstants.DOMAINNAME_LABEL, weblogicDomainName);
8585
labels.put(LabelConstants.CLUSTERNAME_LABEL, clusterName);
86+
labels.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
8687
v1ObjectMeta.setLabels(labels);
8788
v1beta1Ingress.setMetadata(v1ObjectMeta);
8889

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public NextAction apply(Packet packet) {
112112
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
113113
labels.put(LabelConstants.DOMAINNAME_LABEL, weblogicDomainName);
114114
labels.put(LabelConstants.SERVERNAME_LABEL, spec.getAsName());
115+
labels.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
115116
metadata.setLabels(labels);
116117

117118
V1PodSpec podSpec = new V1PodSpec();
@@ -456,6 +457,7 @@ public NextAction apply(Packet packet) {
456457
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
457458
labels.put(LabelConstants.DOMAINNAME_LABEL, weblogicDomainName);
458459
labels.put(LabelConstants.SERVERNAME_LABEL, weblogicServerName);
460+
labels.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
459461
if (weblogicClusterName != null)
460462
labels.put(LabelConstants.CLUSTERNAME_LABEL, weblogicClusterName);
461463
metadata.setLabels(labels);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public NextAction apply(Packet packet) {
6969
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
7070
labels.put(LabelConstants.DOMAINNAME_LABEL, weblogicDomainName);
7171
labels.put(LabelConstants.SERVERNAME_LABEL, serverName);
72+
labels.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
7273
metadata.setLabels(labels);
7374
service.setMetadata(metadata);
7475

@@ -81,6 +82,7 @@ public NextAction apply(Packet packet) {
8182
Map<String, String> selector = new HashMap<>();
8283
selector.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
8384
selector.put(LabelConstants.SERVERNAME_LABEL, serverName);
85+
selector.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
8486
serviceSpec.setSelector(selector);
8587

8688
if (version != null && (version.major > 1 || (version.major == 1 && version.minor >= 8))) {
@@ -196,6 +198,7 @@ public NextAction apply(Packet packet) {
196198
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
197199
labels.put(LabelConstants.DOMAINNAME_LABEL, weblogicDomainName);
198200
labels.put(LabelConstants.CLUSTERNAME_LABEL, clusterName);
201+
labels.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
199202
metadata.setLabels(labels);
200203
service.setMetadata(metadata);
201204

@@ -207,6 +210,7 @@ public NextAction apply(Packet packet) {
207210
Map<String, String> selector = new HashMap<>();
208211
selector.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
209212
selector.put(LabelConstants.CLUSTERNAME_LABEL, clusterName);
213+
selector.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
210214
serviceSpec.setSelector(selector);
211215

212216
List<V1ServicePort> ports = new ArrayList<>();
@@ -450,6 +454,7 @@ public NextAction apply(Packet packet) {
450454
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
451455
labels.put(LabelConstants.DOMAINNAME_LABEL, weblogicDomainName);
452456
labels.put(LabelConstants.SERVERNAME_LABEL, serverName);
457+
labels.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
453458
labels.put(LabelConstants.CHANNELNAME_LABEL, networkAccessPoint.getName());
454459
metadata.setLabels(labels);
455460
service.setMetadata(metadata);
@@ -461,6 +466,7 @@ public NextAction apply(Packet packet) {
461466
Map<String, String> selector = new HashMap<>();
462467
selector.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
463468
selector.put(LabelConstants.SERVERNAME_LABEL, serverName);
469+
selector.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
464470
serviceSpec.setSelector(selector);
465471
List<V1ServicePort> ports = new ArrayList<>();
466472
V1ServicePort servicePort = new V1ServicePort();

src/test/java/oracle/kubernetes/operator/builders/WatchBuilderTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static java.net.HttpURLConnection.HTTP_ENTITY_TOO_LARGE;
3131
import static java.net.HttpURLConnection.HTTP_UNAVAILABLE;
3232
import static oracle.kubernetes.operator.LabelConstants.DOMAINUID_LABEL;
33+
import static oracle.kubernetes.operator.LabelConstants.CREATEDBYOPERATOR_LABEL;
3334
import static oracle.kubernetes.operator.builders.EventMatcher.*;
3435
import static oracle.kubernetes.operator.builders.WatchBuilderTest.JsonServletAction.withResponses;
3536
import static oracle.kubernetes.operator.builders.WatchBuilderTest.ParameterValidation.parameter;
@@ -117,12 +118,14 @@ public void whenServiceWatchSpecifiesParameters_verifyAndReturnResponse() throws
117118
defineHttpResponse(SERVICE_RESOURCE, withResponses(createModifiedResponse(service))
118119
.andValidations(
119120
parameter("resourceVersion").withValue(startResourceVersion),
120-
parameter("labelSelector").withValue(DOMAINUID_LABEL),
121+
parameter("labelSelector").withValue(DOMAINUID_LABEL
122+
+ "," + CREATEDBYOPERATOR_LABEL),
121123
parameter("watch").withValue("true")));
122124

123125
WatchI<V1Service> serviceWatch = new WatchBuilder(clientHolder)
124126
.withResourceVersion(startResourceVersion)
125-
.withLabelSelector(DOMAINUID_LABEL)
127+
.withLabelSelector(DOMAINUID_LABEL
128+
+ "," + CREATEDBYOPERATOR_LABEL)
126129
.createServiceWatch(NAMESPACE);
127130

128131
assertThat(serviceWatch, contains(modifyEvent(service)));

0 commit comments

Comments
 (0)