Skip to content

Commit 996c670

Browse files
committed
Backport OWLS-80884 fix to not stop pods no longer managed by this operator
1 parent a2e9f8e commit 996c670

File tree

5 files changed

+165
-41
lines changed

5 files changed

+165
-41
lines changed

docs/charts/index.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,83 @@ apiVersion: v1
22
entries:
33
weblogic-operator:
44
- apiVersion: v1
5-
created: "2020-06-01T11:06:47.01222-04:00"
5+
created: "2020-06-19T15:05:15.882687-04:00"
66
description: Helm chart for configuring the WebLogic operator.
77
digest: 5f4cd8f4f3282b52b5e90a1169f26986e8272671845053606ade9c855fb04151
88
name: weblogic-operator
99
urls:
1010
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-3.0.0-rc1.tgz
1111
version: 3.0.0-rc1
1212
- apiVersion: v1
13-
created: "2020-06-01T11:06:47.009924-04:00"
13+
created: "2020-06-19T15:05:15.880744-04:00"
1414
description: Helm chart for configuring the WebLogic operator.
15-
digest: 90cce593163ff508ccfe1e00046d2bd7f0ea28b2403812e427f3d6fed473771e
15+
digest: d441888a8deae1b1339e7585e3b437dfd2533303e46e842d7378e16db665e234
1616
name: weblogic-operator
1717
urls:
1818
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.6.0.tgz
1919
version: 2.6.0
2020
- apiVersion: v1
21-
created: "2020-06-01T11:06:46.996245-04:00"
21+
created: "2020-06-19T15:05:15.875847-04:00"
2222
description: Helm chart for configuring the WebLogic operator.
2323
digest: fe41421b7dc45dc8a3b2888d3a626a37f5d3c8e1fa292fb6699deedc5e1db33d
2424
name: weblogic-operator
2525
urls:
2626
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.5.0.tgz
2727
version: 2.5.0
2828
- apiVersion: v1
29-
created: "2020-06-01T11:06:46.984232-04:00"
29+
created: "2020-06-19T15:05:15.874044-04:00"
3030
description: Helm chart for configuring the WebLogic operator.
3131
digest: b36bd32083f67453a62d089a2c09ce38e6655d88ac8a7b38691230c55c40e672
3232
name: weblogic-operator
3333
urls:
3434
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.4.0.tgz
3535
version: 2.4.0
3636
- apiVersion: v1
37-
created: "2020-06-01T11:06:46.957724-04:00"
37+
created: "2020-06-19T15:05:15.872291-04:00"
3838
description: Helm chart for configuring the WebLogic operator.
3939
digest: a3eafe4c2c6ff49384e56421201e59a3737d651af8d5b605b87a19eb1f6f1dc3
4040
name: weblogic-operator
4141
urls:
4242
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.3.1.tgz
4343
version: 2.3.1
4444
- apiVersion: v1
45-
created: "2020-06-01T11:06:46.91045-04:00"
45+
created: "2020-06-19T15:05:15.868706-04:00"
4646
description: Helm chart for configuring the WebLogic operator.
4747
digest: cbc6caaa6eb28e3c7e906ede14b2ae511a0b35fc12a8e3ab629155b09993e8b2
4848
name: weblogic-operator
4949
urls:
5050
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.3.0.tgz
5151
version: 2.3.0
5252
- apiVersion: v1
53-
created: "2020-06-01T11:06:46.888509-04:00"
53+
created: "2020-06-19T15:05:15.866966-04:00"
5454
description: Helm chart for configuring the WebLogic operator.
5555
digest: 23d5a1c554fa8211cc1e86b7ade09460917cb2069e68fb4bfdddafc8db44fdcd
5656
name: weblogic-operator
5757
urls:
5858
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.2.1.tgz
5959
version: 2.2.1
6060
- apiVersion: v1
61-
created: "2020-06-01T11:06:46.885035-04:00"
61+
created: "2020-06-19T15:05:15.865414-04:00"
6262
description: Helm chart for configuring the WebLogic operator.
6363
digest: bba303686cb55d84fe8c0d693a2436e7e686b028085b56e012f6381699a3911f
6464
name: weblogic-operator
6565
urls:
6666
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.2.0.tgz
6767
version: 2.2.0
6868
- apiVersion: v1
69-
created: "2020-06-01T11:06:46.879707-04:00"
69+
created: "2020-06-19T15:05:15.862974-04:00"
7070
description: Helm chart for configuring the WebLogic operator.
7171
digest: 391e23c0969ada5f0cd2a088ddc6f11f237f57521801ed3925db2149a8437a0d
7272
name: weblogic-operator
7373
urls:
7474
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.1.tgz
7575
version: "2.1"
7676
- apiVersion: v1
77-
created: "2020-06-01T11:06:46.872459-04:00"
77+
created: "2020-06-19T15:05:15.861136-04:00"
7878
description: Helm chart for configuring the WebLogic operator.
7979
digest: 298acda78ab73db6b7ba6f2752311bfa40c65874e03fb196b70976192211c1a5
8080
name: weblogic-operator
8181
urls:
8282
- https://oracle.github.io/weblogic-kubernetes-operator/charts/weblogic-operator-2.0.1.tgz
8383
version: 2.0.1
84-
generated: "2020-06-01T11:06:46.867346-04:00"
84+
generated: "2020-06-19T15:05:15.857696-04:00"
-1.37 KB
Binary file not shown.

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

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class Main {
8686
private static final TuningParameters tuningAndConfig;
8787
private static final CallBuilderFactory callBuilderFactory = new CallBuilderFactory();
8888
private static Map<String, NamespaceStatus> namespaceStatuses = new ConcurrentHashMap<>();
89-
private static Map<String, AtomicBoolean> isNamespaceStopping = new ConcurrentHashMap<>();
89+
private static Map<String, AtomicBoolean> namespaceStoppingMap = new ConcurrentHashMap<>();
9090
private static final Map<String, ConfigMapWatcher> configMapWatchers = new ConcurrentHashMap<>();
9191
private static final Map<String, DomainWatcher> domainWatchers = new ConcurrentHashMap<>();
9292
private static final Map<String, EventWatcher> eventWatchers = new ConcurrentHashMap<>();
@@ -227,7 +227,7 @@ private static void begin() {
227227
private static void completeBegin() {
228228
try {
229229
// start the REST server
230-
startRestServer(principal, isNamespaceStopping.keySet());
230+
startRestServer(principal, namespaceStoppingMap.keySet());
231231

232232
// start periodic retry and recheck
233233
int recheckInterval = tuningAndConfig.getMainTuning().targetNamespaceRecheckIntervalSeconds;
@@ -247,14 +247,23 @@ private static void completeBegin() {
247247
}
248248
}
249249

250-
private static void stopNamespace(String ns, boolean remove) {
251-
processor.stopNamespace(ns);
252-
AtomicBoolean stopping =
253-
remove ? isNamespaceStopping.remove(ns) : isNamespaceStopping.get(ns);
250+
private static void stopNamespace(String ns, boolean inTargetNamespaceList) {
251+
AtomicBoolean isNamespaceStopping = isNamespaceStopping(ns);
254252

255-
if (stopping != null) {
256-
stopping.set(true);
253+
// Remove if namespace not in targetNamespace list
254+
if (!inTargetNamespaceList) {
255+
namespaceStoppingMap.remove(ns);
257256
}
257+
258+
// stop all Domains for namespace being stopped (not active)
259+
if (isNamespaceStopping.get()) {
260+
processor.stopNamespace(ns);
261+
}
262+
263+
// set flag to indicate namespace is stopping.
264+
isNamespaceStopping.set(true);
265+
266+
// unsubscribe from resource events for given namespace
258267
namespaceStatuses.remove(ns);
259268
domainWatchers.remove(ns);
260269
eventWatchers.remove(ns);
@@ -267,12 +276,12 @@ private static void stopNamespace(String ns, boolean remove) {
267276
private static void stopNamespaces(Collection<String> targetNamespaces,
268277
Collection<String> namespacesToStop) {
269278
for (String ns : namespacesToStop) {
270-
stopNamespace(ns, (! targetNamespaces.contains(ns)));
279+
stopNamespace(ns, targetNamespaces.contains(ns));
271280
}
272281
}
273282

274283
private static AtomicBoolean isNamespaceStopping(String ns) {
275-
return isNamespaceStopping.computeIfAbsent(ns, (key) -> new AtomicBoolean(false));
284+
return namespaceStoppingMap.computeIfAbsent(ns, (key) -> new AtomicBoolean(false));
276285
}
277286

278287
private static void runSteps(Step firstStep) {
@@ -294,7 +303,7 @@ static Runnable recheckDomains() {
294303

295304
// Check for namespaces that are removed from the operator's
296305
// targetNamespaces list, or that are deleted from the Kubernetes cluster.
297-
Set<String> namespacesToStop = new TreeSet<>(isNamespaceStopping.keySet());
306+
Set<String> namespacesToStop = new TreeSet<>(namespaceStoppingMap.keySet());
298307
for (String ns : targetNamespaces) {
299308
// the active namespaces are the ones that will not be stopped
300309
if (delegate.isNamespaceRunning(ns)) {
@@ -403,7 +412,7 @@ private static Collection<String> getTargetNamespaces() {
403412
return isDedicated()
404413
? Collections.singleton(operatorNamespace)
405414
: getTargetNamespaces(Optional.ofNullable(getHelmVariable.apply("OPERATOR_TARGET_NAMESPACES"))
406-
.orElse(tuningAndConfig.get("targetNamespaces")), operatorNamespace);
415+
.orElse(tuningAndConfig.get("targetNamespaces")), operatorNamespace);
407416
}
408417

409418
public static boolean isDedicated() {
@@ -450,7 +459,7 @@ private static void waitForDeath() {
450459
Thread.currentThread().interrupt();
451460
}
452461

453-
isNamespaceStopping.forEach((key, value) -> value.set(true));
462+
namespaceStoppingMap.forEach((key, value) -> value.set(true));
454463
}
455464

456465
private static EventWatcher createEventWatcher(String ns, String initialResourceVersion) {
@@ -528,15 +537,15 @@ private static void dispatchNamespaceWatch(Watch.Response<V1Namespace> item) {
528537
runSteps(Step.chain(
529538
ConfigMapHelper.createScriptConfigMapStep(operatorNamespace, ns),
530539
createConfigMapStep(ns)));
531-
isNamespaceStopping.put(ns, new AtomicBoolean(false));
540+
namespaceStoppingMap.put(ns, new AtomicBoolean(false));
532541
}
533542
break;
534543

535544
case "DELETED":
536545
// Mark the namespace as isStopping, which will cause the namespace be stopped
537546
// the next time when recheckDomains is triggered
538547
if (delegate.isNamespaceRunning(ns)) {
539-
isNamespaceStopping.put(ns, new AtomicBoolean(true));
548+
namespaceStoppingMap.put(ns, new AtomicBoolean(true));
540549
}
541550

542551
break;
@@ -904,17 +913,17 @@ public NextAction onSuccess(Packet packet, CallResponse<V1NamespaceList> callRes
904913
Step strategy = null;
905914
if (!namespacesToStart.isEmpty()) {
906915
strategy = Step.chain(createDomainCrdAndStartNamespaces(namespacesToStart),
907-
new CreateNamespaceWatcherStep(intialResourceVersion));
916+
new CreateNamespaceWatcherStep(intialResourceVersion));
908917
} else {
909918
strategy = CrdHelper.createDomainCrdStep(version,
910-
new CreateNamespaceWatcherStep(intialResourceVersion));
919+
new CreateNamespaceWatcherStep(intialResourceVersion));
911920
}
912921
return doNext(strategy, packet);
913922
}
914923

915924
private Step createDomainCrdAndStartNamespaces(Collection<String> namespacesToStart) {
916925
return CrdHelper.createDomainCrdStep(version,
917-
new StartNamespacesStep(namespacesToStart, false));
926+
new StartNamespacesStep(namespacesToStart, false));
918927
}
919928

920929
private String getInitialResourceVersion(V1NamespaceList result) {
@@ -991,7 +1000,7 @@ public boolean isNamespaceRunning(String namespace) {
9911000
// make sure the map entry is initialized the value to "false" if absent
9921001
isNamespaceStopping(namespace);
9931002

994-
return !isNamespaceStopping.get(namespace).get();
1003+
return !namespaceStoppingMap.get(namespace).get();
9951004
}
9961005

9971006
@Override

operator/src/test/java/oracle/kubernetes/operator/DomainPresenceTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class DomainPresenceTest extends ThreadFactoryTestBase {
5252

5353
private List<Memento> mementos = new ArrayList<>();
5454
private KubernetesTestSupport testSupport = new KubernetesTestSupport();
55-
private Map<String, AtomicBoolean> isNamespaceStopping;
55+
private Map<String, AtomicBoolean> namespaceStoppingMap;
5656

5757
private static Memento installStub(Class<?> containingClass, String fieldName, Object newValue)
5858
throws NoSuchFieldException {
@@ -73,12 +73,12 @@ public void setUp() throws Exception {
7373
mementos.add(StaticStubSupport.install(Main.class, "engine", testSupport.getEngine()));
7474
testSupport.addContainerComponent("TF", ThreadFactory.class, this);
7575

76-
isNamespaceStopping = getStoppingVariable();
77-
isNamespaceStopping.computeIfAbsent(NS, k -> new AtomicBoolean(true)).set(true);
76+
namespaceStoppingMap = getStoppingVariable();
77+
namespaceStoppingMap.computeIfAbsent(NS, k -> new AtomicBoolean(true)).set(true);
7878
}
7979

8080
private Map<String, AtomicBoolean> getStoppingVariable() throws NoSuchFieldException {
81-
Memento stoppingMemento = StaticStubSupport.preserve(Main.class, "isNamespaceStopping");
81+
Memento stoppingMemento = StaticStubSupport.preserve(Main.class, "namespaceStoppingMap");
8282
return stoppingMemento.getOriginalValue();
8383
}
8484

@@ -88,7 +88,7 @@ private Map<String, AtomicBoolean> getStoppingVariable() throws NoSuchFieldExcep
8888
*/
8989
@After
9090
public void tearDown() throws Exception {
91-
isNamespaceStopping.computeIfAbsent(NS, k -> new AtomicBoolean(true)).set(true);
91+
namespaceStoppingMap.computeIfAbsent(NS, k -> new AtomicBoolean(true)).set(true);
9292
shutDownThreads();
9393

9494
for (Memento memento : mementos) {
@@ -233,7 +233,7 @@ public void whenStrandedResourcesExist_removeThem() {
233233
new V1PersistentVolumeClaim().metadata(createMetadata(UID, NS, "claim1"));
234234
testSupport.defineResources(service1, service2, volume, claim);
235235

236-
isNamespaceStopping.get(NS).set(false);
236+
namespaceStoppingMap.get(NS).set(false);
237237

238238
readExistingResources();
239239

0 commit comments

Comments
 (0)