Skip to content

Commit 94014dd

Browse files
authored
Owls88697 stop namespaces that no longer managed by operator when change to dedicated strategy (#2345)
* add NamespaceListAfterStep to dedicated case to clean up domains * unit test use recheckDomains when testing a specific strategy * unit test use createReadNamespacesStep in strategy specific cases
1 parent 02513eb commit 94014dd

File tree

6 files changed

+213
-70
lines changed

6 files changed

+213
-70
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItKubernetesEvents.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,8 @@ public void testK8SEventsStartStopWatchingNSWithDedicated() {
710710
logger.info("verify NamespaceWatchingStarted event is logged in {0}", opNamespace);
711711
checkEvent(opNamespace, opNamespace, null, NAMESPACE_WATCHING_STARTED, "Normal", timestamp);
712712

713-
// TODO: enable the following check when https://jira.oraclecorp.com/jira/browse/OWLS-87181 is fixed
714-
//logger.info("verify NamespaceWatchingStopped event is logged in {0}", domainNamespace4);
715-
//checkNamespaceWatchingStoppedEvent(opNamespace, domainNamespace4, null, "Normal", timestamp, false);
713+
logger.info("verify NamespaceWatchingStopped event is logged in {0}", domainNamespace4);
714+
checkNamespaceWatchingStoppedEvent(opNamespace, domainNamespace4, null, "Normal", timestamp, false);
716715
}
717716

718717
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ void stopNamespace(String ns) {
118118
podDisruptionBudgetWatchers.removeWatcher(ns);
119119
configMapWatchers.removeWatcher(ns);
120120
jobWatchers.removeWatcher(ns);
121+
122+
DomainProcessorImpl.cleanupNamespace(ns);
121123
}
122124

123125
ConfigMapWatcher getConfigMapWatcher(String namespace) {

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,30 @@ private static DomainPresenceInfo getExistingDomainPresenceInfo(String ns, Strin
122122
return DOMAINS.computeIfAbsent(ns, k -> new ConcurrentHashMap<>()).get(domainUid);
123123
}
124124

125+
static void cleanupNamespace(String namespace) {
126+
DOMAINS.remove(namespace);
127+
domainEventK8SObjects.remove(namespace);
128+
namespaceEventK8SObjects.remove(namespace);
129+
statusUpdaters.remove((namespace));
130+
}
131+
125132
static void registerDomainPresenceInfo(DomainPresenceInfo info) {
126133
DOMAINS
127134
.computeIfAbsent(info.getNamespace(), k -> new ConcurrentHashMap<>())
128135
.put(info.getDomainUid(), info);
129136
}
130137

131138
private static void unregisterPresenceInfo(String ns, String domainUid) {
132-
Map<String, DomainPresenceInfo> map = DOMAINS.get(ns);
133-
if (map != null) {
134-
map.remove(domainUid);
135-
}
139+
Optional.ofNullable(DOMAINS.get(ns)).map(m -> m.remove(domainUid));
140+
}
141+
142+
private static void unregisterEventK8SObject(String ns, String domainUid) {
143+
Optional.ofNullable(domainEventK8SObjects.get(ns)).map(m -> m.remove(domainUid));
144+
}
145+
146+
private static void unregisterDomain(String ns, String domainUid) {
147+
unregisterPresenceInfo(ns, domainUid);
148+
unregisterEventK8SObject(ns, domainUid);
136149
}
137150

138151
private static void registerStatusUpdater(
@@ -1190,7 +1203,7 @@ private static class UnregisterStep extends Step {
11901203

11911204
@Override
11921205
public NextAction apply(Packet packet) {
1193-
unregisterPresenceInfo(info.getNamespace(), info.getDomainUid());
1206+
unregisterDomain(info.getNamespace(), info.getDomainUid());
11941207
return doNext(packet);
11951208
}
11961209
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ class ReadNamespacesStepsVisitor implements NamespaceStrategyVisitor<Step> {
128128

129129
@Override
130130
public Step getDedicatedStrategySelection() {
131-
return createStartNamespacesStep(Collections.singletonList(getOperatorNamespace()));
131+
return Step.chain(new Namespaces.NamespaceListAfterStep(domainNamespaces),
132+
createStartNamespacesStep(Collections.singletonList(getOperatorNamespace())));
132133
}
133134

134135
@Override

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import javax.annotation.Nonnull;
1717
import javax.annotation.Nullable;
1818

19+
import jakarta.validation.constraints.NotNull;
1920
import oracle.kubernetes.operator.helpers.EventHelper.EventData;
2021
import oracle.kubernetes.operator.helpers.HelmAccess;
2122
import oracle.kubernetes.operator.helpers.NamespaceHelper;
@@ -60,6 +61,12 @@ static boolean isDomainNamespace(String ns) {
6061
return getSelectionStrategy().getConfiguredDomainNamespaces();
6162
}
6263

64+
/**
65+
* Returns a (possibly empty) collection of strings which designate namespaces for the operator to manage.
66+
*/
67+
static @NotNull Collection<String> getFoundDomainNamespaces(Packet packet) {
68+
return getSelectionStrategy().getFoundDomainNamespaces(packet);
69+
}
6370

6471
/**
6572
* Returns an array of the label selectors that will determine that a namespace is being used to manage domains.
@@ -157,6 +164,11 @@ public Collection<String> getConfiguredDomainNamespaces() {
157164
public <V> V getSelection(NamespaceStrategyVisitor<V> visitor) {
158165
return visitor.getDedicatedStrategySelection();
159166
}
167+
168+
@Override
169+
public Collection<String> getFoundDomainNamespaces(Packet packet) {
170+
return Collections.singleton(getOperatorNamespace());
171+
}
160172
};
161173

162174
static final String[] NO_SELECTORS = new String[0];
@@ -174,22 +186,23 @@ public String[] getLabelSelectors() {
174186
public abstract <V> V getSelection(NamespaceStrategyVisitor<V> visitor);
175187

176188
private static final Map<String, Pattern> compiledPatterns = new WeakHashMap<>();
177-
}
178189

179-
/**
180-
* Returns a modifiable collection of found namespace names in a packet.
181-
* Callers should use this to add to the collection.
182-
*
183-
* @param packet the packet passed to a step
184-
*/
185-
@SuppressWarnings("unchecked")
186-
static Collection<String> getFoundDomainNamespaces(Packet packet) {
187-
if (!packet.containsKey(ALL_DOMAIN_NAMESPACES)) {
188-
packet.put(ALL_DOMAIN_NAMESPACES, new HashSet<>());
190+
/**
191+
* Returns a modifiable collection of found namespace names in a packet.
192+
* Callers should use this to add to the collection.
193+
*
194+
* @param packet the packet passed to a step
195+
*/
196+
@SuppressWarnings("unchecked")
197+
Collection<String> getFoundDomainNamespaces(Packet packet) {
198+
if (!packet.containsKey(ALL_DOMAIN_NAMESPACES)) {
199+
packet.put(ALL_DOMAIN_NAMESPACES, new HashSet<>());
200+
}
201+
return (Collection<String>) packet.get(ALL_DOMAIN_NAMESPACES);
189202
}
190-
return (Collection<String>) packet.get(ALL_DOMAIN_NAMESPACES);
191203
}
192204

205+
193206
/**
194207
* Gets the configured domain namespace selection strategy.
195208
*
@@ -271,9 +284,6 @@ public NextAction apply(Packet packet) {
271284
return doForkJoin(getNext(), packet, nsStopEventDetails);
272285
}
273286
}
274-
275-
276-
277287
}
278288

279289
@Nonnull

0 commit comments

Comments
 (0)