diff --git a/CHANGELOG.md b/CHANGELOG.md index 8edd574ca5..b00eac8bd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Usage: ### 1.3.0-SNAPSHOT * Fix #576: Add support to publishing helm chart * Fix #634: Replace occutrences of keySet() with entrySet() when value are needed +* Fix #578: NullPointerException in ContainerEnvJavaOptionsMergeEnricher on k8s:resource ### 1.2.0 (2021-03-31) * Fix #529: `.maven-dockerignore`, `.maven-dockerexclude`, `.maven-dockerinclude` are no longer supported diff --git a/jkube-kit/enricher/generic/src/main/java/org/eclipse/jkube/enricher/generic/ContainerEnvJavaOptionsMergeEnricher.java b/jkube-kit/enricher/generic/src/main/java/org/eclipse/jkube/enricher/generic/ContainerEnvJavaOptionsMergeEnricher.java index 0a4b565850..501e16b34e 100644 --- a/jkube-kit/enricher/generic/src/main/java/org/eclipse/jkube/enricher/generic/ContainerEnvJavaOptionsMergeEnricher.java +++ b/jkube-kit/enricher/generic/src/main/java/org/eclipse/jkube/enricher/generic/ContainerEnvJavaOptionsMergeEnricher.java @@ -77,6 +77,7 @@ public ContainerEnvJavaOptionsMergeVisitor(List imageConfigu public void visit(ContainerBuilder containerBuilder) { imageConfigurations.stream() .filter(ic -> ImageEnricher.containerImageName(ic).equals(containerBuilder.getImage())) + .filter(ic -> ic.getBuild() != null) .filter(ic -> ic.getBuild().getEnv() != null) .filter(ic -> !ic.getBuild().getEnv().isEmpty()) .filter(ic -> ic.getBuild().getEnv().containsKey(ENV_KEY)) diff --git a/jkube-kit/enricher/generic/src/test/java/org/eclipse/jkube/enricher/generic/ContainerEnvJavaOptionsMergeTest.java b/jkube-kit/enricher/generic/src/test/java/org/eclipse/jkube/enricher/generic/ContainerEnvJavaOptionsMergeTest.java index defde4274c..2cb82de6b5 100644 --- a/jkube-kit/enricher/generic/src/test/java/org/eclipse/jkube/enricher/generic/ContainerEnvJavaOptionsMergeTest.java +++ b/jkube-kit/enricher/generic/src/test/java/org/eclipse/jkube/enricher/generic/ContainerEnvJavaOptionsMergeTest.java @@ -104,6 +104,24 @@ public void enrichWithDisabledShouldDoNothing() { .containsOnly(new EnvVar("JAVA_OPTIONS", "val-from-container", null)); } + @Test + public void enrichWithNullBuildInImageConfiguration() { + // Given + // @formatter:off + new Expectations() {{ + imageConfiguration.getName(); result = "the-image:latest"; minTimes = 0; + imageConfiguration.getBuild(); result = null; + }}; + // @formatter:on + // When + containerEnvJavaOptionsMergeEnricher.enrich(PlatformMode.kubernetes, kubernetesListBuilder); + // Then + assertThat(containerList(kubernetesListBuilder)) + .flatExtracting("env") + .hasSize(1) + .containsOnly(new EnvVar("JAVA_OPTIONS", "val-from-container", null)); + } + @Test public void enrichWithNullEnvInImageConfiguration() { // Given diff --git a/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/_faq.adoc b/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/_faq.adoc index c65dc20876..f0ee215fe0 100644 --- a/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/_faq.adoc +++ b/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/_faq.adoc @@ -141,3 +141,21 @@ You can also provide a host for it in XML config like this: You can find an example in our link:https://github.com/eclipse/jkube/tree/master/quickstarts/maven/spring-boot[spring-boot] quickstart in `kubernetes-with-ingress` profile. + +=== How to configure image name generated by Eclipse JKube? + +If you want to configure image name generated by Eclipse JKube which is `%g/%a:%l` by default(see <>). It will depend upon what mode you're using in Eclipse JKube: + +- If you're using zero configuration mode, which means you depend on Eclipse JKube <> to generate an opinionated image, you might be able to do it using `jkube.generator.name` flag. +- If you're providing XML image configuration, image name would be picked from `` tag like in this example: +[source,xml,indent=0,subs="verbatim,quotes,attributes"] +---- + + myusername/myimagename:latest + + openjdk:latest + java -jar maven/${project.artifactId}-${project.version}.jar + + +---- +- If you're using <>, you can configure image name via `jkube.image.name` or `jkube.generator.name` flags diff --git a/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/generator/_options_common.adoc b/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/generator/_options_common.adoc index 932b99e893..8170f77bb7 100644 --- a/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/generator/_options_common.adoc +++ b/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/generator/_options_common.adoc @@ -31,7 +31,9 @@ There are some configuration options which are shared by all generators: | *name* | The Docker image name used when doing Docker builds. For OpenShift S2I builds its the name of the image stream. This - can be a pattern as descibed in <>. The default is `%g/%a:%l`. + can be a pattern as described in <>. The default is `%g/%a:%l`. Note that this flag would only work + when you're using opinionated image configuration provided by generators. if generators are not applicable for your project configuration, this + flag won't work. | `jkube.generator.name` | *registry* diff --git a/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/goals/build/_jkube-build.adoc b/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/goals/build/_jkube-build.adoc index 2702c48786..a4c59d0418 100644 --- a/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/goals/build/_jkube-build.adoc +++ b/kubernetes-maven-plugin/doc/src/main/asciidoc/inc/goals/build/_jkube-build.adoc @@ -80,7 +80,7 @@ endif::[] The following sections describe the usual configuration, which is similar to the build configuration used in the https://dmp.fabric8.io[docker-maven-plugin]. -In addition a more automatic way for creating predefined build configuration can be performed with so called <>. Generators are very flexible and can be easily created. These are described in an extra <>. +In addition a more automatic way for creating predefined build configuration can be performed with so called <>. Generators are very flexible and can be easily created. These are described in an extra <>. Note that if you're providing your own XML image configuration, it would be given more precedence. Generators won't be used in case you're already using your own custom image configuration. Global configuration parameters specify overall behavior common for all images to build. Some of the configuration options are shared with other goals.