Skip to content

Commit

Permalink
Merge branch 'owls-120944' into 'release/4.2'
Browse files Browse the repository at this point in the history
Correctly record existing resources during operator start

See merge request weblogic-cloud/weblogic-kubernetes-operator!4802

(cherry picked from commit 12fc411)

7fc20cf8 Correctly record existing resources during operator start
a08aaf40 Restore unit-tests
  • Loading branch information
rjeberhard committed Sep 10, 2024
1 parent 6a1db4c commit a6d0da1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void addOperatorEventList(CoreV1EventList list) {
private void addPod(V1Pod pod) {
String domainUid = PodHelper.getPodDomainUid(pod);
String serverName = PodHelper.getPodServerName(pod);
DomainPresenceInfo info = getExistingDomainPresenceInfo(domainUid);
DomainPresenceInfo info = getOrComputeDomainPresenceInfo(domainUid);
Optional.ofNullable(info).ifPresent(i -> i.addServerNameFromPodList(serverName));

if (domainUid != null && serverName != null) {
Expand All @@ -178,10 +178,6 @@ private DomainPresenceInfo getOrComputeDomainPresenceInfo(String domainUid) {
return getDomainPresenceInfoMap().computeIfAbsent(domainUid, k -> new DomainPresenceInfo(namespace, domainUid));
}

private DomainPresenceInfo getExistingDomainPresenceInfo(String domainUid) {
return getDomainPresenceInfoMap().get(domainUid);
}

private Map<String, DomainPresenceInfo> getDomainPresenceInfoMap() {
return processor.getDomainPresenceInfoMap().computeIfAbsent(namespace, k -> new ConcurrentHashMap<>());
}
Expand All @@ -197,7 +193,7 @@ private void addServiceList(V1ServiceList list) {
private void addService(V1Service service) {
String domainUid = ServiceHelper.getServiceDomainUid(service);
if (domainUid != null) {
ServiceHelper.addToPresence(getExistingDomainPresenceInfo(domainUid), service);
ServiceHelper.addToPresence(getOrComputeDomainPresenceInfo(domainUid), service);
}
}

Expand All @@ -208,7 +204,7 @@ private void addPodDisruptionBudgetList(V1PodDisruptionBudgetList list) {
private void addPodDisruptionBudget(V1PodDisruptionBudget pdb) {
String domainUid = PodDisruptionBudgetHelper.getDomainUid(pdb);
if (domainUid != null) {
PodDisruptionBudgetHelper.addToPresence(getExistingDomainPresenceInfo(domainUid), pdb);
PodDisruptionBudgetHelper.addToPresence(getOrComputeDomainPresenceInfo(domainUid), pdb);
}
}

Expand Down Expand Up @@ -236,7 +232,8 @@ private void addDomain(DomainResource domain) {
DomainPresenceInfo cachedInfo = getDomainPresenceInfoMap().get(domain.getDomainUid());
if (domain.getStatus() == null) {
newDomainNames.add(domain.getDomainUid());
} else if (cachedInfo != null && domain.isGenerationChanged(cachedInfo.getDomain())) {
} else if (cachedInfo != null && cachedInfo.getDomain() != null
&& domain.isGenerationChanged(cachedInfo.getDomain())) {
modifiedDomainNames.add(domain.getDomainUid());
}
getOrComputeDomainPresenceInfo(domain.getDomainUid()).setDomain(domain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,15 @@ void whenDomainStatusBecameNull_generateDomainCreatedEvent() {
}

@Test
void whenK8sHasOneDomainWithMissingInfo_dontRecordAdminServerService() {
void whenK8sHasOneDomainWithMissingInfo_recordAdminServerService() {
addDomainResource(UID1, NS);
V1Service service = createServerService(UID1, NS, "admin");
testSupport.defineResources(service);

testSupport.addToPacket(ProcessingConstants.DOMAIN_PROCESSOR, dp);
testSupport.runSteps(domainNamespaces.readExistingResources(NS, dp));

assertThat(getDomainPresenceInfo(dp, UID1).getServerService("admin"), equalTo(null));
assertThat(getDomainPresenceInfo(dp, UID1).getServerService("admin"), equalTo(service));
}

@Test
Expand Down Expand Up @@ -467,15 +467,15 @@ void whenK8sDomainWithMoreThanCallRequestLimitNumberOfPods_recordPodsPresence()
}

@Test
void whenK8sHasOneDomainWithPodButMissingInfo_dontRecordPodPresence() {
void whenK8sHasOneDomainWithPodButMissingInfo_recordPodPresence() {
addDomainResource(UID1, NS);
V1Pod pod = createPodResource(UID1, NS, "admin");
testSupport.defineResources(pod);

testSupport.addToPacket(ProcessingConstants.DOMAIN_PROCESSOR, dp);
testSupport.runSteps(domainNamespaces.readExistingResources(NS, dp));

assertThat(getDomainPresenceInfo(dp, UID1).getServerPod("admin"), equalTo(null));
assertThat(getDomainPresenceInfo(dp, UID1).getServerPod("admin"), equalTo(pod));
}

@Test
Expand Down

0 comments on commit a6d0da1

Please sign in to comment.