From 5541cc177ad11c144cffadb9ab0957c59201273f Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 27 Oct 2021 15:57:09 +0530 Subject: [PATCH 1/5] HelmMojo: Move manifest not found warning into a separate method Move manifest not found warning message into a method so that it can be overridden in case of OpenShiftHelmMojo Signed-off-by: Rohan Kumar --- .../org/eclipse/jkube/maven/plugin/mojo/build/HelmMojo.java | 6 +++++- .../jkube/maven/plugin/mojo/build/OpenshiftHelmMojo.java | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/kubernetes-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojo.java b/kubernetes-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojo.java index 711f3ada3c..d4c3883674 100644 --- a/kubernetes-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojo.java +++ b/kubernetes-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojo.java @@ -57,7 +57,7 @@ public void executeInternal() throws MojoExecutionException { try { File manifest = getKubernetesManifest(); if (manifest == null || !manifest.isFile()) { - getKitLogger().warn("No kubernetes manifest file has been generated yet by the kubernetes:resource goal at: " + manifest); + logManifestNotFoundWarning(manifest); } helm = initHelmConfig(getDefaultHelmType(), javaProject, getKubernetesManifest(), getKubernetesTemplate(), helm) .generatedChartListeners(Collections.singletonList((helmConfig, type, chartFile) -> projectHelper @@ -69,6 +69,10 @@ public void executeInternal() throws MojoExecutionException { } } + protected void logManifestNotFoundWarning(File manifest) { + getKitLogger().warn("No kubernetes manifest file has been generated yet by the k8s:resource goal at: " + manifest); + } + protected File getKubernetesManifest() { return kubernetesManifest; } diff --git a/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftHelmMojo.java b/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftHelmMojo.java index 755cdcff92..c92444d5a9 100644 --- a/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftHelmMojo.java +++ b/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftHelmMojo.java @@ -55,4 +55,9 @@ protected HelmConfig.HelmType getDefaultHelmType() { protected String getLogPrefix() { return OpenShift.DEFAULT_LOG_PREFIX; } + + @Override + protected void logManifestNotFoundWarning(File manifest) { + getKitLogger().warn("No openshift manifest file has been generated yet by the oc:resource goal at: " + manifest); + } } From 93d556dece7595a243f1f280824fcc9e90fdec2a Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 27 Oct 2021 16:00:28 +0530 Subject: [PATCH 2/5] Fix wrong property name in OpenShiftHelmMojo regarding openshift manifests and template The property name seems to be a typo and openshiftManifest field should have `jkube.openshiftManifest` as property name instead of `jkube.kubernetesManifest` Signed-off-by: Rohan Kumar --- .../jkube/maven/plugin/mojo/build/OpenshiftHelmMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftHelmMojo.java b/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftHelmMojo.java index c92444d5a9..f0bd0bff74 100644 --- a/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftHelmMojo.java +++ b/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftHelmMojo.java @@ -27,13 +27,13 @@ public class OpenshiftHelmMojo extends HelmMojo { /** * The generated kubernetes YAML file */ - @Parameter(property = "jkube.kubernetesManifest", defaultValue = "${basedir}/target/classes/META-INF/jkube/openshift.yml") + @Parameter(property = "jkube.openshiftManifest", defaultValue = "${basedir}/target/classes/META-INF/jkube/openshift.yml") private File openShiftManifest; /** * The generated kubernetes YAML file */ - @Parameter(property = "jkube.kubernetesManifest", defaultValue = "${basedir}/target/classes/META-INF/jkube/openshift") + @Parameter(property = "jkube.kubernetesTemplate", defaultValue = "${basedir}/target/classes/META-INF/jkube/openshift") private File openShiftTemplate; @Override From e1030d3632a71a02a038422d6a4dbf862160db82 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Tue, 26 Oct 2021 22:53:49 +0530 Subject: [PATCH 3/5] Fix #1053: Add ocHelm task to OpenShift Gradle Plugin Implement `oc:helm` equivalent functionality `ocHelm` for OpenShift Gradle Plugin. Signed-off-by: Rohan Kumar --- .../asciidoc/inc/tasks/build/_jkube-helm.adoc | 6 +- .../plugin/task/KubernetesHelmTask.java | 18 ++++- .../gradle/plugin/OpenShiftExtension.java | 11 +++ .../jkube/gradle/plugin/OpenShiftPlugin.java | 3 + .../gradle/plugin/task/OpenShiftHelmTask.java | 44 +++++++++++ .../OpenShiftPluginRegisterTaskTest.java | 4 +- .../gradle/plugin/OpenShiftPluginTest.java | 5 +- .../plugin/task/OpenShiftHelmTaskTest.java | 79 +++++++++++++++++++ .../gradle/plugin/task/TaskEnvironment.java | 4 + .../gradle/spring-boot-helm/build.gradle | 23 ++++++ 10 files changed, 189 insertions(+), 8 deletions(-) create mode 100644 gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTask.java create mode 100644 gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTaskTest.java diff --git a/gradle-plugin/doc/src/main/asciidoc/inc/tasks/build/_jkube-helm.adoc b/gradle-plugin/doc/src/main/asciidoc/inc/tasks/build/_jkube-helm.adoc index 1a50b04334..b5f850a7cf 100644 --- a/gradle-plugin/doc/src/main/asciidoc/inc/tasks/build/_jkube-helm.adoc +++ b/gradle-plugin/doc/src/main/asciidoc/inc/tasks/build/_jkube-helm.adoc @@ -126,11 +126,13 @@ In a next step you can install this via the https://github.com/helm/helm/release [source, sh, subs="+attributes"] ---- -helm install nameForChartInRepository build/jkube/helm/${chartName}/kubernetes +helm install nameForChartInRepository build/jkube/helm/${chartName}/{cluster} ---- or + +[source, sh, subs="+attributes"] ---- -helm install build/jkube/helm/${chartName}/kubernetes --generate-name +helm install build/jkube/helm/${chartName}/{cluster} --generate-name ---- In addition, this task will also create a tar-archive below `${basedir}/build` which contains the chart with its template. diff --git a/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTask.java b/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTask.java index 9c0c8f6f46..18f8997620 100644 --- a/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTask.java +++ b/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTask.java @@ -32,16 +32,28 @@ public KubernetesHelmTask(Class extensionClass) { @Override public void run() { try { - File manifest = kubernetesExtension.getKubernetesManifestOrDefault(); + File manifest = resolveManifest(); if (manifest == null || !manifest.isFile()) { - kitLogger.warn("No kubernetes manifest file has been generated yet by the k8sResource task at: " + manifest); + logManifestNotFoundWarning(manifest); } HelmConfig helm = initHelmConfig(kubernetesExtension.getDefaultHelmType(), kubernetesExtension.javaProject, - kubernetesExtension.getKubernetesManifestOrDefault(), kubernetesExtension.getKubernetesTemplateOrDefault(), + resolveManifest(), resolveTemplate(), kubernetesExtension.helm).build(); jKubeServiceHub.getHelmService().generateHelmCharts(helm); } catch (IOException exception) { throw new IllegalStateException(exception.getMessage()); } } + + protected File resolveManifest() { + return kubernetesExtension.getKubernetesManifestOrDefault(); + } + + protected File resolveTemplate() { + return kubernetesExtension.getKubernetesTemplateOrDefault(); + } + + protected void logManifestNotFoundWarning(File manifest) { + kitLogger.warn("No kubernetes manifest file has been generated yet by the k8sResource task at: " + manifest); + } } diff --git a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtension.java b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtension.java index 351490d220..e29f20ab9c 100644 --- a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtension.java +++ b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtension.java @@ -25,11 +25,13 @@ import org.eclipse.jkube.kit.config.resource.RuntimeMode; import io.fabric8.kubernetes.client.KubernetesClient; +import org.eclipse.jkube.kit.resource.helm.HelmConfig; import org.gradle.api.provider.Property; public abstract class OpenShiftExtension extends KubernetesExtension { public static final Path DEFAULT_OPENSHIFT_MANIFEST = Paths.get("META-INF","jkube","openshift.yml"); + private static final Path DEFAULT_OPENSHIFT_TEMPLATE = Paths.get("META-INF", "jkube", "openshift"); private static final String DEFAULT_OPENSHIFT_PULLSECRET = "pullsecret-jkube"; private static final String DEFAULT_S2I_BUILDNAME_SUFFIX = "-s2i"; public static final String DEFAULT_BUILD_OUTPUT_KIND = "ImageStreamTag"; @@ -108,6 +110,15 @@ public boolean isSupportOAuthClients() { return true; } + @Override + public HelmConfig.HelmType getDefaultHelmType() { + return HelmConfig.HelmType.OPENSHIFT; + } + + public File getOpenShiftTemplateOrDefault() { + return getOrDefaultFile("jkube.kubernetesTemplate", this::getKubernetesTemplate, javaProject.getOutputDirectory().toPath().resolve(DEFAULT_OPENSHIFT_TEMPLATE).toFile()); + } + public File getOpenShiftManifestOrDefault() { return getOrDefaultFile("jkube.openshiftManifest", this::getOpenShiftManifest, javaProject.getOutputDirectory().toPath().resolve(DEFAULT_OPENSHIFT_MANIFEST).toFile()); } diff --git a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftPlugin.java b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftPlugin.java index 1898b2e435..aa82ab8ccd 100644 --- a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftPlugin.java +++ b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftPlugin.java @@ -27,6 +27,7 @@ import org.eclipse.jkube.gradle.plugin.task.OpenShiftApplyTask; import org.eclipse.jkube.gradle.plugin.task.OpenShiftBuildTask; import org.eclipse.jkube.gradle.plugin.task.OpenShiftDebugTask; +import org.eclipse.jkube.gradle.plugin.task.OpenShiftHelmTask; import org.eclipse.jkube.gradle.plugin.task.OpenShiftPushTask; import org.eclipse.jkube.gradle.plugin.task.OpenShiftResourceTask; import org.eclipse.jkube.gradle.plugin.task.OpenShiftUndeployTask; @@ -47,6 +48,7 @@ public Map>> getTaskPrecedence() { ret.put("ocDebug", Arrays.asList(KubernetesBuildTask.class, OpenShiftBuildTask.class, KubernetesResourceTask.class, OpenShiftResourceTask.class, KubernetesApplyTask.class, OpenShiftApplyTask.class)); ret.put("ocPush", Arrays.asList(KubernetesBuildTask.class, OpenShiftBuildTask.class)); + ret.put("ocHelm", Arrays.asList(KubernetesResourceTask.class, OpenShiftResourceTask.class)); return ret; } @@ -60,6 +62,7 @@ protected void jKubeApply(Project project) { register(project, "ocPush", OpenShiftPushTask.class); register(project, "ocResource", OpenShiftResourceTask.class); register(project, "ocUndeploy", OpenShiftUndeployTask.class); + register(project, "ocHelm", OpenShiftHelmTask.class); } } diff --git a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTask.java b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTask.java new file mode 100644 index 0000000000..e305d4e6c4 --- /dev/null +++ b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTask.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2019 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at: + * + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.jkube.gradle.plugin.task; + +import org.eclipse.jkube.gradle.plugin.OpenShiftExtension; + +import javax.inject.Inject; +import java.io.File; + +public class OpenShiftHelmTask extends KubernetesHelmTask implements OpenShiftJKubeTask { + + @Inject + public OpenShiftHelmTask(Class extensionClass) { + super(extensionClass); + setDescription( + "Generates a Helm chart for the OpenShift resources."); + } + + @Override + protected File resolveManifest() { + return getOpenShiftExtension().getOpenShiftManifestOrDefault(); + } + + @Override + protected File resolveTemplate() { + return getOpenShiftExtension().getOpenShiftTemplateOrDefault(); + } + + @Override + protected void logManifestNotFoundWarning(File manifest) { + kitLogger.warn("No OpenShift manifest file has been generated yet by the ocResource task at: " + manifest); + } +} diff --git a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftPluginRegisterTaskTest.java b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftPluginRegisterTaskTest.java index b612f1c588..f72ffa4a00 100644 --- a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftPluginRegisterTaskTest.java +++ b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftPluginRegisterTaskTest.java @@ -21,6 +21,7 @@ import org.eclipse.jkube.gradle.plugin.task.OpenShiftApplyTask; import org.eclipse.jkube.gradle.plugin.task.OpenShiftBuildTask; import org.eclipse.jkube.gradle.plugin.task.OpenShiftDebugTask; +import org.eclipse.jkube.gradle.plugin.task.OpenShiftHelmTask; import org.eclipse.jkube.gradle.plugin.task.OpenShiftPushTask; import org.eclipse.jkube.gradle.plugin.task.OpenShiftResourceTask; import org.eclipse.jkube.gradle.plugin.task.OpenShiftUndeployTask; @@ -50,7 +51,8 @@ public static Collection data() { new Object[] { "ocLog", KubernetesLogTask.class }, new Object[] { "ocPush", OpenShiftPushTask.class }, new Object[] { "ocResource", OpenShiftResourceTask.class }, - new Object[] { "ocUndeploy", OpenShiftUndeployTask.class }); + new Object[] { "ocUndeploy", OpenShiftUndeployTask.class }, + new Object[] { "ocHelm", OpenShiftHelmTask.class}); } @Parameterized.Parameter diff --git a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftPluginTest.java b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftPluginTest.java index ced8609f20..60358559ad 100644 --- a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftPluginTest.java +++ b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftPluginTest.java @@ -37,10 +37,11 @@ public void configurePrecedence_withValidProject_shouldReturnTaskPrecedence() { final Map>> result = new OpenShiftPlugin().getTaskPrecedence(); // Then assertThat(result) - .hasSize(3) + .hasSize(4) .containsEntry("ocApply", Arrays.asList(KubernetesResourceTask.class, OpenShiftResourceTask.class)) .containsEntry("ocDebug", Arrays.asList(KubernetesBuildTask.class, OpenShiftBuildTask.class, KubernetesResourceTask.class, OpenShiftResourceTask.class, KubernetesApplyTask.class, OpenShiftApplyTask.class)) - .containsEntry("ocPush", Arrays.asList(KubernetesBuildTask.class, OpenShiftBuildTask.class)); + .containsEntry("ocPush", Arrays.asList(KubernetesBuildTask.class, OpenShiftBuildTask.class)) + .containsEntry("ocHelm", Arrays.asList(KubernetesResourceTask.class, OpenShiftResourceTask.class)); } } diff --git a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTaskTest.java b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTaskTest.java new file mode 100644 index 0000000000..ce7f81780c --- /dev/null +++ b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTaskTest.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2019 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at: + * + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.jkube.gradle.plugin.task; + +import org.eclipse.jkube.gradle.plugin.OpenShiftExtension; +import org.eclipse.jkube.gradle.plugin.TestOpenShiftExtension; +import org.eclipse.jkube.kit.resource.helm.HelmService; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.MockedConstruction; + +import java.io.IOException; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.Assert.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mockConstruction; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class OpenShiftHelmTaskTest { + @Rule + public TaskEnvironment taskEnvironment = new TaskEnvironment(); + + private TestOpenShiftExtension extension; + private MockedConstruction helmServiceMockedConstruction; + + @Before + public void setUp() { + extension = new TestOpenShiftExtension(); + helmServiceMockedConstruction = mockConstruction(HelmService.class); + when(taskEnvironment.project.getExtensions().getByType(OpenShiftExtension.class)).thenReturn(extension); + } + + @Test + public void runTask_withNoTemplateDir_shouldThrowException() { + // Given + OpenShiftHelmTask kubernetesHelmTask = new OpenShiftHelmTask(OpenShiftExtension.class); + + // When + IllegalStateException illegalStateException = assertThrows(IllegalStateException.class, kubernetesHelmTask::runTask); + + // Then + assertThat(illegalStateException) + .hasMessageContaining("META-INF/jkube/openshift (No such file or directory)"); + } + + @Test + public void runTask_withTemplateDir_shouldCallHelmService() throws IOException { + // Given + taskEnvironment.withOpenShiftTemplate(); + OpenShiftHelmTask kubernetesHelmTask = new OpenShiftHelmTask(OpenShiftExtension.class); + + // When + kubernetesHelmTask.runTask(); + + // Then + verify((helmServiceMockedConstruction.constructed().iterator().next()), times(1)).generateHelmCharts(any()); + } + + @After + public void tearDown() { + helmServiceMockedConstruction.close(); + } +} diff --git a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskEnvironment.java b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskEnvironment.java index a7e976d7fc..3b85516c65 100644 --- a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskEnvironment.java +++ b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/task/TaskEnvironment.java @@ -62,4 +62,8 @@ public void withOpenShiftManifest() throws IOException { final File manifestsDir = newFolder("build", "classes", "java", "main", "META-INF", "jkube"); FileUtils.touch(new File(manifestsDir, "openshift.yml").toPath()); } + + public void withOpenShiftTemplate() throws IOException { + newFolder("build", "classes", "java", "main", "META-INF", "jkube", "openshift"); + } } diff --git a/quickstarts/gradle/spring-boot-helm/build.gradle b/quickstarts/gradle/spring-boot-helm/build.gradle index e95728ac10..d53202f84b 100644 --- a/quickstarts/gradle/spring-boot-helm/build.gradle +++ b/quickstarts/gradle/spring-boot-helm/build.gradle @@ -41,3 +41,26 @@ kubernetes { }] } } + +openshift { + resources { + labels { + all { + testProject = 'spring-boot-with-yaml-label-for-all' + } + } + } + generator { + config { + 'spring-boot' { + color = 'always' + } + } + } + helm { + maintainers = [{ + name = 'John' + email = 'john.doe@example.com' + }] + } +} From b693e5f41dba784caa17f55305302890dedb8f37 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 27 Oct 2021 16:51:56 +0530 Subject: [PATCH 4/5] Remove usage of getOpenShiftManifestOrDefault from OpenShiftExtension We had getOpenShiftManifestOrDefault method in OpenShiftExtension which was used for getting openshift manifests in case of OpenShift. However, this seemed redundant as we had getManifest method in KubernetesExtension(overridden in OpenShiftExtension) for same task. To keep it simple, remove getOpenShiftManifstOrDefault method from OpenShiftExtension and override getKubernetesManifestOrDefault method in OpenShiftExtension Signed-off-by: Rohan Kumar --- .../jkube/gradle/plugin/task/KubernetesHelmTask.java | 12 ++---------- .../gradle/plugin/task/KubernetesUndeployTask.java | 6 +----- .../jkube/gradle/plugin/OpenShiftExtension.java | 10 ++++++---- .../jkube/gradle/plugin/task/OpenShiftHelmTask.java | 10 ---------- .../gradle/plugin/task/OpenShiftUndeployTask.java | 5 ----- .../plugin/OpenShiftExtensionPropertyTest.java | 2 +- 6 files changed, 10 insertions(+), 35 deletions(-) diff --git a/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTask.java b/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTask.java index 18f8997620..2eb8b139ab 100644 --- a/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTask.java +++ b/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmTask.java @@ -32,12 +32,12 @@ public KubernetesHelmTask(Class extensionClass) { @Override public void run() { try { - File manifest = resolveManifest(); + File manifest = kubernetesExtension.getKubernetesManifestOrDefault(); if (manifest == null || !manifest.isFile()) { logManifestNotFoundWarning(manifest); } HelmConfig helm = initHelmConfig(kubernetesExtension.getDefaultHelmType(), kubernetesExtension.javaProject, - resolveManifest(), resolveTemplate(), + kubernetesExtension.getKubernetesManifestOrDefault(), kubernetesExtension.getKubernetesTemplateOrDefault(), kubernetesExtension.helm).build(); jKubeServiceHub.getHelmService().generateHelmCharts(helm); } catch (IOException exception) { @@ -45,14 +45,6 @@ public void run() { } } - protected File resolveManifest() { - return kubernetesExtension.getKubernetesManifestOrDefault(); - } - - protected File resolveTemplate() { - return kubernetesExtension.getKubernetesTemplateOrDefault(); - } - protected void logManifestNotFoundWarning(File manifest) { kitLogger.warn("No kubernetes manifest file has been generated yet by the k8sResource task at: " + manifest); } diff --git a/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesUndeployTask.java b/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesUndeployTask.java index fde499cfe2..7ff7c50a75 100644 --- a/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesUndeployTask.java +++ b/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesUndeployTask.java @@ -52,13 +52,9 @@ public void run() { } } - protected File findResources() { - return kubernetesExtension.getKubernetesManifestOrDefault(); - } - protected List findManifestsToUndeploy() { final List ret = new ArrayList<>(); - ret.add(findResources()); + ret.add(kubernetesExtension.getKubernetesManifestOrDefault()); return ret; } } \ No newline at end of file diff --git a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtension.java b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtension.java index e29f20ab9c..9c09167199 100644 --- a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtension.java +++ b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtension.java @@ -73,9 +73,9 @@ public ResourceClassifier getResourceClassifier() { @Override public File getManifest(KitLogger kitLogger, KubernetesClient kubernetesClient) { if (OpenshiftHelper.isOpenShift(kubernetesClient)) { - return getOpenShiftManifestOrDefault(); + return getKubernetesManifestOrDefault(); } - return getKubernetesManifestOrDefault(); + return super.getKubernetesManifestOrDefault(); } @Override @@ -115,11 +115,13 @@ public HelmConfig.HelmType getDefaultHelmType() { return HelmConfig.HelmType.OPENSHIFT; } - public File getOpenShiftTemplateOrDefault() { + @Override + public File getKubernetesTemplateOrDefault() { return getOrDefaultFile("jkube.kubernetesTemplate", this::getKubernetesTemplate, javaProject.getOutputDirectory().toPath().resolve(DEFAULT_OPENSHIFT_TEMPLATE).toFile()); } - public File getOpenShiftManifestOrDefault() { + @Override + public File getKubernetesManifestOrDefault() { return getOrDefaultFile("jkube.openshiftManifest", this::getOpenShiftManifest, javaProject.getOutputDirectory().toPath().resolve(DEFAULT_OPENSHIFT_MANIFEST).toFile()); } diff --git a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTask.java b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTask.java index e305d4e6c4..afbc005780 100644 --- a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTask.java +++ b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTask.java @@ -27,16 +27,6 @@ public OpenShiftHelmTask(Class extensionClass) { "Generates a Helm chart for the OpenShift resources."); } - @Override - protected File resolveManifest() { - return getOpenShiftExtension().getOpenShiftManifestOrDefault(); - } - - @Override - protected File resolveTemplate() { - return getOpenShiftExtension().getOpenShiftTemplateOrDefault(); - } - @Override protected void logManifestNotFoundWarning(File manifest) { kitLogger.warn("No OpenShift manifest file has been generated yet by the ocResource task at: " + manifest); diff --git a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftUndeployTask.java b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftUndeployTask.java index 555167c200..c5a8760268 100644 --- a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftUndeployTask.java +++ b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftUndeployTask.java @@ -27,11 +27,6 @@ public OpenShiftUndeployTask(Class extensionClass) "Undeploys (deletes) the OpenShift resources generated by the current project."); } - @Override - protected File findResources() { - return getOpenShiftExtension().getOpenShiftManifestOrDefault(); - } - @Override protected List findManifestsToUndeploy() { final List ret = super.findManifestsToUndeploy(); diff --git a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtensionPropertyTest.java b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtensionPropertyTest.java index 9c3fefca0f..b42c9d9ce5 100644 --- a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtensionPropertyTest.java +++ b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtensionPropertyTest.java @@ -50,7 +50,7 @@ public static Collection data() { new Object[] { "getBuildOutputKindOrDefault", "jkube.build.buildOutput.kind", "DockerImage", "DockerImage", "ImageStreamTag" }, new Object[] { "getProcessTemplatesLocallyOrDefault", "jkube.deploy.processTemplatesLocally", "true", true, false }, - new Object[] { "getOpenShiftManifestOrDefault", "jkube.openshiftManifest", + new Object[] { "getKubernetesManifestOrDefault", "jkube.openshiftManifest", Paths.get("META-INF", "jkube", "other.yml").toString(), Paths.get("META-INF", "jkube", "other.yml").toFile(), new File(BASE, "build").toPath().resolve(Paths.get("META-INF", "jkube", "openshift.yml")).toFile() }, From 0fa094eb8800bf888a0f7a0c5d86ff16a7e99cee Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 27 Oct 2021 17:18:38 +0530 Subject: [PATCH 5/5] OpenShiftExtensionPropertyTest: Add test for getKubernetesTemplateOrDefault Add test for getKubernetesTemplateOrDefault's overridden implementation in OpenShiftExtension Signed-off-by: Rohan Kumar --- .../gradle/plugin/OpenShiftExtensionPropertyTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtensionPropertyTest.java b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtensionPropertyTest.java index b42c9d9ce5..93656dbd24 100644 --- a/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtensionPropertyTest.java +++ b/gradle-plugin/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/OpenShiftExtensionPropertyTest.java @@ -16,10 +16,7 @@ import org.eclipse.jkube.kit.common.JavaProject; import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy; import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -58,6 +55,11 @@ public static Collection data() { Paths.get("test-project-is.yml").toString(), Paths.get("test-project-is.yml").toFile(), new File(BASE, "build").toPath().resolve("artifact-id-is.yml").toFile() + }, + new Object[] { "getKubernetesTemplateOrDefault", "jkube.kubernetesTemplate", + Paths.get("META-INF", "jkube", "other").toString(), + Paths.get("META-INF", "jkube", "other").toFile(), + new File(BASE, "build").toPath().resolve(Paths.get("META-INF", "jkube", "openshift")).toFile() } ); }