Skip to content

Commit 12fc411

Browse files
committed
Merge branch 'owls-120944' into 'release/4.2'
Correctly record existing resources during operator start See merge request weblogic-cloud/weblogic-kubernetes-operator!4802
2 parents 6046991 + 8e619e9 commit 12fc411

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2024, 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;
@@ -154,7 +154,7 @@ private void addOperatorEventList(CoreV1EventList list) {
154154
private void addPod(V1Pod pod) {
155155
String domainUid = PodHelper.getPodDomainUid(pod);
156156
String serverName = PodHelper.getPodServerName(pod);
157-
DomainPresenceInfo info = getExistingDomainPresenceInfo(domainUid);
157+
DomainPresenceInfo info = getOrComputeDomainPresenceInfo(domainUid);
158158
Optional.ofNullable(info).ifPresent(i -> i.addServerNameFromPodList(serverName));
159159

160160
if (domainUid != null && serverName != null) {
@@ -173,10 +173,6 @@ private DomainPresenceInfo getOrComputeDomainPresenceInfo(String domainUid) {
173173
return getDomainPresenceInfoMap().computeIfAbsent(domainUid, k -> new DomainPresenceInfo(namespace, domainUid));
174174
}
175175

176-
private DomainPresenceInfo getExistingDomainPresenceInfo(String domainUid) {
177-
return getDomainPresenceInfoMap().get(domainUid);
178-
}
179-
180176
private Map<String, DomainPresenceInfo> getDomainPresenceInfoMap() {
181177
return processor.getDomainPresenceInfoMap().computeIfAbsent(namespace, k -> new ConcurrentHashMap<>());
182178
}
@@ -192,7 +188,7 @@ private void addServiceList(V1ServiceList list) {
192188
private void addService(V1Service service) {
193189
String domainUid = ServiceHelper.getServiceDomainUid(service);
194190
if (domainUid != null) {
195-
ServiceHelper.addToPresence(getExistingDomainPresenceInfo(domainUid), service);
191+
ServiceHelper.addToPresence(getOrComputeDomainPresenceInfo(domainUid), service);
196192
}
197193
}
198194

@@ -203,7 +199,7 @@ private void addPodDisruptionBudgetList(V1PodDisruptionBudgetList list) {
203199
private void addPodDisruptionBudget(V1PodDisruptionBudget pdb) {
204200
String domainUid = PodDisruptionBudgetHelper.getDomainUid(pdb);
205201
if (domainUid != null) {
206-
PodDisruptionBudgetHelper.addToPresence(getExistingDomainPresenceInfo(domainUid), pdb);
202+
PodDisruptionBudgetHelper.addToPresence(getOrComputeDomainPresenceInfo(domainUid), pdb);
207203
}
208204
}
209205

@@ -231,7 +227,8 @@ private void addDomain(DomainResource domain) {
231227
DomainPresenceInfo cachedInfo = getDomainPresenceInfoMap().get(domain.getDomainUid());
232228
if (domain.getStatus() == null) {
233229
newDomainNames.add(domain.getDomainUid());
234-
} else if (cachedInfo != null && domain.isGenerationChanged(cachedInfo.getDomain())) {
230+
} else if (cachedInfo != null && cachedInfo.getDomain() != null
231+
&& domain.isGenerationChanged(cachedInfo.getDomain())) {
235232
modifiedDomainNames.add(domain.getDomainUid());
236233
}
237234
getOrComputeDomainPresenceInfo(domain.getDomainUid()).setDomain(domain);

operator/src/test/java/oracle/kubernetes/operator/DomainPresenceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2024, 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;
@@ -410,15 +410,15 @@ void whenDomainStatusBecameNull_generateDomainCreatedEvent() {
410410
}
411411

412412
@Test
413-
void whenK8sHasOneDomainWithMissingInfo_dontRecordAdminServerService() {
413+
void whenK8sHasOneDomainWithMissingInfo_recordAdminServerService() {
414414
addDomainResource(UID1, NS);
415415
V1Service service = createServerService(UID1, NS, "admin");
416416
testSupport.defineResources(service);
417417

418418
testSupport.addComponent("DP", DomainProcessor.class, dp);
419419
testSupport.runSteps(domainNamespaces.readExistingResources(NS, dp));
420420

421-
assertThat(getDomainPresenceInfo(dp, UID1).getServerService("admin"), equalTo(null));
421+
assertThat(getDomainPresenceInfo(dp, UID1).getServerService("admin"), equalTo(service));
422422
}
423423

424424
@Test
@@ -466,15 +466,15 @@ void whenK8sDomainWithMoreThanCallRequestLimitNumberOfPods_recordPodsPresence()
466466
}
467467

468468
@Test
469-
void whenK8sHasOneDomainWithPodButMissingInfo_dontRecordPodPresence() {
469+
void whenK8sHasOneDomainWithPodButMissingInfo_recordPodPresence() {
470470
addDomainResource(UID1, NS);
471471
V1Pod pod = createPodResource(UID1, NS, "admin");
472472
testSupport.defineResources(pod);
473473

474474
testSupport.addComponent("DP", DomainProcessor.class, dp);
475475
testSupport.runSteps(domainNamespaces.readExistingResources(NS, dp));
476476

477-
assertThat(getDomainPresenceInfo(dp, UID1).getServerPod("admin"), equalTo(null));
477+
assertThat(getDomainPresenceInfo(dp, UID1).getServerPod("admin"), equalTo(pod));
478478
}
479479

480480
@Test

0 commit comments

Comments
 (0)