Skip to content

Commit be450df

Browse files
authored
Ignore NS deleted events for not managed namespaces (#3983)
1 parent 7bfc9b6 commit be450df

File tree

4 files changed

+157
-45
lines changed

4 files changed

+157
-45
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator;
@@ -75,6 +75,10 @@ AtomicBoolean isStopping(String ns) {
7575
return namespaceStoppingMap.computeIfAbsent(ns, key -> new AtomicBoolean(false));
7676
}
7777

78+
AtomicBoolean getStopping(String ns) {
79+
return namespaceStoppingMap.get(ns);
80+
}
81+
7882
boolean isStarting(String ns) {
7983
return Optional.ofNullable(namespaceStatuses.get(ns))
8084
.map(NamespaceStatus::isNamespaceStarting)

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator;
55

6+
import java.util.ArrayList;
67
import java.util.Arrays;
78
import java.util.Collection;
89
import java.util.Collections;
@@ -271,7 +272,7 @@ static class NamespaceListAfterStep extends Step {
271272

272273
@Override
273274
public NextAction apply(Packet packet) {
274-
NamespaceValidationContext validationContext = new NamespaceValidationContext(packet);
275+
NamespaceValidationContext validationContext = new NamespaceValidationContext(packet, domainNamespaces);
275276
getNonNullConfiguredDomainNamespaces().forEach(validationContext::validateConfiguredNamespace);
276277
List<StepAndPacket> nsStopEventSteps = getCreateNSStopEventSteps(packet, validationContext);
277278
stopRemovedNamespaces(validationContext);
@@ -280,18 +281,23 @@ public NextAction apply(Packet packet) {
280281

281282
private List<StepAndPacket> getCreateNSStopEventSteps(Packet packet, NamespaceValidationContext validationContext) {
282283
return domainNamespaces.getNamespaces().stream()
283-
.filter(validationContext::isNoLongerActiveDomainNamespace)
284+
.filter(validationContext::isNotManaged)
284285
.map(n -> createNSStopEventDetails(packet, n)).collect(Collectors.toList());
285286
}
286287

287288
private StepAndPacket createNSStopEventDetails(Packet packet, String namespace) {
288289
LOGGER.info(MessageKeys.END_MANAGING_NAMESPACE, namespace);
289-
return new StepAndPacket(
290-
Step.chain(
291-
createEventStep(new EventData(NAMESPACE_WATCHING_STOPPED).resourceName(namespace).namespace(namespace)),
292-
createEventStep(new EventData(STOP_MANAGING_NAMESPACE).resourceName(namespace)
293-
.namespace(getOperatorNamespace()))),
294-
packet.copy());
290+
return new StepAndPacket(getSteps(namespace), packet.copy());
291+
}
292+
293+
private Step getSteps(String ns) {
294+
List<Step> steps = new ArrayList<>();
295+
if (!domainNamespaces.isStopping(ns).get()) {
296+
steps.add(createEventStep(new EventData(NAMESPACE_WATCHING_STOPPED).resourceName(ns).namespace(ns)));
297+
}
298+
steps.add(createEventStep(
299+
new EventData(STOP_MANAGING_NAMESPACE).resourceName(ns).namespace(getOperatorNamespace())));
300+
return Step.chain(steps.toArray(new Step[0]));
295301
}
296302

297303
private Step createNamespaceWatchStopEventsStep(List<StepAndPacket> nsStopEventDetails) {
@@ -333,9 +339,15 @@ private void stopRemovedNamespaces(NamespaceValidationContext validationContext)
333339
private static class NamespaceValidationContext {
334340

335341
final Collection<String> allDomainNamespaces;
342+
final DomainNamespaces domainNamespaces;
336343

337-
NamespaceValidationContext(Packet packet) {
344+
NamespaceValidationContext(Packet packet, DomainNamespaces domainNamespaces) {
338345
allDomainNamespaces = Optional.ofNullable(getFoundDomainNamespaces(packet)).orElse(Collections.emptyList());
346+
this.domainNamespaces = domainNamespaces;
347+
}
348+
349+
private boolean isNotManaged(String ns) {
350+
return !allDomainNamespaces.contains(ns) || domainNamespaces.isStopping(ns).get();
339351
}
340352

341353
private boolean isNoLongerActiveDomainNamespace(String ns) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2017, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator;
@@ -445,7 +445,7 @@ void dispatchNamespaceWatch(Watch.Response<V1Namespace> item) {
445445
case "DELETED":
446446
// Mark the namespace as isStopping, which will cause the namespace be stopped
447447
// the next time when recheckDomains is triggered
448-
mainDelegate.getDomainNamespaces().isStopping(ns).set(true);
448+
Optional.ofNullable(mainDelegate.getDomainNamespaces().getStopping(ns)).ifPresent(n -> n.set(true));
449449

450450
break;
451451

0 commit comments

Comments
 (0)