forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'eclipse-jkube:master' into gh_2467-experimental
- Loading branch information
Showing
40 changed files
with
712 additions
and
50 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
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
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
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
...rc/main/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmDependencyUpdateTask.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 KubernetesHelmDependencyUpdateTask extends AbstractJKubeTask { | ||
@Inject | ||
public KubernetesHelmDependencyUpdateTask(Class<? extends KubernetesExtension> extensionClass) { | ||
super(extensionClass); | ||
setDescription("Update the on-disk dependencies to mirror Chart.yaml"); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (kubernetesExtension.getSkipOrDefault()) { | ||
return; | ||
} | ||
try { | ||
final HelmConfig helm = initHelmConfig(kubernetesExtension.getDefaultHelmType(), kubernetesExtension.javaProject, | ||
kubernetesExtension.getKubernetesTemplateOrDefault(), | ||
kubernetesExtension.helm) | ||
.build(); | ||
jKubeServiceHub.getHelmService().dependencyUpdate(helm); | ||
} catch (Exception exp) { | ||
kitLogger.error("Error performing helm dependency update", 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
89 changes: 89 additions & 0 deletions
89
...est/java/org/eclipse/jkube/gradle/plugin/task/KubernetesHelmDependencyUpdateTaskTest.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,89 @@ | ||
/* | ||
* 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.apache.commons.io.FileUtils; | ||
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 java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardOpenOption; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
class KubernetesHelmDependencyUpdateTaskTest { | ||
@RegisterExtension | ||
private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); | ||
|
||
@BeforeEach | ||
void setUp() throws IOException { | ||
final TestKubernetesExtension extension = new TestKubernetesExtension(); | ||
Helm.create().withDir(taskEnvironment.getRoot().toPath()).withName("empty-project").call(); | ||
Path helmChartOutputDir = taskEnvironment.getRoot().toPath().resolve("build").resolve("jkube").resolve("helm"); | ||
Files.createDirectories(helmChartOutputDir.resolve("kubernetes")); | ||
FileUtils.copyDirectory(taskEnvironment.getRoot().toPath().resolve("empty-project").toFile(), helmChartOutputDir.resolve("kubernetes").toFile()); | ||
Files.write(helmChartOutputDir.resolve("kubernetes").resolve("Chart.yaml"), | ||
("\ndependencies:\n" + | ||
" - name: the-dependency\n" + | ||
" version: 0.1.0\n" + | ||
" repository: file://../../../../the-dependency\n").getBytes(StandardCharsets.UTF_8), | ||
StandardOpenOption.APPEND); | ||
System.setProperty("jkube.kubernetesTemplate", taskEnvironment.getRoot().getAbsolutePath()); | ||
extension.helm = HelmConfig.builder().chartExtension("tgz").outputDir(helmChartOutputDir.toString()).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_withInvalidHelmDependency_shouldThrowException() { | ||
// Given | ||
KubernetesHelmDependencyUpdateTask kubernetesHelmDependencyUpdateTask = new KubernetesHelmDependencyUpdateTask(KubernetesExtension.class); | ||
// When + Then | ||
assertThatThrownBy(kubernetesHelmDependencyUpdateTask::runTask) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessageContaining("the-dependency not found"); | ||
} | ||
|
||
@Test | ||
void runTask_withHelmDependencyPresent_shouldSucceed() { | ||
// Given | ||
KubernetesHelmDependencyUpdateTask kubernetesHelmDependencyUpdateTask = new KubernetesHelmDependencyUpdateTask(KubernetesExtension.class); | ||
Helm.create().withName("the-dependency").withDir(taskEnvironment.getRoot().toPath()).call(); | ||
|
||
// When | ||
kubernetesHelmDependencyUpdateTask.runTask(); | ||
// Then | ||
verify(taskEnvironment.logger).lifecycle("k8s: Running Helm Dependency Upgrade empty-project 0.1.0"); | ||
verify(taskEnvironment.logger).lifecycle("k8s: Saving 1 charts"); | ||
verify(taskEnvironment.logger).lifecycle("k8s: Deleting outdated charts"); | ||
} | ||
} |
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
...src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmDependencyUpdateTask.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 OpenShiftHelmDependencyUpdateTask extends KubernetesHelmDependencyUpdateTask implements OpenShiftJKubeTask { | ||
@Inject | ||
public OpenShiftHelmDependencyUpdateTask(Class<? extends OpenShiftExtension> extensionClass) { | ||
super(extensionClass); | ||
setDescription("Update the on-disk dependencies to mirror Chart.yaml"); | ||
} | ||
} |
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
89 changes: 89 additions & 0 deletions
89
...test/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmDependencyUpdateTaskTest.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,89 @@ | ||
/* | ||
* 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.apache.commons.io.FileUtils; | ||
import org.eclipse.jkube.gradle.plugin.OpenShiftExtension; | ||
import org.eclipse.jkube.gradle.plugin.TestOpenShiftExtension; | ||
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 java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardOpenOption; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
class OpenShiftHelmDependencyUpdateTaskTest { | ||
@RegisterExtension | ||
private final TaskEnvironmentExtension taskEnvironment = new TaskEnvironmentExtension(); | ||
|
||
@BeforeEach | ||
void setUp() throws IOException { | ||
final TestOpenShiftExtension extension = new TestOpenShiftExtension(); | ||
Helm.create().withDir(taskEnvironment.getRoot().toPath()).withName("empty-project").call(); | ||
Path helmChartOutputDir = taskEnvironment.getRoot().toPath().resolve("build").resolve("jkube").resolve("helm"); | ||
Files.createDirectories(helmChartOutputDir.resolve("openshift")); | ||
FileUtils.copyDirectory(taskEnvironment.getRoot().toPath().resolve("empty-project").toFile(), helmChartOutputDir.resolve("openshift").toFile()); | ||
Files.write(helmChartOutputDir.resolve("openshift").resolve("Chart.yaml"), | ||
("\ndependencies:\n" + | ||
" - name: the-dependency\n" + | ||
" version: 0.1.0\n" + | ||
" repository: file://../../../../the-dependency\n").getBytes(StandardCharsets.UTF_8), | ||
StandardOpenOption.APPEND); | ||
System.setProperty("jkube.kubernetesTemplate", taskEnvironment.getRoot().getAbsolutePath()); | ||
extension.helm = HelmConfig.builder().chartExtension("tgz").outputDir(helmChartOutputDir.toString()).build(); | ||
extension.isUseColor = false; | ||
when(taskEnvironment.project.getName()).thenReturn("empty-project"); | ||
when(taskEnvironment.project.getVersion()).thenReturn("0.1.0"); | ||
when(taskEnvironment.project.getExtensions().getByType(OpenShiftExtension.class)).thenReturn(extension); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
System.clearProperty("jkube.kubernetesTemplate"); | ||
} | ||
|
||
@Test | ||
void runTask_withInvalidHelmDependency_shouldThrowException() { | ||
// Given | ||
OpenShiftHelmDependencyUpdateTask openShiftHelmDependencyUpdateTask = new OpenShiftHelmDependencyUpdateTask(OpenShiftExtension.class); | ||
// When + Then | ||
assertThatThrownBy(openShiftHelmDependencyUpdateTask::runTask) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessageContaining("the-dependency not found"); | ||
} | ||
|
||
@Test | ||
void runTask_withHelmDependencyPresent_shouldSucceed() { | ||
// Given | ||
OpenShiftHelmDependencyUpdateTask openShiftHelmDependencyUpdateTask = new OpenShiftHelmDependencyUpdateTask(OpenShiftExtension.class); | ||
Helm.create().withName("the-dependency").withDir(taskEnvironment.getRoot().toPath()).call(); | ||
|
||
// When | ||
openShiftHelmDependencyUpdateTask.runTask(); | ||
// Then | ||
verify(taskEnvironment.logger).lifecycle("oc: Running Helm Dependency Upgrade empty-project 0.1.0"); | ||
verify(taskEnvironment.logger).lifecycle("oc: Saving 1 charts"); | ||
verify(taskEnvironment.logger).lifecycle("oc: Deleting outdated charts"); | ||
} | ||
} |
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.