Skip to content

Commit

Permalink
fix (jkube-kit/generator) : Align BaseGenerator's config options to w…
Browse files Browse the repository at this point in the history
…ork with `jkube.generator.*` properties (#1489)

BaseGenerator `add` and `tags` options also available with
`jkube.generator.add` and `jkube.generator.tags` properties
respectively.

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia authored and manusa committed May 13, 2022
1 parent 312c280 commit 2a372a3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Usage:
* Fix #1324: Support legacy javaee as well as jakartaee projects in the Tomcat webapp generator
* Fix #1482: Quarkus Generator and Enricher should be compatible with the Red Hat build
* Fix #1483: Assembly files with unnormalized paths don't get fileMode changes
* Fix #1489: Align BaseGenerator's `add` and `tags` config options to work with `jkube.generator.*` properties

### 1.7.0 (2022-02-25)
* Fix #1315: Pod Log Service works for Jobs with no selector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected boolean shouldAddGeneratedImageConfiguration(List<ImageConfiguration>
return false;
}
if (containsBuildConfiguration(configs)) {
return Configs.asBoolean(getConfig(Config.ADD));
return Boolean.parseBoolean(getConfigWithFallback(Config.ADD, "jkube.generator.add", "false"));
}
return true;
}
Expand All @@ -233,7 +233,7 @@ protected void addLatestTagIfSnapshot(BuildConfiguration.BuildConfigurationBuild
}

protected void addTagsFromConfig(BuildConfiguration.BuildConfigurationBuilder buildConfigurationBuilder) {
String commaSeparatedTags = getConfig(Config.TAGS);
String commaSeparatedTags = getConfigWithFallback(Config.TAGS, "jkube.generator.tags", null);
if (StringUtils.isNotBlank(commaSeparatedTags)) {
List<String> tags = Arrays.stream(commaSeparatedTags.split(","))
.map(String::trim)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,41 @@ public void shouldNotAddDefaultImageInCaseOfSimpleDockerfile() throws IOExceptio
assertFalse(generator.shouldAddGeneratedImageConfiguration(Collections.emptyList()));
}

@Test
public void shouldAddGeneratedImageConfiguration_whenAddEnabledViaConfig_shouldReturnTrue() {
// Given
new Expectations() {{
ctx.getProject();
result = project;
}};
properties.put("jkube.generator.test-generator.add", "true");
BaseGenerator generator = createGenerator(null);

// When
boolean result = generator.shouldAddGeneratedImageConfiguration(createNewImageConfigurationList());

// Then
assertTrue(result);
}


@Test
public void shouldAddGeneratedImageConfiguration_whenAddEnabledViaProperty_shouldReturnTrue() {
// Given
new Expectations() {{
ctx.getProject();
result = project;
}};
properties.put("jkube.generator.add", "true");
BaseGenerator generator = createGenerator(null);

// When
boolean result = generator.shouldAddGeneratedImageConfiguration(createNewImageConfigurationList());

// Then
assertTrue(result);
}

@Test
public void addLatestTagIfSnapshot() {
new Expectations() {
Expand Down Expand Up @@ -369,6 +404,22 @@ public void addTagsFromConfig() {
.containsExactlyInAnyOrder("tag-1", "tag-2", "other-tag");
}

@Test
public void addTagsFromProperty() {
new Expectations() {{
ctx.getProject();
result = project;
}};
BuildConfiguration.BuildConfigurationBuilder builder = BuildConfiguration.builder();
properties.put("jkube.generator.tags", " tag-1, tag-2 , other-tag");
BaseGenerator generator = createGenerator(null);
generator.addTagsFromConfig(builder);
BuildConfiguration config = builder.build();
assertThat(config.getTags())
.hasSize(3)
.containsExactlyInAnyOrder("tag-1", "tag-2", "other-tag");
}

public void inKubernetes() {
// @formatter:off
new Expectations() {{
Expand Down Expand Up @@ -426,4 +477,11 @@ protected String getIstagFrom() {
return "selectorIstagFromUpstream";
}
}

private List<ImageConfiguration> createNewImageConfigurationList() {
return Collections.singletonList(ImageConfiguration.builder()
.name("test:latest")
.build(BuildConfiguration.builder().from("foo:latest").build())
.build());
}
}

0 comments on commit 2a372a3

Please sign in to comment.