Skip to content

Commit

Permalink
Fix eclipse-jkube#578: NullpointerException in ContainerEnvJavaOption…
Browse files Browse the repository at this point in the history
…sMergeEnricher

+ Fix NullPointerException in ContainerEnvJavaOptionsMergeEnricher
+ Add FAQ for image name configuration in docs
+ Add note in docs for image precedence of XML configuration over
  generators
+ Added sentence in `jkube.generator.name` flag description that it's
  only applicable in scope of generators
  • Loading branch information
rohanKanojia committed Apr 20, 2021
1 parent 3af6339 commit 9d2ae2d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Usage:
* Fix #630: Document usage for `jkube.build.switchToDeployment` flag
* Fix #647: Resource configuration can now add annotations and labels to ServiceAccount
* Fix #632: Add support for Quarkus Fast Jar Packaging
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public ContainerEnvJavaOptionsMergeVisitor(List<ImageConfiguration> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions kubernetes-maven-plugin/doc/src/main/asciidoc/inc/_faq.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<image-name>>). It will depend upon what mode you're using in Eclipse JKube:

- If you're using <<zero-config, zero configuration mode>>, which means you depend on Eclipse JKube <<generators>> to generate an opinionated image, you will be able to do it using `jkube.generator.name` maven property.
- If you're providing <<config-image, XML image configuration>>, image name would be picked from `<name>` tag like in this example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
<image>
<name>myusername/myimagename:latest</name> <!-- Your image name -->
<build>
<from>openjdk:latest</from>
<cmd>java -jar maven/${project.artifactId}-${project.version}.jar</cmd>
</build>
</image>
----
- If you're using <<simple-dockerfile-build, Simple Dockerfile Mode>>, you can configure image name via `jkube.image.name` or `jkube.generator.name` flags
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<image-name-placeholders, Name Placeholders>>. The default is `%g/%a:%l`.
can be a pattern as described in <<image-name-placeholders, Name Placeholders>>. 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*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, Generators>>. Generators are very flexible and can be easily created. These are described in an extra <<generators, section>>.
In addition a more automatic way for creating predefined build configuration can be performed with so called <<generators, Generators>>. Generators are very flexible and can be easily created. These are described in an extra <<generators, section>>. 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.

Expand Down

0 comments on commit 9d2ae2d

Please sign in to comment.