From e54b17459ad6973f7da333b0a185793ba8db0c18 Mon Sep 17 00:00:00 2001 From: Anil Kedia Date: Tue, 21 Dec 2021 14:53:21 +0000 Subject: [PATCH 1/2] Backport fix for OWLS-94649 to 3.3 release. --- .../operator/DomainProcessorImpl.java | 43 ++++++++++ .../kubernetes/operator/PodWatcher.java | 13 +++ .../operator/ProcessingConstants.java | 1 + .../operator/helpers/JobHelper.java | 33 +++++++- .../operator/DomainProcessorTest.java | 79 +++++++++++++++++++ .../helpers/IntrospectionStatusTest.java | 45 +++++++++-- 6 files changed, 204 insertions(+), 10 deletions(-) diff --git a/operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java b/operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java index 833867c645a..9edea2ccb0a 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java +++ b/operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java @@ -23,6 +23,7 @@ import io.kubernetes.client.openapi.models.CoreV1Event; import io.kubernetes.client.openapi.models.V1ConfigMap; import io.kubernetes.client.openapi.models.V1ContainerState; +import io.kubernetes.client.openapi.models.V1ContainerStateWaiting; import io.kubernetes.client.openapi.models.V1ContainerStatus; import io.kubernetes.client.openapi.models.V1ObjectMeta; import io.kubernetes.client.openapi.models.V1ObjectReference; @@ -1380,6 +1381,16 @@ private void invoke() { DomainStatusUpdater.createFailureRelatedSteps( info, waiting.getReason(), waiting.getMessage(), null))); break; + case INIT_CONTAINERS_NOT_READY: + List waitingMessages = new ArrayList<>(); + List waitingReasons = new ArrayList<>(); + + getInitContainersWaitingReasonsAndMessages(introspectorPod, waitingReasons, waitingMessages); + if (!waitingReasons.isEmpty()) { + delegate.runSteps(DomainStatusUpdater.createFailureRelatedSteps( + info, onSeparateLines(waitingReasons), onSeparateLines(waitingMessages), null)); + } + break; case TERMINATED_ERROR_REASON: Optional.ofNullable(getMatchingContainerStatus()) .map(V1ContainerStatus::getState) @@ -1408,6 +1419,38 @@ private void invoke() { } } + private void getInitContainersWaitingReasonsAndMessages(V1Pod pod, List waitingReasons, List waitingMessages) { + Optional.ofNullable(getInitContainerStatuses(pod)).orElseGet(Collections::emptyList).stream() + .forEach(status -> { + waitingMessages.add(getWaitingMessageFromStatus(status)); + waitingReasons.add(getWaitingReason(status)); + }); + } + + private String getWaitingReason(V1ContainerStatus status) { + return Optional.ofNullable(status) + .map(V1ContainerStatus::getState) + .map(V1ContainerState::getWaiting) + .map(V1ContainerStateWaiting::getReason) + .orElse(null); + } + + private String getWaitingMessageFromStatus(V1ContainerStatus status) { + return Optional.ofNullable(status) + .map(V1ContainerStatus::getState) + .map(V1ContainerState::getWaiting) + .map(V1ContainerStateWaiting::getMessage) + .orElse(null); + } + + private List getInitContainerStatuses(V1Pod pod) { + return Optional.ofNullable(pod.getStatus()).map(V1PodStatus::getInitContainerStatuses).orElse(null); + } + + private String onSeparateLines(List waitingReasons) { + return String.join(System.lineSeparator(), waitingReasons); + } + private boolean isNotTerminatedByOperator() { return notNullOrEmpty(getPodStatusReason()) || notNullOrEmpty(getPodStatusMessage()) || !isJobPodTerminated(); } diff --git a/operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java b/operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java index cc9d05ceda5..5687ac2aabb 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java +++ b/operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java @@ -60,6 +60,7 @@ public class PodWatcher extends Watcher implements WatchListener, public enum PodStatus { PHASE_FAILED, WAITING_NON_NULL_MESSAGE, + INIT_CONTAINERS_NOT_READY, TERMINATED_ERROR_REASON, UNSCHEDULABLE, SUCCESS @@ -214,6 +215,8 @@ static PodStatus getPodStatus(@Nonnull V1Pod pod) { return PodStatus.PHASE_FAILED; } else if (notReady(conStatus) && getContainerStateWaitingMessage(conStatus) != null) { return PodStatus.WAITING_NON_NULL_MESSAGE; + } else if (initContainersNotReady(pod)) { + return PodStatus.INIT_CONTAINERS_NOT_READY; } else if (notReady(conStatus) && getContainerStateTerminatedReason(conStatus).contains("Error")) { return PodStatus.TERMINATED_ERROR_REASON; } else if (isUnschedulable(pod)) { @@ -222,6 +225,11 @@ static PodStatus getPodStatus(@Nonnull V1Pod pod) { return PodStatus.SUCCESS; } + private static boolean initContainersNotReady(@Nonnull V1Pod pod) { + return notReady(Optional.ofNullable(pod.getStatus()).map(s -> s.getInitContainerStatuses()) + .orElseGet(Collections::emptyList)); + } + static V1ContainerStatus getContainerStatus(@Nonnull V1Pod pod) { return getContainerStatuses(pod) .stream() @@ -257,6 +265,11 @@ private static String getReason(V1PodCondition podCondition) { return Optional.ofNullable(podCondition).map(V1PodCondition::getReason).orElse(""); } + private static boolean notReady(List initContainerStatus) { + return Optional.ofNullable(initContainerStatus) + .orElseGet(Collections::emptyList).stream().anyMatch(statuses -> notReady(statuses)); + } + private static boolean notReady(V1ContainerStatus conStatus) { return !Optional.ofNullable(conStatus).map(V1ContainerStatus::getReady).orElse(false); } diff --git a/operator/src/main/java/oracle/kubernetes/operator/ProcessingConstants.java b/operator/src/main/java/oracle/kubernetes/operator/ProcessingConstants.java index ecdaa33bce7..af03b808258 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/ProcessingConstants.java +++ b/operator/src/main/java/oracle/kubernetes/operator/ProcessingConstants.java @@ -28,6 +28,7 @@ public interface ProcessingConstants { String DOMAIN_TOPOLOGY = "domainTopology"; String JOB_POD_NAME = "jobPodName"; String JOB_POD_CONTAINER_WAITING_REASON = "jobPodContainerWaitingReason"; + String JOB_POD_INIT_CONTAINER_WAITING_REASON = "jobPodInitContainerWaitingReason"; String DOMAIN_INTROSPECTOR_JOB = "domainIntrospectorJob"; String DOMAIN_INTROSPECTOR_LOG_RESULT = "domainIntrospectorLogResult"; String DOMAIN_INTROSPECT_REQUESTED = "domainIntrospectRequested"; diff --git a/operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java b/operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java index f88330e805c..2a334a112a3 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java +++ b/operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java @@ -496,6 +496,10 @@ private static boolean isImagePullError(String jobPodContainerWaitingReason) { .orElse(false); } + private List getInitContainerStatuses(V1Pod pod) { + return Optional.ofNullable(pod.getStatus()).map(V1PodStatus::getInitContainerStatuses).orElse(null); + } + private static boolean isJobTimedout(DomainPresenceInfo info) { return Objects.equals(getReason(info), "DeadlineExceeded") || getMessage(info).contains("DeadlineExceeded"); } @@ -565,6 +569,21 @@ private void recordJobPodNameAndStatus(Packet packet, V1Pod pod) { .map(V1ContainerStatus::getState).map(V1ContainerState::getWaiting) .map(V1ContainerStateWaiting::getReason).orElse(null)); } + + packet.put(ProcessingConstants.JOB_POD_INIT_CONTAINER_WAITING_REASON, getInitContainerWaitingMessages(pod)); + } + + private Boolean getInitContainerWaitingMessages(V1Pod pod) { + return Optional.ofNullable(getInitContainerStatuses(pod)).orElseGet(Collections::emptyList).stream() + .anyMatch(status -> isImagePullError(getWaitingReason(status))); + } + + private String getWaitingReason(V1ContainerStatus status) { + return Optional.ofNullable(status) + .map(V1ContainerStatus::getState) + .map(V1ContainerState::getWaiting) + .map(V1ContainerStateWaiting::getReason) + .orElse(null); } } @@ -572,14 +591,15 @@ static OffsetDateTime createNextSteps(List nextSteps, Packet packet, V1Job OffsetDateTime jobStartTime; DomainPresenceInfo info = packet.getSpi(DomainPresenceInfo.class); String namespace = info.getNamespace(); - String jobPodContainerWaitingReason = (String) packet.get(ProcessingConstants.JOB_POD_CONTAINER_WAITING_REASON); + String jobPodContainerWaitingReason = packet.getValue(ProcessingConstants.JOB_POD_CONTAINER_WAITING_REASON); + Boolean jobInitContainerImagePullError = getjobInitContainerImagePullError(packet); if (job != null) { jobStartTime = Optional.ofNullable(job.getMetadata()) .map(V1ObjectMeta::getCreationTimestamp).orElse(OffsetDateTime.now()); String lastIntrospectJobProcessedId = getLastIntrospectJobProcessedId(info); - if (isJobTimedout(info) || (isImagePullError(jobPodContainerWaitingReason))) { + if (isJobTimedout(info) || (isImagePullError(jobPodContainerWaitingReason)) || jobInitContainerImagePullError) { jobStartTime = OffsetDateTime.now(); packet.put(DOMAIN_INTROSPECT_REQUESTED, ReadDomainIntrospectorPodLogResponseStep.INTROSPECTION_FAILED); nextSteps.add(Step.chain(deleteDomainIntrospectorJobStep(null), @@ -602,6 +622,15 @@ static OffsetDateTime createNextSteps(List nextSteps, Packet packet, V1Job } return jobStartTime; } + + private static Boolean getjobInitContainerImagePullError(Packet packet) { + Boolean containerWaitingReason = packet.getValue(ProcessingConstants.JOB_POD_INIT_CONTAINER_WAITING_REASON); + return Optional.ofNullable(containerWaitingReason).orElse(Boolean.FALSE); + } + + private static Boolean isNotNull(Boolean jobInitContainerImagePullError) { + return Optional.ofNullable(jobInitContainerImagePullError).orElse(false); + } } static ReadDomainIntrospectorPodLogStep readDomainIntrospectorPodLog(Step next) { diff --git a/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java b/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java index c42764ecf60..7b6a5a98a59 100644 --- a/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java +++ b/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java @@ -26,12 +26,16 @@ import com.meterware.simplestub.StaticStubSupport; import io.kubernetes.client.openapi.models.CoreV1Event; import io.kubernetes.client.openapi.models.V1ConfigMap; +import io.kubernetes.client.openapi.models.V1ContainerState; +import io.kubernetes.client.openapi.models.V1ContainerStateWaiting; +import io.kubernetes.client.openapi.models.V1ContainerStatus; import io.kubernetes.client.openapi.models.V1Job; import io.kubernetes.client.openapi.models.V1JobCondition; import io.kubernetes.client.openapi.models.V1JobStatus; import io.kubernetes.client.openapi.models.V1LabelSelector; import io.kubernetes.client.openapi.models.V1ObjectMeta; import io.kubernetes.client.openapi.models.V1Pod; +import io.kubernetes.client.openapi.models.V1PodStatus; import io.kubernetes.client.openapi.models.V1Secret; import io.kubernetes.client.openapi.models.V1Service; import io.kubernetes.client.openapi.models.V1ServicePort; @@ -52,6 +56,7 @@ import oracle.kubernetes.operator.helpers.ServiceHelper; import oracle.kubernetes.operator.helpers.TuningParametersStub; import oracle.kubernetes.operator.helpers.UnitTestHash; +import oracle.kubernetes.operator.logging.MessageKeys; import oracle.kubernetes.operator.rest.ScanCacheStub; import oracle.kubernetes.operator.utils.InMemoryCertificates; import oracle.kubernetes.operator.wlsconfig.WlsClusterConfig; @@ -87,16 +92,19 @@ import static oracle.kubernetes.operator.LabelConstants.DOMAINUID_LABEL; import static oracle.kubernetes.operator.LabelConstants.INTROSPECTION_STATE_LABEL; import static oracle.kubernetes.operator.LabelConstants.SERVERNAME_LABEL; +import static oracle.kubernetes.operator.ProcessingConstants.DOMAIN_INTROSPECTOR_JOB; import static oracle.kubernetes.operator.WebLogicConstants.RUNNING_STATE; import static oracle.kubernetes.operator.WebLogicConstants.SHUTDOWN_STATE; import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.CONFIG_MAP; import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.DOMAIN; +import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.JOB; import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.POD; import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.SERVICE; import static oracle.kubernetes.operator.logging.MessageKeys.NOT_STARTING_DOMAINUID_THREAD; import static oracle.kubernetes.utils.LogMatcher.containsFine; import static oracle.kubernetes.weblogic.domain.model.ConfigurationConstants.START_ALWAYS; import static oracle.kubernetes.weblogic.domain.model.ConfigurationConstants.START_NEVER; +import static oracle.kubernetes.weblogic.domain.model.DomainConditionType.Failed; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; @@ -120,6 +128,7 @@ class DomainProcessorTest { private static final String[] MANAGED_SERVER_NAMES = IntStream.rangeClosed(1, MAX_SERVERS).mapToObj(DomainProcessorTest::getManagedServerName).toArray(String[]::new); public static final String DOMAIN_NAME = "base_domain"; + private TestUtils.ConsoleHandlerMemento consoleHandlerMemento; @Nonnull private static String getManagedServerName(int n) { @@ -165,6 +174,9 @@ private static WlsDomainConfig createDomainConfig() { @BeforeEach public void setUp() throws Exception { + consoleHandlerMemento = TestUtils.silenceOperatorLogger() + .collectLogMessages(logRecords, NOT_STARTING_DOMAINUID_THREAD).withLogLevel(Level.FINE); + mementos.add(consoleHandlerMemento); mementos.add(TestUtils.silenceOperatorLogger() .collectLogMessages(logRecords, NOT_STARTING_DOMAINUID_THREAD).withLogLevel(Level.FINE)); mementos.add(testSupport.install()); @@ -1337,4 +1349,71 @@ private void defineDuplicateServerNames() { domain.getSpec().getManagedServers().add(new ManagedServer().withServerName("ms1")); domain.getSpec().getManagedServers().add(new ManagedServer().withServerName("ms1")); } + + @Test + void whenIntrospectionJobInitContainerHasImagePullFailure_jobRecreatedAndFailedConditionCleared() throws Exception { + consoleHandlerMemento.ignoringLoggedExceptions(RuntimeException.class); + consoleHandlerMemento.ignoreMessage(MessageKeys.NOT_STARTING_DOMAINUID_THREAD); + jobStatus = createBackoffStatus(); + establishPreviousIntrospection(null); + defineIntrospectionWithInitContainerImagePullError(); + testSupport.doOnDelete(JOB, j -> deletePod()); + testSupport.doOnCreate(JOB, j -> createJobPodAndSetCompletedStatus(job)); + domainConfigurator.withIntrospectVersion(NEW_INTROSPECTION_STATE); + processor.createMakeRightOperation(new DomainPresenceInfo(newDomain)).interrupt().execute(); + + assertThat(isDomainConditionFailed(), is(false)); + } + + V1JobStatus createBackoffStatus() { + return new V1JobStatus().addConditionsItem(new V1JobCondition().status("True").type("Failed") + .reason("BackoffLimitExceeded")); + } + + private void defineIntrospectionWithInitContainerImagePullError() { + V1Job job = asFailedJob(createIntrospectorJob("IMAGE_PULL_FAILURE_JOB")); + testSupport.defineResources(job); + testSupport.addToPacket(DOMAIN_INTROSPECTOR_JOB, job); + setJobPodInitContainerStatusImagePullError(); + } + + private void setJobPodInitContainerStatusImagePullError() { + testSupport.getResourceWithName(POD, getJobName()).status(new V1PodStatus().initContainerStatuses( + Arrays.asList(new V1ContainerStatus().state(new V1ContainerState().waiting( + new V1ContainerStateWaiting().reason("ImagePullBackOff").message("Back-off pulling image")))))); + } + + private V1Job asFailedJob(V1Job job) { + job.setStatus(new V1JobStatus().addConditionsItem(new V1JobCondition().status("True").type("Failed") + .reason("BackoffLimitExceeded"))); + return job; + } + + private V1Job createIntrospectorJob(String uid) { + return new V1Job().metadata(createJobMetadata(uid)).status(new V1JobStatus()); + } + + private V1ObjectMeta createJobMetadata(String uid) { + return new V1ObjectMeta().name(getJobName()).namespace(NS).creationTimestamp(SystemClock.now()).uid(uid); + } + + private static String getJobName() { + return LegalNames.toJobIntrospectorName(UID); + } + + private void deletePod() { + testSupport.deleteResources(new V1Pod().metadata(new V1ObjectMeta().name(getJobName()).namespace(NS))); + } + + private void createJobPodAndSetCompletedStatus(V1Job job) { + Map labels = new HashMap<>(); + labels.put(LabelConstants.JOBNAME_LABEL, getJobName()); + testSupport.defineResources(POD, + new V1Pod().metadata(new V1ObjectMeta().name(getJobName()).labels(labels).namespace(NS))); + job.setStatus(createCompletedStatus()); + } + + private boolean isDomainConditionFailed() { + return newDomain.getStatus().getConditions().stream().anyMatch(c -> c.getType() == Failed); + } } diff --git a/operator/src/test/java/oracle/kubernetes/operator/helpers/IntrospectionStatusTest.java b/operator/src/test/java/oracle/kubernetes/operator/helpers/IntrospectionStatusTest.java index 5746799e25e..9c10d3c9d60 100644 --- a/operator/src/test/java/oracle/kubernetes/operator/helpers/IntrospectionStatusTest.java +++ b/operator/src/test/java/oracle/kubernetes/operator/helpers/IntrospectionStatusTest.java @@ -50,6 +50,7 @@ class IntrospectionStatusTest { private static final String UNSCHEDULABLE = "Unschedulable"; private static final String IMAGE_PULL_BACKOFF = "ImagePullBackoff"; private static final String DEADLINE_EXCEEDED = "DeadlineExceeded"; + private static final int MESSAGE_LENGTH = 10; private final List mementos = new ArrayList<>(); private final KubernetesTestSupport testSupport = new KubernetesTestSupport(); private final Map> presenceInfoMap = new HashMap<>(); @@ -208,6 +209,21 @@ void whenNewIntrospectorJobPodStatusReasonNullAfterImagePullFailure_patchDomain( assertThat(updatedDomain.getStatus().getMessage(), emptyOrNullString()); } + @Test + void whenPodHasInitContainerImagePullErrorWaitingMessage_updateDomainStatus() { + processor.dispatchPodWatch( + WatchEvent.createAddedEvent( + createIntrospectorJobPodWithInitContainerStatus(createWaitingState(IMAGE_PULL_FAILURE, MESSAGE))) + .toWatchResponse()); + + assertThat(getDomain().getStatus().getReason(), equalTo("ErrImagePull")); + assertThat(getDomain().getStatus().getMessage(), equalTo(MESSAGE)); + } + + private Domain getDomain() { + return testSupport.getResourceWithName(KubernetesTestSupport.DOMAIN, UID); + } + private V1Pod createIntrospectorJobPod(V1ContainerState waitingState) { return createIntrospectorJobPod(UID) .status( @@ -224,14 +240,27 @@ private V1Pod createIntrospectorJobPod(V1ContainerState waitingState) { @SuppressWarnings("SameParameterValue") private V1Pod createIntrospectorJobPod(String domainUid) { return AnnotationHelper.withSha256Hash( - new V1Pod() - .metadata( - withIntrospectorJobLabels( - new V1ObjectMeta() - .name(toJobIntrospectorName(domainUid) + getPodSuffix()) - .namespace(NS), - domainUid)) - .spec(new V1PodSpec())); + new V1Pod() + .metadata( + withIntrospectorJobLabels( + new V1ObjectMeta() + .name(toJobIntrospectorName(domainUid) + getPodSuffix()) + .namespace(NS), + domainUid)) + .spec(new V1PodSpec())); + } + + private V1Pod createIntrospectorJobPodWithInitContainerStatus(V1ContainerState waitingState) { + return createIntrospectorJobPod(UID) + .status( + new V1PodStatusBuilder() + .addNewInitContainerStatus() + .withImage(IMAGE_NAME) + .withName(toJobIntrospectorName(UID)) + .withReady(false) + .withState(waitingState) + .endInitContainerStatus() + .build()); } private V1Pod createIntrospectorJobPodWithConditions(V1PodCondition condition) { From d3af12225a0e5272550a2e8ae864b04d00ec699d Mon Sep 17 00:00:00 2001 From: Anil Kedia Date: Tue, 21 Dec 2021 15:41:33 +0000 Subject: [PATCH 2/2] Minor cleanup related changes. --- .../operator/DomainProcessorImpl.java | 17 +++++++---------- .../oracle/kubernetes/operator/PodWatcher.java | 6 +++--- .../kubernetes/operator/helpers/JobHelper.java | 11 +++-------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java b/operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java index 9edea2ccb0a..2e7f53d007b 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java +++ b/operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java @@ -1382,10 +1382,15 @@ private void invoke() { info, waiting.getReason(), waiting.getMessage(), null))); break; case INIT_CONTAINERS_NOT_READY: - List waitingMessages = new ArrayList<>(); List waitingReasons = new ArrayList<>(); + List waitingMessages = new ArrayList<>(); - getInitContainersWaitingReasonsAndMessages(introspectorPod, waitingReasons, waitingMessages); + Optional.ofNullable(getInitContainerStatuses(introspectorPod)) + .orElseGet(Collections::emptyList).stream() + .forEach(status -> { + waitingMessages.add(getWaitingMessageFromStatus(status)); + waitingReasons.add(getWaitingReason(status)); + }); if (!waitingReasons.isEmpty()) { delegate.runSteps(DomainStatusUpdater.createFailureRelatedSteps( info, onSeparateLines(waitingReasons), onSeparateLines(waitingMessages), null)); @@ -1419,14 +1424,6 @@ private void invoke() { } } - private void getInitContainersWaitingReasonsAndMessages(V1Pod pod, List waitingReasons, List waitingMessages) { - Optional.ofNullable(getInitContainerStatuses(pod)).orElseGet(Collections::emptyList).stream() - .forEach(status -> { - waitingMessages.add(getWaitingMessageFromStatus(status)); - waitingReasons.add(getWaitingReason(status)); - }); - } - private String getWaitingReason(V1ContainerStatus status) { return Optional.ofNullable(status) .map(V1ContainerStatus::getState) diff --git a/operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java b/operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java index 5687ac2aabb..6b6d2711df1 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java +++ b/operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java @@ -265,9 +265,9 @@ private static String getReason(V1PodCondition podCondition) { return Optional.ofNullable(podCondition).map(V1PodCondition::getReason).orElse(""); } - private static boolean notReady(List initContainerStatus) { - return Optional.ofNullable(initContainerStatus) - .orElseGet(Collections::emptyList).stream().anyMatch(statuses -> notReady(statuses)); + private static boolean notReady(List initContainerStatuses) { + return Optional.ofNullable(initContainerStatuses) + .orElseGet(Collections::emptyList).stream().anyMatch(status -> notReady(status)); } private static boolean notReady(V1ContainerStatus conStatus) { diff --git a/operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java b/operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java index 2a334a112a3..d41d5733120 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java +++ b/operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java @@ -568,9 +568,8 @@ private void recordJobPodNameAndStatus(Packet packet, V1Pod pod) { .map(V1PodStatus::getContainerStatuses).map(statuses -> statuses.get(0)) .map(V1ContainerStatus::getState).map(V1ContainerState::getWaiting) .map(V1ContainerStateWaiting::getReason).orElse(null)); + packet.put(ProcessingConstants.JOB_POD_INIT_CONTAINER_WAITING_REASON, getInitContainerWaitingMessages(pod)); } - - packet.put(ProcessingConstants.JOB_POD_INIT_CONTAINER_WAITING_REASON, getInitContainerWaitingMessages(pod)); } private Boolean getInitContainerWaitingMessages(V1Pod pod) { @@ -624,12 +623,8 @@ static OffsetDateTime createNextSteps(List nextSteps, Packet packet, V1Job } private static Boolean getjobInitContainerImagePullError(Packet packet) { - Boolean containerWaitingReason = packet.getValue(ProcessingConstants.JOB_POD_INIT_CONTAINER_WAITING_REASON); - return Optional.ofNullable(containerWaitingReason).orElse(Boolean.FALSE); - } - - private static Boolean isNotNull(Boolean jobInitContainerImagePullError) { - return Optional.ofNullable(jobInitContainerImagePullError).orElse(false); + return Optional.ofNullable(packet.getValue(ProcessingConstants.JOB_POD_INIT_CONTAINER_WAITING_REASON)) + .orElse(Boolean.FALSE); } }