From a6d0da174443915c104303e37b52a0da02a0a98f Mon Sep 17 00:00:00 2001 From: Ryan Eberhard Date: Tue, 10 Sep 2024 17:18:07 +0000 Subject: [PATCH] Merge branch 'owls-120944' into 'release/4.2' Correctly record existing resources during operator start See merge request weblogic-cloud/weblogic-kubernetes-operator!4802 (cherry picked from commit 12fc411718bab0873ba6eb17ded83ddda5dcc6c6) 7fc20cf8 Correctly record existing resources during operator start a08aaf40 Restore unit-tests --- .../operator/DomainResourcesValidation.java | 13 +++++-------- .../kubernetes/operator/DomainPresenceTest.java | 8 ++++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/operator/src/main/java/oracle/kubernetes/operator/DomainResourcesValidation.java b/operator/src/main/java/oracle/kubernetes/operator/DomainResourcesValidation.java index 678bb4dc541..61cd2e8c541 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/DomainResourcesValidation.java +++ b/operator/src/main/java/oracle/kubernetes/operator/DomainResourcesValidation.java @@ -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) { @@ -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 getDomainPresenceInfoMap() { return processor.getDomainPresenceInfoMap().computeIfAbsent(namespace, k -> new ConcurrentHashMap<>()); } @@ -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); } } @@ -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); } } @@ -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); diff --git a/operator/src/test/java/oracle/kubernetes/operator/DomainPresenceTest.java b/operator/src/test/java/oracle/kubernetes/operator/DomainPresenceTest.java index 2cbe80432c8..473b0038b3c 100644 --- a/operator/src/test/java/oracle/kubernetes/operator/DomainPresenceTest.java +++ b/operator/src/test/java/oracle/kubernetes/operator/DomainPresenceTest.java @@ -411,7 +411,7 @@ void whenDomainStatusBecameNull_generateDomainCreatedEvent() { } @Test - void whenK8sHasOneDomainWithMissingInfo_dontRecordAdminServerService() { + void whenK8sHasOneDomainWithMissingInfo_recordAdminServerService() { addDomainResource(UID1, NS); V1Service service = createServerService(UID1, NS, "admin"); testSupport.defineResources(service); @@ -419,7 +419,7 @@ void whenK8sHasOneDomainWithMissingInfo_dontRecordAdminServerService() { 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 @@ -467,7 +467,7 @@ void whenK8sDomainWithMoreThanCallRequestLimitNumberOfPods_recordPodsPresence() } @Test - void whenK8sHasOneDomainWithPodButMissingInfo_dontRecordPodPresence() { + void whenK8sHasOneDomainWithPodButMissingInfo_recordPodPresence() { addDomainResource(UID1, NS); V1Pod pod = createPodResource(UID1, NS, "admin"); testSupport.defineResources(pod); @@ -475,7 +475,7 @@ void whenK8sHasOneDomainWithPodButMissingInfo_dontRecordPodPresence() { 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