Skip to content

Commit

Permalink
fix (jkube-kit/generator) : Remove addLatestTagIfSnapshot method from…
Browse files Browse the repository at this point in the history
… BaseGenerator

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Jun 20, 2024
1 parent 7073d17 commit 40f7880
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,6 @@ protected boolean shouldAddGeneratedImageConfiguration(List<ImageConfiguration>
return true;
}

protected void addLatestTagIfSnapshot(BuildConfiguration.BuildConfigurationBuilder buildBuilder) {
if (getProject().getVersion().endsWith("-SNAPSHOT") && !getImageName().contains("%t")) {
buildBuilder.tags(Collections.singletonList("latest"));
}
}

protected void addTagsFromConfig(BuildConfiguration.BuildConfigurationBuilder buildConfigurationBuilder) {
String commaSeparatedTags = getConfigWithFallback(Config.TAGS, "jkube.generator.tags", null);
if (StringUtils.isNotBlank(commaSeparatedTags)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.assertj.core.api.AssertionsForClassTypes.entry;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.eclipse.jkube.generator.api.support.BaseGenerator.PROPERTY_JKUBE_GENERATOR_NAME;

class BaseGeneratorTest {

Expand Down Expand Up @@ -355,39 +354,6 @@ void shouldAddGeneratedImageConfiguration_whenAddEnabledViaProperty_shouldReturn
assertThat(result).isTrue();
}

@Test
@DisplayName("add latest tag if project's version is SNAPSHOT")
void addLatestTagIfSnapshot() {
ctx = ctx.toBuilder().project(ctx.getProject().toBuilder().version("1.2-SNAPSHOT").build()).build();
BuildConfiguration.BuildConfigurationBuilder builder = BuildConfiguration.builder();
new TestBaseGenerator(ctx, "test-generator").addLatestTagIfSnapshot(builder);
BuildConfiguration config = builder.build();
List<String> tags = config.getTags();
assertThat(tags)
.singleElement()
.asString()
.endsWith("latest");
}

@Test
@DisplayName("omit latest tag if formatter contains '%t'")
void omitLatestTagIfTimestamped() {
properties.put(PROPERTY_JKUBE_GENERATOR_NAME, "%g/%a:%t");
ctx = ctx.toBuilder().project(
ctx.getProject().toBuilder()
.version("1.2-SNAPSHOT")
.properties(properties)
.build())
.build();
BuildConfiguration.BuildConfigurationBuilder builder = BuildConfiguration.builder();

new TestBaseGenerator(ctx, "test-generator").addLatestTagIfSnapshot(builder);

BuildConfiguration buildConfiguration = builder.build();
List<String> tags = buildConfiguration.getTags();
assertThat(tags).isEmpty();
}

@Test
@DisplayName("add tags from config")
void addTagsFromConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ protected BuildConfiguration.BuildConfigurationBuilder initImageBuildConfigurati
addJolokiaPort(buildBuilder);
addPrometheusPort(buildBuilder);

addLatestTagIfSnapshot(buildBuilder);
addTagsFromConfig(buildBuilder);
buildBuilder.workdir(getBuildWorkdir());
buildBuilder.entryPoint(getBuildEntryPoint());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void customizeWithOverriddenPropertiesShouldAddImageConfiguration() {
.hasFieldOrPropertyWithValue("alias", "java-exec")
.extracting(ImageConfiguration::getBuildConfiguration)
.hasFieldOrPropertyWithValue("from", "custom-image")
.hasFieldOrPropertyWithValue("tags", Collections.singletonList("latest"))
.hasFieldOrPropertyWithValue("tags", Collections.emptyList())
.hasFieldOrPropertyWithValue("env", new HashMap<String, String>(){{
put("JAVA_APP_DIR", "/other-dir");
put("JAVA_MAIN_CLASS", "com.example.Main");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public List<ImageConfiguration> customize(List<ImageConfiguration> configs, bool
if (!prePackagePhase) {
buildBuilder.assembly(createDefaultAssembly());
}
addLatestTagIfSnapshot(buildBuilder);
addTagsFromConfig(buildBuilder);
imageBuilder
.name(getImageName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void customizeWithKarafMavenPluginShouldAddImageConfiguration() {
.hasFieldOrPropertyWithValue("name", "%g/%a:%l")
.hasFieldOrPropertyWithValue("alias", "karaf")
.extracting(ImageConfiguration::getBuildConfiguration)
.hasFieldOrPropertyWithValue("tags", Collections.singletonList("latest"))
.hasFieldOrPropertyWithValue("tags", Collections.emptyList())
.hasFieldOrPropertyWithValue("ports", Arrays.asList("8181", "8778"))
.extracting(BuildConfiguration::getEnv)
.asInstanceOf(InstanceOfAssertFactories.MAP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public List<ImageConfiguration> customize(List<ImageConfiguration> configs, bool
if (!prePackagePhase) {
buildBuilder.assembly(createAssembly(handler));
}
addLatestTagIfSnapshot(buildBuilder);
addTagsFromConfig(buildBuilder);
imageBuilder
.name(getImageName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void withDefaultHandler_shouldAddImageConfiguration() throws IOException {
.hasFieldOrPropertyWithValue("name", "%g/%a:%l")
.hasFieldOrPropertyWithValue("alias", "webapp")
.extracting(ImageConfiguration::getBuildConfiguration)
.hasFieldOrPropertyWithValue("tags", Collections.singletonList("latest"))
.hasFieldOrPropertyWithValue("tags", Collections.emptyList())
.hasFieldOrPropertyWithValue("ports", Collections.singletonList("8080"))
.hasFieldOrPropertyWithValue("env", new HashMap<String, String>() {{
put("DEPLOY_DIR", "/deployments");
Expand Down Expand Up @@ -164,7 +164,7 @@ void withOverriddenProperties_shouldAddImageConfiguration() throws IOException {
.hasFieldOrPropertyWithValue("name", "%a:%l")
.hasFieldOrPropertyWithValue("alias", "webapp")
.extracting(ImageConfiguration::getBuildConfiguration)
.hasFieldOrPropertyWithValue("tags", Collections.singletonList("latest"))
.hasFieldOrPropertyWithValue("tags", Collections.emptyList())
.hasFieldOrPropertyWithValue("ports", Arrays.asList("8082", "80"))
.hasFieldOrPropertyWithValue("env", Collections.singletonMap("DEPLOY_DIR", "/other-dir"))
.hasFieldOrPropertyWithValue("cmd.shell", "sleep 3600")
Expand Down

0 comments on commit 40f7880

Please sign in to comment.