Skip to content

Commit

Permalink
Merge branch 'eclipse-jkube:master' into gh_2467-experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
arman-yekkehkhani authored Jun 5, 2024
2 parents 26eb38b + 740279f commit b16ea84
Show file tree
Hide file tree
Showing 40 changed files with 712 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Usage:
* Fix #2904: `docker.buildArg.*` properties not taken into account in OpenShift plugins
* Fix #3007: Kubernetes Maven Plugin generating resource manifests with line feeds on Windows
* Fix #3067: Helm Push uses configured docker global and push registries instead of pull
* Fix #2110: Add new helm dependency update goal task (`k8s:helm-dependency-update` for maven and `k8sHelmDependencyUpdate` for gradle)
* Fix #3122: JKube should also pass project directory in `buildpacks` build strategy

### 1.16.2 (2024-03-27)
* Fix #2461: `k8s:watch`/`k8sWatch` should throw error in `buildpacks` build strategy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ include::{kitdoc-path}/inc/helm/_jkube_helm.adoc[]
include::{kitdoc-path}/inc/helm/_jkube_helm_push.adoc[]

include::{kitdoc-path}/inc/helm/_jkube_helm_lint.adoc[]

include::{kitdoc-path}/inc/helm/_jkube_helm_dependency_update.adoc[]
2 changes: 1 addition & 1 deletion gradle-plugin/it/src/it/helidon-properties/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tasks.withType(JavaCompile) {
}

ext {
helidonversion = '2.6.0'
helidonversion = '2.6.7'
mainClass='io.helidon.microprofile.cdi.Main'
}

Expand Down
2 changes: 1 addition & 1 deletion gradle-plugin/it/src/it/helidon/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tasks.withType(JavaCompile) {
}

