Skip to content

Commit 0586186

Browse files
authored
Merge pull request #103 from oracle/issue-54
Issue 54: Deleted pods, services, and ingress resources are recreated
2 parents 25f33ca + 4985335 commit 0586186

19 files changed

+865
-400
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ public NextAction apply(Packet packet) {
303303
@Override
304304
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
305305
Map<String, List<String>> responseHeaders) {
306-
if (statusCode == CallBuilder.NOT_FOUND || statusCode == CallBuilder.CONFLICT) {
306+
if (statusCode == CallBuilder.NOT_FOUND) {
307307
return doNext(packet); // Just ignore update
308308
}
309-
return super.onFailure(packet, e, statusCode, responseHeaders);
309+
return super.onFailure(next, packet, e, statusCode, responseHeaders);
310310
}
311311

312312
@Override
@@ -426,10 +426,10 @@ public NextAction apply(Packet packet) {
426426
@Override
427427
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
428428
Map<String, List<String>> responseHeaders) {
429-
if (statusCode == CallBuilder.NOT_FOUND || statusCode == CallBuilder.CONFLICT) {
429+
if (statusCode == CallBuilder.NOT_FOUND) {
430430
return doNext(packet); // Just ignore update
431431
}
432-
return super.onFailure(packet, e, statusCode, responseHeaders);
432+
return super.onFailure(next, packet, e, statusCode, responseHeaders);
433433
}
434434

435435
@Override
@@ -547,10 +547,10 @@ public NextAction apply(Packet packet) {
547547
@Override
548548
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
549549
Map<String, List<String>> responseHeaders) {
550-
if (statusCode == CallBuilder.NOT_FOUND || statusCode == CallBuilder.CONFLICT) {
550+
if (statusCode == CallBuilder.NOT_FOUND) {
551551
return doNext(packet); // Just ignore update
552552
}
553-
return super.onFailure(packet, e, statusCode, responseHeaders);
553+
return super.onFailure(next, packet, e, statusCode, responseHeaders);
554554
}
555555

556556
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Watch<Domain> initiateWatch(Object context, String resourceVersion) throw
7676
return Watch.createWatch(client.getApiClient(),
7777
client.callBuilder().with($ -> {
7878
$.resourceVersion = resourceVersion;
79-
$.timeoutSeconds = 2;
79+
$.timeoutSeconds = 30;
8080
$.watch = true;
8181
}).listDomainCall(ns),
8282
new TypeToken<Watch.Response<Domain>>() {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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.concurrent.atomic.AtomicBoolean;
7+
8+
import com.google.gson.reflect.TypeToken;
9+
import io.kubernetes.client.ApiException;
10+
import io.kubernetes.client.models.V1beta1Ingress;
11+
import io.kubernetes.client.util.Watch;
12+
import oracle.kubernetes.operator.helpers.ClientHelper;
13+
import oracle.kubernetes.operator.helpers.ClientHolder;
14+
import oracle.kubernetes.operator.watcher.Watcher;
15+
import oracle.kubernetes.operator.watcher.Watching;
16+
import oracle.kubernetes.operator.watcher.WatchingEventDestination;
17+
18+
/**
19+
* This class handles Ingress watching. It receives Ingress change events and sends
20+
* them into the operator for processing.
21+
*/
22+
public class IngressWatcher implements Runnable {
23+
private final String ns;
24+
private final String initialResourceVersion;
25+
private final WatchingEventDestination<V1beta1Ingress> destination;
26+
private final AtomicBoolean isStopping;
27+
28+
public static IngressWatcher create(String ns, String initialResourceVersion, WatchingEventDestination<V1beta1Ingress> destination, AtomicBoolean isStopping) {
29+
IngressWatcher dlw = new IngressWatcher(ns, initialResourceVersion, destination, isStopping);
30+
Thread thread = new Thread(dlw);
31+
thread.setName("Thread-IngressWatcher-" + ns);
32+
thread.setDaemon(true);
33+
thread.start();
34+
return dlw;
35+
}
36+
37+
private IngressWatcher(String ns, String initialResourceVersion, WatchingEventDestination<V1beta1Ingress> destination, AtomicBoolean isStopping) {
38+
this.ns = ns;
39+
this.initialResourceVersion = initialResourceVersion;
40+
this.destination = destination;
41+
this.isStopping = isStopping;
42+
}
43+
44+
/**
45+
* Polling loop. Get the next Ingress object event and process it.
46+
*/
47+
@Override
48+
public void run() {
49+
ClientHelper helper = ClientHelper.getInstance();
50+
ClientHolder client = helper.take();
51+
try {
52+
Watching<V1beta1Ingress> w = createWatching(client);
53+
Watcher<V1beta1Ingress> watcher = new Watcher<V1beta1Ingress>(w, null, initialResourceVersion);
54+
55+
// invoke watch on current Thread. Won't return until watch stops
56+
watcher.doWatch();
57+
58+
} finally {
59+
helper.recycle(client);
60+
}
61+
}
62+
63+
protected Watching<V1beta1Ingress> createWatching(ClientHolder client) {
64+
return new Watching<V1beta1Ingress>() {
65+
66+
/**
67+
* Watcher callback to issue the list Ingress changes. It is driven by the
68+
* Watcher wrapper to issue repeated watch requests.
69+
* @param context user defined contact object or null
70+
* @param resourceVersion resource version to omit older events
71+
* @return Watch object or null if the operation should end
72+
* @throws ApiException if there is an API error.
73+
*/
74+
@Override
75+
public Watch<V1beta1Ingress> initiateWatch(Object context, String resourceVersion) throws ApiException {
76+
return Watch.createWatch(client.getApiClient(),
77+
client.callBuilder().with($ -> {
78+
$.resourceVersion = resourceVersion;
79+
$.labelSelector = LabelConstants.DOMAINUID_LABEL; // Any Ingress with a domainUID label
80+
$.timeoutSeconds = 30;
81+
$.watch = true;
82+
}).listIngressCall(ns),
83+
new TypeToken<Watch.Response<V1beta1Ingress>>() {
84+
}.getType());
85+
}
86+
87+
@Override
88+
public void eventCallback(Watch.Response<V1beta1Ingress> item) {
89+
processEventCallback(item);
90+
}
91+
92+
@Override
93+
public boolean isStopping() {
94+
return isStopping.get();
95+
}
96+
};
97+
}
98+
99+
public void processEventCallback(Watch.Response<V1beta1Ingress> item) {
100+
destination.eventCallback(item);
101+
}
102+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public interface LabelConstants {
88
public static final String DOMAINUID_LABEL = "weblogic.domainUID";
99
public static final String DOMAINNAME_LABEL = "weblogic.domainName";
1010
public static final String SERVERNAME_LABEL = "weblogic.serverName";
11+
public static final String CHANNELNAME_LABEL = "weblogic.channelName";
1112
public static final String CLUSTERNAME_LABEL = "weblogic.clusterName";
1213

1314
}

0 commit comments

Comments
 (0)