diff --git a/gradle-plugin/it/src/it/controller/expected/cronjob/kubernetes.yml b/gradle-plugin/it/src/it/controller/expected/cronjob/kubernetes.yml new file mode 100644 index 0000000000..f98e256362 --- /dev/null +++ b/gradle-plugin/it/src/it/controller/expected/cronjob/kubernetes.yml @@ -0,0 +1,41 @@ +--- +apiVersion: v1 +kind: List +items: + - apiVersion: batch/v1 + kind: CronJob + metadata: + labels: + app: controller + provider: jkube + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: controller + spec: + jobTemplate: + spec: + template: + metadata: + labels: + app: controller + provider: jkube + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + spec: + containers: + - name: repository-controller + image: repository/controller:latest + imagePullPolicy: IfNotPresent + securityContext: + privileged: false + env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: HOSTNAME + valueFrom: + fieldRef: + fieldPath: metadata.name + restartPolicy: OnFailure + schedule: '*/2 * * * *' diff --git a/gradle-plugin/it/src/it/controller/expected/cronjob/openshift.yml b/gradle-plugin/it/src/it/controller/expected/cronjob/openshift.yml new file mode 100644 index 0000000000..1c59b6ee2e --- /dev/null +++ b/gradle-plugin/it/src/it/controller/expected/cronjob/openshift.yml @@ -0,0 +1,37 @@ +--- +apiVersion: v1 +kind: List +items: + - apiVersion: batch/v1 + kind: CronJob + metadata: + labels: + app: controller + provider: jkube + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: controller + spec: + jobTemplate: + spec: + template: + metadata: + labels: + app: controller + provider: jkube + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + spec: + containers: + - name: repository-controller + image: repository/controller:latest + imagePullPolicy: IfNotPresent + securityContext: + privileged: false + env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + restartPolicy: OnFailure + schedule: '*/2 * * * *' diff --git a/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/KubernetesConfiguredControllerIT.java b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/KubernetesConfiguredControllerIT.java index 24ddf6932c..9545c859e8 100644 --- a/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/KubernetesConfiguredControllerIT.java +++ b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/KubernetesConfiguredControllerIT.java @@ -16,6 +16,7 @@ import net.minidev.json.parser.ParseException; import org.eclipse.jkube.kit.common.ResourceVerify; import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -45,4 +46,23 @@ void k8sResourceTask_whenRunWithConfiguredControllerType_generatesK8sManifestWit .contains("Adding revision history limit to 2") .contains("validating"); } + + @Test + void k8sResourceTask_whenRunWithCronJobController_generatesK8sManifestWithCronJobController() throws IOException, ParseException { + // When + final BuildResult result = gradleRunner.withITProject("controller") + .withArguments("-Pjkube.enricher.jkube-controller.type=CronJob", + "-Pjkube.enricher.jkube-controller.schedule=*/2 * * * *", "k8sResource") + .build(); + // Then + ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultKubernetesResourceFile(), + gradleRunner.resolveFile("expected", "cronjob", "kubernetes.yml")); + assertThat(result).extracting(BuildResult::getOutput).asString() + .contains( + "Using resource templates from", + "Adding a default CronJob", + "Adding revision history limit to 2", + "validating" + ); + } } diff --git a/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/OpenShiftConfiguredControllerIT.java b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/OpenShiftConfiguredControllerIT.java index 9adc3532d6..c87576fe30 100644 --- a/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/OpenShiftConfiguredControllerIT.java +++ b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/OpenShiftConfiguredControllerIT.java @@ -16,6 +16,7 @@ import net.minidev.json.parser.ParseException; import org.eclipse.jkube.kit.common.ResourceVerify; import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -45,4 +46,23 @@ void ocResourceTask_whenRunWithConfiguredControllerType_generatesOpenShiftManife .contains("Adding revision history limit to 2") .contains("validating"); } + + @Test + void ocResourceTask_whenRunWithCronJobController_generatesOpenShiftManifestWithCronJobController() throws IOException, ParseException { + // When + final BuildResult result = gradleRunner.withITProject("controller") + .withArguments("-Pjkube.enricher.jkube-controller.type=CronJob", + "-Pjkube.enricher.jkube-controller.schedule=*/2 * * * *", "ocResource", "--stacktrace") + .build(); + // Then + ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultOpenShiftResourceFile(), + gradleRunner.resolveFile("expected", "cronjob", "openshift.yml")); + assertThat(result).extracting(BuildResult::getOutput).asString() + .contains( + "Using resource templates from", + "Adding a default CronJob", + "Adding revision history limit to 2", + "validating" + ); + } }