ext {
helidonversion = '2.6.0'
helidonversion = '2.6.7'
mainClass='io.helidon.microprofile.cdi.Main'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ITGradleRunnerExtension implements BeforeEachCallback, AfterEachCal
@Override
public void beforeEach(ExtensionContext context) throws Exception {
gradleRunner = GradleRunner.create()
.withGradleDistribution(new URI("https://services.gradle.org/distributions/gradle-8.2.1-bin.zip"))
.withGradleDistribution(new URI("https://services.gradle.org/distributions/gradle-8.8-bin.zip"))
.withDebug(true)
.withPluginClasspath(Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator))
.map(File::new).collect(Collectors.toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.jkube.gradle.plugin.task.KubernetesBuildTask;
import org.eclipse.jkube.gradle.plugin.task.KubernetesConfigViewTask;
import org.eclipse.jkube.gradle.plugin.task.KubernetesDebugTask;
import org.eclipse.jkube.gradle.plugin.task.KubernetesHelmDependencyUpdateTask;
import org.eclipse.jkube.gradle.plugin.task.KubernetesHelmLintTask;
import org.eclipse.jkube.gradle.plugin.task.KubernetesHelmPushTask;
import org.eclipse.jkube.gradle.plugin.task.KubernetesHelmTask;
Expand Down Expand Up @@ -51,6 +52,7 @@ public Map<String, Collection<Class<? extends Task>>> getTaskPrecedence() {
ret.put("k8sHelm", Collections.singletonList(KubernetesResourceTask.class));
ret.put("k8sHelmPush", Collections.singletonList(KubernetesHelmTask.class));
ret.put("k8sHelmLint", Collections.singletonList(KubernetesHelmTask.class));
ret.put("k8sHelmDependencyUpdate", Collections.singletonList(KubernetesHelmTask.class));
return ret;
}

Expand All @@ -67,6 +69,7 @@ protected void jKubeApply(Project project) {
register(project, "k8sHelm", KubernetesHelmTask.class);
register(project, "k8sHelmPush", KubernetesHelmPushTask.class);
register(project, "k8sHelmLint", KubernetesHelmLintTask.class);
register(project, "k8sHelmDependencyUpdate", KubernetesHelmDependencyUpdateTask.class);
register(project, "k8sRemoteDev", KubernetesRemoteDevTask.class);
register(project, "k8sWatch", KubernetesWatchTask.class);
}
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ void getTaskPrecedence_withValidProject_shouldReturnTaskPrecedence() {
final Map<String, Collection<Class<? extends Task>>> result = new KubernetesPlugin().getTaskPrecedence();
// Then
assertThat(result)
.hasSize(6)
.hasSize(7)
.containsEntry("k8sApply", Collections.singletonList(KubernetesResourceTask.class))
.containsEntry("k8sDebug",
Arrays.asList(KubernetesBuildTask.class, KubernetesResourceTask.class, KubernetesApplyTask.class))
.containsEntry("k8sPush", Collections.singletonList(KubernetesBuildTask.class))
.containsEntry("k8sHelm", Collections.singletonList(KubernetesResourceTask.class))
.containsEntry("k8sHelmDependencyUpdate", Collections.singletonList(KubernetesHelmTask.class))
.containsEntry("k8sHelmPush", Collections.singletonList(KubernetesHelmTask.class))
.containsEntry("k8sHelmLint", Collections.singletonList(KubernetesHelmTask.class));
}
Expand Down
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.OpenShiftHelmDependencyUpdateTask;
import org.eclipse.jkube.gradle.plugin.task.OpenShiftHelmLintTask;
import org.eclipse.jkube.gradle.plugin.task.OpenShiftHelmPushTask;
import org.eclipse.jkube.gradle.plugin.task.OpenShiftHelmTask;
Expand Down Expand Up @@ -55,6 +56,7 @@ public Map<String, Collection<Class<? extends Task>>> getTaskPrecedence() {
ret.put("ocHelm", Arrays.asList(KubernetesResourceTask.class, OpenShiftResourceTask.class));
ret.put("ocHelmPush", Arrays.asList(KubernetesHelmTask.class, OpenShiftHelmTask.class));
ret.put("ocHelmLint", Arrays.asList(KubernetesHelmTask.class, OpenShiftHelmTask.class));
ret.put("ocHelmDependencyUpdate", Arrays.asList(KubernetesHelmTask.class, OpenShiftHelmTask.class));
return ret;
}

Expand All @@ -71,6 +73,7 @@ protected void jKubeApply(Project project) {
register(project, "ocHelm", OpenShiftHelmTask.class);
register(project, "ocHelmPush", OpenShiftHelmPushTask.class);
register(project, "ocHelmLint", OpenShiftHelmLintTask.class);
register(project, "ocHelmDependencyUpdate", OpenShiftHelmDependencyUpdateTask.class);
register(project, "ocRemoteDev", OpenShiftRemoteDevTask.class);
register(project, "ocWatch", OpenShiftWatchTask.class);
}
Expand Down
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ void configurePrecedence_withValidProject_shouldReturnTaskPrecedence() {
final Map<String, Collection<Class<? extends Task>>> result = new OpenShiftPlugin().getTaskPrecedence();
// Then
assertThat(result)
.hasSize(6)
.hasSize(7)
.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("ocHelm", Arrays.asList(KubernetesResourceTask.class, OpenShiftResourceTask.class))
.containsEntry("ocHelmDependencyUpdate", Arrays.asList(KubernetesHelmTask.class, OpenShiftHelmTask.class))
.containsEntry("ocHelmPush", Arrays.asList(KubernetesHelmTask.class, OpenShiftHelmTask.class))
.containsEntry("ocHelmLint", Arrays.asList(KubernetesHelmTask.class, OpenShiftHelmTask.class));
}
Expand Down
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ public class BuildPackBuildOptions {
private List<String> tags;
private Map<String, String> env;
private List<String> volumes;
private String path;
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private List<String> createBuildCommandArguments(BuildPackBuildOptions buildOpti
if (buildOptions.isClearCache()) {
buildArgs.add("--clear-cache");
}
buildArgs.addAll(Arrays.asList("--path", buildOptions.getPath()));
return buildArgs;
}

Expand Down
Loading

0 comments on commit b16ea84

Please sign in to comment.