-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: helm lint exposed in Gradle and Maven plugins
Signed-off-by: Marc Nuri <marc@marcnuri.com>
- Loading branch information
Showing
16 changed files
with
534 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 | ||
*/ | ||
plugins { | ||
id 'org.eclipse.jkube.kubernetes' version "${jKubeVersion}" | ||
id 'org.eclipse.jkube.openshift' version "${jKubeVersion}" | ||
id 'java' | ||
} | ||
|
||
group = 'org.eclipse.jkube.integration.tests.gradle' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = '11' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
def extensionConfig = { | ||
offline = true | ||
images { | ||
image { | ||
name = 'repository/helm-fragment:latest' | ||
build { | ||
from = 'repository/from:latest' | ||
} | ||
} | ||
} | ||
} | ||
|
||
kubernetes(extensionConfig) | ||
openshift(extensionConfig) | ||
|
56 changes: 56 additions & 0 deletions
56
gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/HelmLintIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.tests; | ||
|
||
import org.gradle.testkit.runner.BuildResult; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
class HelmLintIT { | ||
|
||
@RegisterExtension | ||
public final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension(); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
gradleRunner.withITProject("helm-lint"); | ||
} | ||
|
||
@Test | ||
void k8sHelmLint() { | ||
// When | ||
final BuildResult result = gradleRunner | ||
.withArguments("clean", "k8sResource", "k8sHelm", "k8sHelmLint").build(); | ||
// Then | ||
assertThat(result).extracting(BuildResult::getOutput).asString() | ||
.contains("k8s: Linting helm-lint 0.0.1-SNAPSHOT") | ||
.contains("k8s: [INFO] Chart.yaml: icon is recommended") | ||
.contains("k8s: Linting successful"); | ||
} | ||
|
||
@Test | ||
void ocHelmLint() { | ||
// When | ||
final BuildResult result = gradleRunner | ||
.withArguments("clean", "ocResource", "ocHelm", "ocHelmLint").build(); | ||
// Then | ||
assertThat(result).extracting(BuildResult::getOutput).asString() | ||
.contains("oc: Linting helm-lint 0.0.1-SNAPSHOT") | ||
.contains("oc: [INFO] Chart.yaml: icon is recommended") | ||
.contains("oc: Linting successful"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmLintTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.KubernetesExtension; | ||
import org.eclipse.jkube.kit.resource.helm.HelmConfig; | ||
|
||
import javax.inject.Inject; | ||
|
||
import static org.eclipse.jkube.kit.resource.helm.HelmServiceUtil.initHelmConfig; | ||
|
||
public class KubernetesHelmLintTask extends AbstractJKubeTask { | ||
@Inject | ||
public KubernetesHelmLintTask(Class<? extends KubernetesExtension> extensionClass) { | ||
super(extensionClass); | ||
setDescription("Examine Helm chart for possible issues"); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (kubernetesExtension.getSkipOrDefault()) { | ||
return; | ||
} | ||
try { | ||
final HelmConfig helm = initHelmConfig(kubernetesExtension.getDefaultHelmType(), kubernetesExtension.javaProject, | ||
kubernetesExtension.getKubernetesTemplateOrDefault(), | ||
kubernetesExtension.helm) | ||
.build(); | ||
jKubeServiceHub.getHelmService().lint(helm); | ||
} catch (Exception exp) { | ||
kitLogger.error("Error performing helm lint", exp); | ||
throw new IllegalStateException(exp.getMessage(), exp); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...rnetes/src/test/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmLintTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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 com.marcnuri.helm.Helm; | ||
import org.eclipse.jkube.gradle.plugin.KubernetesExtension; | ||
import org.eclipse.jkube.gradle.plugin.TestKubernetesExtension; | ||
import org.eclipse.jkube.kit.resource.helm.HelmConfig; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.mockito.ArgumentMatchers.startsWith; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
class KubernetesHelmLintTaskTest { | ||
|
||
@RegisterExtension | ||
private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); | ||
|
||
@BeforeEach | ||
void setUp() throws IOException { | ||
System.setProperty("jkube.kubernetesTemplate", taskEnvironment.getRoot().getAbsolutePath()); | ||
final TestKubernetesExtension extension = new TestKubernetesExtension(); | ||
extension.helm = HelmConfig.builder().chartExtension("tgz").build(); | ||
extension.isUseColor = false; | ||
when(taskEnvironment.project.getName()).thenReturn("empty-project"); | ||
when(taskEnvironment.project.getVersion()).thenReturn("0.1.0"); | ||
when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
System.clearProperty("jkube.kubernetesTemplate"); | ||
} | ||
|
||
@Test | ||
void runTask_withMissingHelmPackage_shouldThrowException() { | ||
KubernetesHelmLintTask kubernetesHelmLintTask = new KubernetesHelmLintTask(KubernetesExtension.class); | ||
assertThatThrownBy(kubernetesHelmLintTask::runTask) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessage("Linting failed"); | ||
verify(taskEnvironment.logger).lifecycle("k8s: Linting empty-project 0.1.0"); | ||
verify(taskEnvironment.logger).lifecycle(startsWith("k8s: Using packaged file:")); | ||
} | ||
|
||
@Test | ||
void runTask_withHelmPackage_shouldSucceed() { | ||
KubernetesHelmLintTask kubernetesHelmLintTask = new KubernetesHelmLintTask(KubernetesExtension.class); | ||
Helm.create().withDir(taskEnvironment.getRoot().toPath()).withName("empty-project").call() | ||
.packageIt().withDestination(taskEnvironment.getRoot().toPath().resolve("build").resolve("jkube").resolve("helm").resolve("empty-project").resolve("kubernetes")).call(); | ||
kubernetesHelmLintTask.runTask(); | ||
verify(taskEnvironment.logger).lifecycle("k8s: Linting empty-project 0.1.0"); | ||
verify(taskEnvironment.logger).lifecycle(startsWith("k8s: Using packaged file:")); | ||
verify(taskEnvironment.logger).lifecycle("k8s: [INFO] Chart.yaml: icon is recommended"); | ||
verify(taskEnvironment.logger).lifecycle("k8s: Linting successful"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...n/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmLintTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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; | ||
|
||
public class OpenShiftHelmLintTask extends KubernetesHelmLintTask implements OpenShiftJKubeTask { | ||
@Inject | ||
public OpenShiftHelmLintTask(Class<? extends OpenShiftExtension> extensionClass) { | ||
super(extensionClass); | ||
setDescription("Examine Helm chart for possible issues"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.