|
14 | 14 | import java.util.Map; |
15 | 15 | import java.util.Properties; |
16 | 16 |
|
17 | | -import io.kubernetes.client.openapi.models.V1ConfigMapVolumeSource; |
18 | 17 | import io.kubernetes.client.openapi.models.V1Container; |
19 | | -import io.kubernetes.client.openapi.models.V1ContainerPort; |
20 | 18 | import io.kubernetes.client.openapi.models.V1EnvVar; |
21 | | -import io.kubernetes.client.openapi.models.V1Job; |
22 | | -import io.kubernetes.client.openapi.models.V1JobCondition; |
23 | | -import io.kubernetes.client.openapi.models.V1JobSpec; |
24 | 19 | import io.kubernetes.client.openapi.models.V1LocalObjectReference; |
25 | 20 | import io.kubernetes.client.openapi.models.V1ObjectMeta; |
26 | 21 | import io.kubernetes.client.openapi.models.V1PersistentVolumeClaimVolumeSource; |
27 | | -import io.kubernetes.client.openapi.models.V1Pod; |
28 | | -import io.kubernetes.client.openapi.models.V1PodSpec; |
29 | | -import io.kubernetes.client.openapi.models.V1PodTemplateSpec; |
30 | 22 | import io.kubernetes.client.openapi.models.V1SecretReference; |
31 | 23 | import io.kubernetes.client.openapi.models.V1Volume; |
32 | 24 | import io.kubernetes.client.openapi.models.V1VolumeMount; |
|
61 | 53 | import static oracle.weblogic.kubernetes.actions.ActionConstants.ITTESTS_DIR; |
62 | 54 | import static oracle.weblogic.kubernetes.actions.ActionConstants.RESOURCE_DIR; |
63 | 55 | import static oracle.weblogic.kubernetes.actions.TestActions.addLabelsToNamespace; |
64 | | -import static oracle.weblogic.kubernetes.actions.TestActions.createNamespacedJob; |
65 | | -import static oracle.weblogic.kubernetes.actions.TestActions.getJob; |
66 | | -import static oracle.weblogic.kubernetes.actions.TestActions.getPodLog; |
67 | | -import static oracle.weblogic.kubernetes.actions.TestActions.listPods; |
68 | 56 | import static oracle.weblogic.kubernetes.actions.TestActions.scaleCluster; |
69 | | -import static oracle.weblogic.kubernetes.assertions.TestAssertions.jobCompleted; |
70 | 57 | import static oracle.weblogic.kubernetes.utils.CommonPatchTestUtils.patchServerStartPolicy; |
71 | 58 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkAppUsingHostHeader; |
72 | 59 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodDeleted; |
73 | 60 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReady; |
74 | 61 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkServiceExists; |
75 | 62 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createDomainAndVerify; |
| 63 | +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createDomainJob; |
76 | 64 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createSecretForBaseImages; |
77 | 65 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createSecretWithUsernamePassword; |
78 | | -import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createfixPVCOwnerContainer; |
79 | 66 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.generateFileFromTemplate; |
80 | 67 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.installAndVerifyOperator; |
81 | 68 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.setPodAntiAffinity; |
|
89 | 76 | import static org.junit.jupiter.api.Assertions.assertEquals; |
90 | 77 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
91 | 78 | import static org.junit.jupiter.api.Assertions.assertTrue; |
92 | | -import static org.junit.jupiter.api.Assertions.fail; |
93 | 79 |
|
94 | 80 | /** |
95 | 81 | * Tests to create domain in persistent volume using WLST. |
@@ -407,105 +393,11 @@ private void createDomainOnPVUsingWlst(Path wlstScriptFile, Path domainPropertie |
407 | 393 | .addArgsItem("/u01/weblogic/" + domainPropertiesFile.getFileName()); //domain property file |
408 | 394 |
|
409 | 395 | logger.info("Running a Kubernetes job to create the domain"); |
410 | | - createDomainJob(pvName, pvcName, domainScriptConfigMapName, namespace, jobCreationContainer); |
411 | | - |
412 | | - } |
413 | | - |
414 | | - /** |
415 | | - * Create a job to create a domain in persistent volume. |
416 | | - * |
417 | | - * @param pvName name of the persistent volume to create domain in |
418 | | - * @param pvcName name of the persistent volume claim |
419 | | - * @param domainScriptCM configmap holding domain creation script files |
420 | | - * @param namespace name of the domain namespace in which the job is created |
421 | | - * @param jobContainer V1Container with job commands to create domain |
422 | | - */ |
423 | | - private void createDomainJob(String pvName, |
424 | | - String pvcName, String domainScriptCM, String namespace, V1Container jobContainer) { |
425 | | - logger.info("Running Kubernetes job to create domain"); |
426 | 396 | Map<String, String> annotMap = new HashMap<String, String>(); |
427 | 397 | annotMap.put("sidecar.istio.io/inject", "false"); |
428 | | - |
429 | | - V1Job jobBody = new V1Job() |
430 | | - .metadata( |
431 | | - new V1ObjectMeta() |
432 | | - .name("create-domain-onpv-job-" + pvName) // name of the create domain job |
433 | | - .namespace(namespace)) |
434 | | - .spec(new V1JobSpec() |
435 | | - .backoffLimit(0) // try only once |
436 | | - .template(new V1PodTemplateSpec() |
437 | | - .metadata(new V1ObjectMeta() |
438 | | - .annotations(annotMap)) |
439 | | - .spec(new V1PodSpec() |
440 | | - .restartPolicy("Never") |
441 | | - .initContainers(Arrays.asList(createfixPVCOwnerContainer(pvName, "/shared"))) |
442 | | - .containers(Arrays.asList(jobContainer // container containing WLST or WDT details |
443 | | - .name("create-weblogic-domain-onpv-container") |
444 | | - .image(WEBLOGIC_IMAGE_TO_USE_IN_SPEC) |
445 | | - .imagePullPolicy("Always") |
446 | | - .ports(Arrays.asList(new V1ContainerPort() |
447 | | - .containerPort(7001))) |
448 | | - .volumeMounts(Arrays.asList( |
449 | | - new V1VolumeMount() |
450 | | - .name("create-weblogic-domain-job-cm-volume") // domain creation scripts volume |
451 | | - .mountPath("/u01/weblogic"), // availble under /u01/weblogic inside pod |
452 | | - new V1VolumeMount() |
453 | | - .name(pvName) // location to write domain |
454 | | - .mountPath("/shared"))))) // mounted under /shared inside pod |
455 | | - .volumes(Arrays.asList( |
456 | | - new V1Volume() |
457 | | - .name(pvName) |
458 | | - .persistentVolumeClaim( |
459 | | - new V1PersistentVolumeClaimVolumeSource() |
460 | | - .claimName(pvcName)), |
461 | | - new V1Volume() |
462 | | - .name("create-weblogic-domain-job-cm-volume") |
463 | | - .configMap( |
464 | | - new V1ConfigMapVolumeSource() |
465 | | - .name(domainScriptCM)))) //config map containing domain scripts |
466 | | - .imagePullSecrets(Arrays.asList( |
467 | | - new V1LocalObjectReference() |
468 | | - .name(BASE_IMAGES_REPO_SECRET)))))); // this secret is used only on non-kind cluster |
469 | | - |
470 | | - String jobName = assertDoesNotThrow(() |
471 | | - -> createNamespacedJob(jobBody), "Failed to create Job"); |
472 | | - |
473 | | - logger.info("Checking if the domain creation job {0} completed in namespace {1}", |
474 | | - jobName, namespace); |
475 | | - withStandardRetryPolicy |
476 | | - .conditionEvaluationListener( |
477 | | - condition -> logger.info("Waiting for job {0} to be completed in namespace {1} " |
478 | | - + "(elapsed time {2} ms, remaining time {3} ms)", |
479 | | - jobName, |
480 | | - namespace, |
481 | | - condition.getElapsedTimeInMS(), |
482 | | - condition.getRemainingTimeInMS())) |
483 | | - .until(jobCompleted(jobName, null, namespace)); |
484 | | - |
485 | | - // check job status and fail test if the job failed to create domain |
486 | | - V1Job job = assertDoesNotThrow(() -> getJob(jobName, namespace), |
487 | | - "Getting the job failed"); |
488 | | - if (job != null) { |
489 | | - V1JobCondition jobCondition = job.getStatus().getConditions().stream().filter( |
490 | | - v1JobCondition -> "Failed".equalsIgnoreCase(v1JobCondition.getType())) |
491 | | - .findAny() |
492 | | - .orElse(null); |
493 | | - if (jobCondition != null) { |
494 | | - logger.severe("Job {0} failed to create domain", jobName); |
495 | | - List<V1Pod> pods = assertDoesNotThrow(() |
496 | | - -> listPods(namespace, "job-name=" + jobName).getItems(), |
497 | | - "Listing pods failed"); |
498 | | - if (!pods.isEmpty()) { |
499 | | - String podLog = assertDoesNotThrow(() -> getPodLog(pods.get(0).getMetadata().getName(), namespace), |
500 | | - "Failed to get pod log"); |
501 | | - logger.severe(podLog); |
502 | | - fail("Domain create job failed"); |
503 | | - } |
504 | | - } |
505 | | - } |
| 398 | + createDomainJob(WEBLOGIC_IMAGE_TO_USE_IN_SPEC, pvName, pvcName, domainScriptConfigMapName, |
| 399 | + namespace, jobCreationContainer, annotMap); |
506 | 400 |
|
507 | 401 | } |
508 | 402 |
|
509 | | - |
510 | | - |
511 | 403 | } |
0 commit comments