Skip to content

Owls88697 stop namespaces that no longer managed by operator when change to dedicated strategy #2345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 4, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,8 @@ public void testK8SEventsStartStopWatchingNSWithDedicated() {
logger.info("verify NamespaceWatchingStarted event is logged in {0}", opNamespace);
checkEvent(opNamespace, opNamespace, null, NAMESPACE_WATCHING_STARTED, "Normal", timestamp);

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ void stopNamespace(String ns) {
podDisruptionBudgetWatchers.removeWatcher(ns);
configMapWatchers.removeWatcher(ns);
jobWatchers.removeWatcher(ns);

DomainProcessorImpl.cleanupNamespace(ns);
}

ConfigMapWatcher getConfigMapWatcher(String namespace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,30 @@ private static DomainPresenceInfo getExistingDomainPresenceInfo(String ns, Strin
return DOMAINS.computeIfAbsent(ns, k -> new ConcurrentHashMap<>()).get(domainUid);
}

static void cleanupNamespace(String namespace) {
DOMAINS.remove(namespace);
domainEventK8SObjects.remove(namespace);
namespaceEventK8SObjects.remove(namespace);
statusUpdaters.remove((namespace));
}

static void registerDomainPresenceInfo(DomainPresenceInfo info) {
DOMAINS
.computeIfAbsent(info.getNamespace(), k -> new ConcurrentHashMap<>())
.put(info.getDomainUid(), info);
}

private static void unregisterPresenceInfo(String ns, String domainUid) {
Map<String, DomainPresenceInfo> map = DOMAINS.get(ns);
if (map != null) {
map.remove(domainUid);
}
Optional.ofNullable(DOMAINS.get(ns)).map(m -> m.remove(domainUid));
}

private static void unregisterEventK8SObject(String ns, String domainUid) {
Optional.ofNullable(domainEventK8SObjects.get(ns)).map(m -> m.remove(domainUid));
}

private static void unregisterDomain(String ns, String domainUid) {
unregisterPresenceInfo(ns, domainUid);
unregisterEventK8SObject(ns, domainUid);
}

private static void registerStatusUpdater(
Expand Down Expand Up @@ -1189,7 +1202,7 @@ private static class UnregisterStep extends Step {

@Override
public NextAction apply(Packet packet) {
unregisterPresenceInfo(info.getNamespace(), info.getDomainUid());
unregisterDomain(info.getNamespace(), info.getDomainUid());
return doNext(packet);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class ReadNamespacesStepsVisitor implements NamespaceStrategyVisitor<Step> {

@Override
public Step getDedicatedStrategySelection() {
return createStartNamespacesStep(Collections.singletonList(getOperatorNamespace()));
return Step.chain(new Namespaces.NamespaceListAfterStep(domainNamespaces),
createStartNamespacesStep(Collections.singletonList(getOperatorNamespace())));
}

@Override
Expand Down
40 changes: 25 additions & 15 deletions operator/src/main/java/oracle/kubernetes/operator/Namespaces.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import jakarta.validation.constraints.NotNull;
import oracle.kubernetes.operator.helpers.EventHelper.EventData;
import oracle.kubernetes.operator.helpers.HelmAccess;
import oracle.kubernetes.operator.helpers.NamespaceHelper;
Expand Down Expand Up @@ -60,6 +61,12 @@ static boolean isDomainNamespace(String ns) {
return getSelectionStrategy().getConfiguredDomainNamespaces();
}

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

/**
* Returns an array of the label selectors that will determine that a namespace is being used to manage domains.
Expand Down Expand Up @@ -157,6 +164,11 @@ public Collection<String> getConfiguredDomainNamespaces() {
public <V> V getSelection(NamespaceStrategyVisitor<V> visitor) {
return visitor.getDedicatedStrategySelection();
}

@Override
public Collection<String> getFoundDomainNamespaces(Packet packet) {
return Collections.singleton(getOperatorNamespace());
}
};

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

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

/**
* Returns a modifiable collection of found namespace names in a packet.
* Callers should use this to add to the collection.
*
* @param packet the packet passed to a step
*/
@SuppressWarnings("unchecked")
static Collection<String> getFoundDomainNamespaces(Packet packet) {
if (!packet.containsKey(ALL_DOMAIN_NAMESPACES)) {
packet.put(ALL_DOMAIN_NAMESPACES, new HashSet<>());
/**
* Returns a modifiable collection of found namespace names in a packet.
* Callers should use this to add to the collection.
*
* @param packet the packet passed to a step
*/
@SuppressWarnings("unchecked")
Collection<String> getFoundDomainNamespaces(Packet packet) {
if (!packet.containsKey(ALL_DOMAIN_NAMESPACES)) {
packet.put(ALL_DOMAIN_NAMESPACES, new HashSet<>());
}
return (Collection<String>) packet.get(ALL_DOMAIN_NAMESPACES);
}
return (Collection<String>) packet.get(ALL_DOMAIN_NAMESPACES);
}


/**
* Gets the configured domain namespace selection strategy.
*
Expand Down Expand Up @@ -271,9 +284,6 @@ public NextAction apply(Packet packet) {
return doForkJoin(getNext(), packet, nsStopEventDetails);
}
}



}

@Nonnull
Expand Down
Loading