2626import com .meterware .simplestub .StaticStubSupport ;
2727import io .kubernetes .client .openapi .models .CoreV1Event ;
2828import io .kubernetes .client .openapi .models .V1ConfigMap ;
29+ import io .kubernetes .client .openapi .models .V1ContainerState ;
30+ import io .kubernetes .client .openapi .models .V1ContainerStateWaiting ;
31+ import io .kubernetes .client .openapi .models .V1ContainerStatus ;
2932import io .kubernetes .client .openapi .models .V1Job ;
3033import io .kubernetes .client .openapi .models .V1JobCondition ;
3134import io .kubernetes .client .openapi .models .V1JobStatus ;
3235import io .kubernetes .client .openapi .models .V1LabelSelector ;
3336import io .kubernetes .client .openapi .models .V1ObjectMeta ;
3437import io .kubernetes .client .openapi .models .V1Pod ;
38+ import io .kubernetes .client .openapi .models .V1PodStatus ;
3539import io .kubernetes .client .openapi .models .V1Secret ;
3640import io .kubernetes .client .openapi .models .V1Service ;
3741import io .kubernetes .client .openapi .models .V1ServicePort ;
5256import oracle .kubernetes .operator .helpers .ServiceHelper ;
5357import oracle .kubernetes .operator .helpers .TuningParametersStub ;
5458import oracle .kubernetes .operator .helpers .UnitTestHash ;
59+ import oracle .kubernetes .operator .logging .MessageKeys ;
5560import oracle .kubernetes .operator .rest .ScanCacheStub ;
5661import oracle .kubernetes .operator .utils .InMemoryCertificates ;
5762import oracle .kubernetes .operator .wlsconfig .WlsClusterConfig ;
8792import static oracle .kubernetes .operator .LabelConstants .DOMAINUID_LABEL ;
8893import static oracle .kubernetes .operator .LabelConstants .INTROSPECTION_STATE_LABEL ;
8994import static oracle .kubernetes .operator .LabelConstants .SERVERNAME_LABEL ;
95+ import static oracle .kubernetes .operator .ProcessingConstants .DOMAIN_INTROSPECTOR_JOB ;
9096import static oracle .kubernetes .operator .WebLogicConstants .RUNNING_STATE ;
9197import static oracle .kubernetes .operator .WebLogicConstants .SHUTDOWN_STATE ;
9298import static oracle .kubernetes .operator .helpers .KubernetesTestSupport .CONFIG_MAP ;
9399import static oracle .kubernetes .operator .helpers .KubernetesTestSupport .DOMAIN ;
100+ import static oracle .kubernetes .operator .helpers .KubernetesTestSupport .JOB ;
94101import static oracle .kubernetes .operator .helpers .KubernetesTestSupport .POD ;
95102import static oracle .kubernetes .operator .helpers .KubernetesTestSupport .SERVICE ;
96103import static oracle .kubernetes .operator .logging .MessageKeys .NOT_STARTING_DOMAINUID_THREAD ;
97104import static oracle .kubernetes .utils .LogMatcher .containsFine ;
98105import static oracle .kubernetes .weblogic .domain .model .ConfigurationConstants .START_ALWAYS ;
99106import static oracle .kubernetes .weblogic .domain .model .ConfigurationConstants .START_NEVER ;
107+ import static oracle .kubernetes .weblogic .domain .model .DomainConditionType .Failed ;
100108import static org .hamcrest .Matchers .allOf ;
101109import static org .hamcrest .Matchers .contains ;
102110import static org .hamcrest .Matchers .empty ;
@@ -120,6 +128,7 @@ class DomainProcessorTest {
120128 private static final String [] MANAGED_SERVER_NAMES =
121129 IntStream .rangeClosed (1 , MAX_SERVERS ).mapToObj (DomainProcessorTest ::getManagedServerName ).toArray (String []::new );
122130 public static final String DOMAIN_NAME = "base_domain" ;
131+ private TestUtils .ConsoleHandlerMemento consoleHandlerMemento ;
123132
124133 @ Nonnull
125134 private static String getManagedServerName (int n ) {
@@ -165,6 +174,9 @@ private static WlsDomainConfig createDomainConfig() {
165174
166175 @ BeforeEach
167176 public void setUp () throws Exception {
177+ consoleHandlerMemento = TestUtils .silenceOperatorLogger ()
178+ .collectLogMessages (logRecords , NOT_STARTING_DOMAINUID_THREAD ).withLogLevel (Level .FINE );
179+ mementos .add (consoleHandlerMemento );
168180 mementos .add (TestUtils .silenceOperatorLogger ()
169181 .collectLogMessages (logRecords , NOT_STARTING_DOMAINUID_THREAD ).withLogLevel (Level .FINE ));
170182 mementos .add (testSupport .install ());
@@ -1337,4 +1349,71 @@ private void defineDuplicateServerNames() {
13371349 domain .getSpec ().getManagedServers ().add (new ManagedServer ().withServerName ("ms1" ));
13381350 domain .getSpec ().getManagedServers ().add (new ManagedServer ().withServerName ("ms1" ));
13391351 }
1352+
1353+ @ Test
1354+ void whenIntrospectionJobInitContainerHasImagePullFailure_jobRecreatedAndFailedConditionCleared () throws Exception {
1355+ consoleHandlerMemento .ignoringLoggedExceptions (RuntimeException .class );
1356+ consoleHandlerMemento .ignoreMessage (MessageKeys .NOT_STARTING_DOMAINUID_THREAD );
1357+ jobStatus = createBackoffStatus ();
1358+ establishPreviousIntrospection (null );
1359+ defineIntrospectionWithInitContainerImagePullError ();
1360+ testSupport .doOnDelete (JOB , j -> deletePod ());
1361+ testSupport .doOnCreate (JOB , j -> createJobPodAndSetCompletedStatus (job ));
1362+ domainConfigurator .withIntrospectVersion (NEW_INTROSPECTION_STATE );
1363+ processor .createMakeRightOperation (new DomainPresenceInfo (newDomain )).interrupt ().execute ();
1364+
1365+ assertThat (isDomainConditionFailed (), is (false ));
1366+ }
1367+
1368+ V1JobStatus createBackoffStatus () {
1369+ return new V1JobStatus ().addConditionsItem (new V1JobCondition ().status ("True" ).type ("Failed" )
1370+ .reason ("BackoffLimitExceeded" ));
1371+ }
1372+
1373+ private void defineIntrospectionWithInitContainerImagePullError () {
1374+ V1Job job = asFailedJob (createIntrospectorJob ("IMAGE_PULL_FAILURE_JOB" ));
1375+ testSupport .defineResources (job );
1376+ testSupport .addToPacket (DOMAIN_INTROSPECTOR_JOB , job );
1377+ setJobPodInitContainerStatusImagePullError ();
1378+ }
1379+
1380+ private void setJobPodInitContainerStatusImagePullError () {
1381+ testSupport .<V1Pod >getResourceWithName (POD , getJobName ()).status (new V1PodStatus ().initContainerStatuses (
1382+ Arrays .asList (new V1ContainerStatus ().state (new V1ContainerState ().waiting (
1383+ new V1ContainerStateWaiting ().reason ("ImagePullBackOff" ).message ("Back-off pulling image" ))))));
1384+ }
1385+
1386+ private V1Job asFailedJob (V1Job job ) {
1387+ job .setStatus (new V1JobStatus ().addConditionsItem (new V1JobCondition ().status ("True" ).type ("Failed" )
1388+ .reason ("BackoffLimitExceeded" )));
1389+ return job ;
1390+ }
1391+
1392+ private V1Job createIntrospectorJob (String uid ) {
1393+ return new V1Job ().metadata (createJobMetadata (uid )).status (new V1JobStatus ());
1394+ }
1395+
1396+ private V1ObjectMeta createJobMetadata (String uid ) {
1397+ return new V1ObjectMeta ().name (getJobName ()).namespace (NS ).creationTimestamp (SystemClock .now ()).uid (uid );
1398+ }
1399+
1400+ private static String getJobName () {
1401+ return LegalNames .toJobIntrospectorName (UID );
1402+ }
1403+
1404+ private void deletePod () {
1405+ testSupport .deleteResources (new V1Pod ().metadata (new V1ObjectMeta ().name (getJobName ()).namespace (NS )));
1406+ }
1407+
1408+ private void createJobPodAndSetCompletedStatus (V1Job job ) {
1409+ Map <String , String > labels = new HashMap <>();
1410+ labels .put (LabelConstants .JOBNAME_LABEL , getJobName ());
1411+ testSupport .defineResources (POD ,
1412+ new V1Pod ().metadata (new V1ObjectMeta ().name (getJobName ()).labels (labels ).namespace (NS )));
1413+ job .setStatus (createCompletedStatus ());
1414+ }
1415+
1416+ private boolean isDomainConditionFailed () {
1417+ return newDomain .getStatus ().getConditions ().stream ().anyMatch (c -> c .getType () == Failed );
1418+ }
13401419}
0 commit comments