Skip to content

Commit 35ec49a

Browse files
committed
Merge remote-tracking branch 'origin/develop' into domain-introspector
2 parents 2351af5 + 098327d commit 35ec49a

24 files changed

+945
-483
lines changed

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

Lines changed: 338 additions & 176 deletions
Large diffs are not rendered by default.

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

Lines changed: 93 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.StringTokenizer;
2525
import java.util.TreeSet;
2626
import java.util.concurrent.ConcurrentHashMap;
27+
import java.util.concurrent.ConcurrentMap;
2728
import java.util.concurrent.ScheduledExecutorService;
2829
import java.util.concurrent.ThreadFactory;
2930
import java.util.concurrent.TimeUnit;
@@ -66,6 +67,8 @@ private static ThreadFactory getThreadFactory() {
6667

6768
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
6869

70+
private static final String NS_STARTING_NOW = "NS_STARTING_NOW";
71+
6972
static final TuningParameters tuningAndConfig;
7073

7174
static {
@@ -101,7 +104,8 @@ private static ThreadFactory getThreadFactory() {
101104

102105
static final Engine engine = new Engine(wrappedExecutorService);
103106

104-
static final Map<String, AtomicBoolean> isNamespaceStopping = new ConcurrentHashMap<>();
107+
static final ConcurrentMap<String, AtomicBoolean> isNamespaceStarted = new ConcurrentHashMap<>();
108+
static final ConcurrentMap<String, AtomicBoolean> isNamespaceStopping = new ConcurrentHashMap<>();
105109

106110
private static final Map<String, ConfigMapWatcher> configMapWatchers = new ConcurrentHashMap<>();
107111
private static final Map<String, DomainWatcher> domainWatchers = new ConcurrentHashMap<>();
@@ -121,12 +125,12 @@ private static ThreadFactory getThreadFactory() {
121125
static final String READINESS_PROBE_FAILURE_EVENT_FILTER =
122126
"reason=Unhealthy,type=Warning,involvedObject.fieldPath=spec.containers{weblogic-server}";
123127

124-
static Map<String, DomainPresenceInfo> getDomainPresenceInfos() {
125-
return DomainPresenceInfoManager.getDomainPresenceInfos();
128+
static Map<String, DomainPresenceInfo> getDomainPresenceInfos(String ns) {
129+
return DomainPresenceInfoManager.getDomainPresenceInfos(ns);
126130
}
127131

128-
static ServerKubernetesObjects getKubernetesObjects(String serverLegalName) {
129-
return ServerKubernetesObjectsManager.lookup(serverLegalName);
132+
static Map<String, ServerKubernetesObjects> getKubernetesObjects(String ns) {
133+
return ServerKubernetesObjectsManager.getServerKubernetesObjects(ns);
130134
}
131135

132136
/**
@@ -205,8 +209,6 @@ private static void begin() {
205209
}
206210

207211
private static void completeBegin() {
208-
DomainProcessor.deleteStrandedResources();
209-
210212
try {
211213
// start the REST server
212214
startRestServer(principal, isNamespaceStopping.keySet());
@@ -263,7 +265,11 @@ private static class StartNamespaceBeforeStep extends Step {
263265

264266
@Override
265267
public NextAction apply(Packet packet) {
266-
if (isNamespaceStopping.putIfAbsent(ns, new AtomicBoolean(false)) == null) {
268+
AtomicBoolean a = isNamespaceStarted.computeIfAbsent(ns, (key) -> new AtomicBoolean(false));
269+
boolean startingNow = !a.getAndSet(true);
270+
packet.put(NS_STARTING_NOW, (Boolean) startingNow);
271+
272+
if (startingNow) {
267273
try {
268274
HealthCheckHelper.performSecurityChecks(version, operatorNamespace, ns);
269275
} catch (Throwable e) {
@@ -282,13 +288,12 @@ private static void stopNamespaces(Collection<String> namespacesToStop) {
282288
if (stopping != null) {
283289
stopping.set(true);
284290
}
291+
isNamespaceStarted.remove(ns);
285292
}
286293
}
287294

288-
private static final AtomicBoolean UNINITIALIZED_NS_STOPPING = new AtomicBoolean(true);
289-
290295
static AtomicBoolean isNamespaceStopping(String ns) {
291-
return isNamespaceStopping.getOrDefault(ns, UNINITIALIZED_NS_STOPPING);
296+
return isNamespaceStopping.computeIfAbsent(ns, (key) -> new AtomicBoolean(false));
292297
}
293298

294299
static void runSteps(Step firstStep) {
@@ -312,7 +317,7 @@ private static Runnable recheckDomains() {
312317
namespacesToStop.removeAll(targetNamespaces);
313318
stopNamespaces(namespacesToStop);
314319

315-
runSteps(new StartNamespacesStep(targetNamespaces), DomainProcessor::deleteStrandedResources);
320+
runSteps(new StartNamespacesStep(targetNamespaces));
316321
};
317322
}
318323

@@ -468,7 +473,7 @@ static String getOperatorNamespace() {
468473
return namespace;
469474
}
470475

471-
private static Collection<String> getTargetNamespaces() {
476+
public static Collection<String> getTargetNamespaces() {
472477
String namespace = getOperatorNamespace();
473478

474479
return getTargetNamespaces(tuningAndConfig.get("targetNamespaces"), namespace);
@@ -529,30 +534,33 @@ public NextAction onFailure(Packet packet, CallResponse<DomainList> callResponse
529534

530535
@Override
531536
public NextAction onSuccess(Packet packet, CallResponse<DomainList> callResponse) {
537+
Boolean startingNow = (Boolean) packet.get(NS_STARTING_NOW);
538+
if (startingNow == null) {
539+
startingNow = Boolean.TRUE;
540+
}
541+
532542
Set<String> domainUIDs = new HashSet<>();
533543
if (callResponse.getResult() != null) {
534544
for (Domain dom : callResponse.getResult().getItems()) {
535545
String domainUID = dom.getSpec().getDomainUID();
536546
domainUIDs.add(domainUID);
537547
DomainPresenceInfo info = DomainPresenceInfoManager.getOrCreate(dom);
538-
if (isNamespaceStopping(dom.getMetadata().getNamespace()).get()) {
548+
if (startingNow) {
539549
// Update domain here if namespace is not yet running
540550
info.setDomain(dom);
541551
}
542-
DomainProcessor.makeRightDomainPresence(info, dom, true, false, false);
552+
DomainProcessor.makeRightDomainPresence(info, domainUID, dom, true, false, false);
543553
}
544554
}
545555

546-
getDomainPresenceInfos()
556+
getDomainPresenceInfos(ns)
547557
.forEach(
548558
(key, value) -> {
549-
Domain d = value.getDomain();
550-
if (d != null && ns.equals(d.getMetadata().getNamespace())) {
551-
if (!domainUIDs.contains(d.getSpec().getDomainUID())) {
552-
// This is a stranded DomainPresenceInfo. Clear the Domain reference
553-
// so that stranded resources are marked for clean-up.
554-
value.setDomain(null);
555-
}
559+
if (!domainUIDs.contains(key)) {
560+
// This is a stranded DomainPresenceInfo.
561+
value.setDeleting(true);
562+
Domain dom = value.getDomain();
563+
DomainProcessor.makeRightDomainPresence(value, key, dom, true, true, false);
556564
}
557565
});
558566

@@ -594,23 +602,66 @@ public NextAction onFailure(Packet packet, CallResponse<V1ServiceList> callRespo
594602
@Override
595603
public NextAction onSuccess(Packet packet, CallResponse<V1ServiceList> callResponse) {
596604
V1ServiceList result = callResponse.getResult();
605+
606+
Set<String> serviceNames = new HashSet<>();
607+
Set<String> channelNames = new HashSet<>();
608+
Set<String> clusterNames = new HashSet<>();
597609
if (result != null) {
598610
for (V1Service service : result.getItems()) {
599611
String domainUID = ServiceWatcher.getServiceDomainUID(service);
600612
String serverName = ServiceWatcher.getServiceServerName(service);
601613
String channelName = ServiceWatcher.getServiceChannelName(service);
602-
if (domainUID != null && serverName != null) {
614+
String clusterName = ServiceWatcher.getServiceClusterName(service);
615+
if (domainUID != null) {
603616
DomainPresenceInfo info = DomainPresenceInfoManager.getOrCreate(ns, domainUID);
604-
ServerKubernetesObjects sko =
605-
ServerKubernetesObjectsManager.getOrCreate(info, domainUID, serverName);
606-
if (channelName != null) {
607-
sko.getChannels().put(channelName, service);
608-
} else {
609-
sko.getService().set(service);
617+
if (clusterName != null) {
618+
clusterNames.add(clusterName);
619+
info.getClusters().put(clusterName, service);
620+
} else if (serverName != null) {
621+
ServerKubernetesObjects sko =
622+
ServerKubernetesObjectsManager.getOrCreate(info, domainUID, serverName);
623+
if (channelName != null) {
624+
channelNames.add(channelName);
625+
sko.getChannels().put(channelName, service);
626+
} else {
627+
serviceNames.add(service.getMetadata().getName());
628+
sko.getService().set(service);
629+
}
610630
}
611631
}
612632
}
613633
}
634+
635+
getDomainPresenceInfos(ns)
636+
.forEach(
637+
(key, value) -> {
638+
ConcurrentMap<String, V1Service> map = value.getClusters();
639+
map.forEach(
640+
(ckey, cvalue) -> {
641+
map.compute(
642+
ckey,
643+
(k, current) -> {
644+
return clusterNames.contains(ckey) ? current : null;
645+
});
646+
});
647+
});
648+
getKubernetesObjects(ns)
649+
.forEach(
650+
(key, value) -> {
651+
if (!serviceNames.contains(key)) {
652+
value.getService().set(null);
653+
}
654+
ConcurrentMap<String, V1Service> map = value.getChannels();
655+
map.forEach(
656+
(ckey, cvalue) -> {
657+
map.compute(
658+
ckey,
659+
(k, current) -> {
660+
return channelNames.contains(ckey) ? current : null;
661+
});
662+
});
663+
});
664+
614665
if (!serviceWatchers.containsKey(ns)) {
615666
serviceWatchers.put(ns, createServiceWatcher(ns, getInitialResourceVersion(result)));
616667
}
@@ -669,18 +720,30 @@ public NextAction onFailure(Packet packet, CallResponse<V1PodList> callResponse)
669720
@Override
670721
public NextAction onSuccess(Packet packet, CallResponse<V1PodList> callResponse) {
671722
V1PodList result = callResponse.getResult();
723+
724+
Set<String> podNames = new HashSet<>();
672725
if (result != null) {
673726
for (V1Pod pod : result.getItems()) {
674727
String domainUID = PodWatcher.getPodDomainUID(pod);
675728
String serverName = PodWatcher.getPodServerName(pod);
676729
if (domainUID != null && serverName != null) {
730+
podNames.add(pod.getMetadata().getName());
677731
DomainPresenceInfo info = DomainPresenceInfoManager.getOrCreate(ns, domainUID);
678732
ServerKubernetesObjects sko =
679733
ServerKubernetesObjectsManager.getOrCreate(info, domainUID, serverName);
680734
sko.getPod().set(pod);
681735
}
682736
}
683737
}
738+
739+
getKubernetesObjects(ns)
740+
.forEach(
741+
(key, value) -> {
742+
if (!podNames.contains(key)) {
743+
value.getPod().set(null);
744+
}
745+
});
746+
684747
if (!podWatchers.containsKey(ns)) {
685748
podWatchers.put(ns, createPodWatcher(ns, getInitialResourceVersion(result)));
686749
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
import oracle.kubernetes.operator.work.Step;
3535

3636
/** Watches for Pods to become Ready or leave Ready state */
37-
public class PodWatcher extends Watcher<V1Pod> implements WatchListener<V1Pod> {
37+
public class PodWatcher extends Watcher<V1Pod>
38+
implements WatchListener<V1Pod>, PodAwaiterStepFactory {
3839
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
3940

4041
private final String ns;
@@ -93,7 +94,8 @@ public void receivedResponse(Watch.Response<V1Pod> item) {
9394
Boolean isReady = isReady(pod);
9495
String podName = pod.getMetadata().getName();
9596
Container c = ContainerResolver.getInstance().getContainer();
96-
ServerKubernetesObjects sko = ServerKubernetesObjectsManager.lookup(podName);
97+
ServerKubernetesObjects sko =
98+
ServerKubernetesObjectsManager.lookup(pod.getMetadata().getNamespace(), podName);
9799
if (sko != null) {
98100
sko.getLastKnownStatus().set(isReady ? WebLogicConstants.RUNNING_STATE : null);
99101
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,13 @@ static String getServiceChannelName(V1Service service) {
7474
}
7575
return null;
7676
}
77+
78+
static String getServiceClusterName(V1Service service) {
79+
V1ObjectMeta meta = service.getMetadata();
80+
Map<String, String> labels = meta.getLabels();
81+
if (labels != null) {
82+
return labels.get(LabelConstants.CLUSTERNAME_LABEL);
83+
}
84+
return null;
85+
}
7786
}

0 commit comments

Comments
 (0)