From 9998085cc100f8f712b5dc1bd5e943baa8c94f9c Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Thu, 25 Apr 2024 16:55:39 +0530 Subject: [PATCH] refactor : Move BuildRecreateMode enum to `jkube-kit/common` Signed-off-by: Rohan Kumar --- .../gradle/plugin/task/OpenShiftBuildTask.java | 3 ++- .../jkube/kit/common}/BuildRecreateMode.java | 2 +- .../config/image/build/BuildConfiguration.java | 3 ++- .../service/openshift/OpenshiftBuildService.java | 6 +++--- .../OpenshiftBuildServiceIntegrationTest.java | 3 ++- .../generator/api/DefaultGeneratorManager.java | 2 +- .../jkube/generator/api/GeneratorContext.java | 3 ++- .../api/DefaultGeneratorManagerTest.java | 15 ++++++++------- .../plugin/mojo/build/OpenshiftBuildMojo.java | 3 ++- 9 files changed, 23 insertions(+), 17 deletions(-) rename jkube-kit/{config/resource/src/main/java/org/eclipse/jkube/kit/config/resource => common/src/main/java/org/eclipse/jkube/kit/common}/BuildRecreateMode.java (97%) diff --git a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftBuildTask.java b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftBuildTask.java index 4f6ceb7fc7..f83d0d1baf 100644 --- a/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftBuildTask.java +++ b/gradle-plugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftBuildTask.java @@ -17,6 +17,7 @@ import org.eclipse.jkube.generator.api.GeneratorContext; import org.eclipse.jkube.gradle.plugin.OpenShiftExtension; +import org.eclipse.jkube.kit.common.BuildRecreateMode; import org.eclipse.jkube.kit.config.resource.PlatformMode; import org.eclipse.jkube.kit.config.service.BuildServiceConfig; @@ -48,6 +49,6 @@ protected GeneratorContext.GeneratorContextBuilder initGeneratorContextBuilder() .openshiftPullSecret(getOpenShiftExtension().getOpenshiftPullSecretOrDefault()) .openshiftPushSecret(getOpenShiftExtension().getOpenshiftPushSecretOrDefault()) .openshiftBuildOutputKind(getOpenShiftExtension().getBuildOutputKindOrDefault()) - .openshiftBuildRecreate(getOpenShiftExtension().getBuildRecreateOrDefault()); + .openshiftBuildRecreate(BuildRecreateMode.fromParameter(kubernetesExtension.getBuildRecreateOrDefault())); } } diff --git a/jkube-kit/config/resource/src/main/java/org/eclipse/jkube/kit/config/resource/BuildRecreateMode.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/BuildRecreateMode.java similarity index 97% rename from jkube-kit/config/resource/src/main/java/org/eclipse/jkube/kit/config/resource/BuildRecreateMode.java rename to jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/BuildRecreateMode.java index ea68812a93..c32f662f78 100644 --- a/jkube-kit/config/resource/src/main/java/org/eclipse/jkube/kit/config/resource/BuildRecreateMode.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/BuildRecreateMode.java @@ -11,7 +11,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.jkube.kit.config.resource; +package org.eclipse.jkube.kit.common; import org.apache.commons.lang3.StringUtils; diff --git a/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/BuildConfiguration.java b/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/BuildConfiguration.java index 428b5d18b1..d1d57b220a 100644 --- a/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/BuildConfiguration.java +++ b/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/BuildConfiguration.java @@ -32,6 +32,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; import lombok.Singular; +import org.eclipse.jkube.kit.common.BuildRecreateMode; import org.eclipse.jkube.kit.common.Arguments; import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.common.archive.ArchiveCompression; @@ -398,7 +399,7 @@ public class BuildConfiguration implements Serializable { *

* This field is applicable in case of OpenShift s2i build strategy */ - private String openshiftBuildRecreateMode; + private BuildRecreateMode openshiftBuildRecreateMode; public boolean isDockerFileMode() { return dockerFile != null || contextDir != null; diff --git a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java index ee04dd237c..dcc3282df6 100644 --- a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java +++ b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java @@ -39,7 +39,7 @@ import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.common.JKubeConfiguration; import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy; -import org.eclipse.jkube.kit.config.resource.BuildRecreateMode; +import org.eclipse.jkube.kit.common.BuildRecreateMode; import org.eclipse.jkube.kit.config.resource.RuntimeMode; import org.eclipse.jkube.kit.config.service.AbstractImageBuildService; import org.eclipse.jkube.kit.config.service.BuildServiceConfig; @@ -214,7 +214,7 @@ protected String updateOrCreateBuildConfig(BuildServiceConfig config, OpenShiftC BuildConfigSpec spec = OpenShiftBuildServiceUtils.getBuildConfigSpec(buildConfig); validateSourceType(buildName, spec); - if (BuildRecreateMode.fromParameter(imageConfig.getBuild().getOpenshiftBuildRecreateMode()).isBuildConfig()) { + if (imageConfig.getBuild().getOpenshiftBuildRecreateMode().isBuildConfig()) { // Delete and recreate afresh client.buildConfigs().inNamespace(applicableOpenShiftNamespace).withName(buildName).delete(); return createBuildConfig(builder, buildName, buildStrategyResource, buildOutput); @@ -405,7 +405,7 @@ private boolean updateSecret(OpenShiftClient client, String pullSecretName, Map< private void checkOrCreateImageStream(ImageConfiguration applicableImageConfig, OpenShiftClient client, KubernetesListBuilder builder, String imageStreamName) { boolean hasImageStream = client.imageStreams().inNamespace(applicableOpenShiftNamespace).withName(imageStreamName).get() != null; - if (hasImageStream && BuildRecreateMode.fromParameter(applicableImageConfig.getBuild().getOpenshiftBuildRecreateMode()).isImageStream()) { + if (hasImageStream && applicableImageConfig.getBuild().getOpenshiftBuildRecreateMode().isImageStream()) { client.imageStreams().inNamespace(applicableOpenShiftNamespace).withName(imageStreamName).delete(); hasImageStream = false; } diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildServiceIntegrationTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildServiceIntegrationTest.java index a768981f17..aad97335fa 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildServiceIntegrationTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildServiceIntegrationTest.java @@ -32,6 +32,7 @@ import org.eclipse.jkube.kit.build.service.docker.ArchiveService; import org.eclipse.jkube.kit.common.Assembly; import org.eclipse.jkube.kit.common.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.BuildRecreateMode; import org.eclipse.jkube.kit.common.JKubeConfiguration; import org.eclipse.jkube.kit.common.JavaProject; import org.eclipse.jkube.kit.common.KitLogger; @@ -142,7 +143,7 @@ void init(@TempDir Path temporaryFolder) throws Exception { .build(BuildConfiguration.builder() .from(projectName) .openshiftS2iBuildNameSuffix("-s2i-suffix2") - .openshiftBuildRecreateMode("none") + .openshiftBuildRecreateMode(BuildRecreateMode.none) .build() ).build(); diff --git a/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/DefaultGeneratorManager.java b/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/DefaultGeneratorManager.java index 950294fc10..66b5af8ebc 100644 --- a/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/DefaultGeneratorManager.java +++ b/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/DefaultGeneratorManager.java @@ -157,7 +157,7 @@ private BuildConfiguration mergeGlobalConfigParamsWithSingleImageBuildConfig(Bui if (StringUtils.isBlank(build.getOpenshiftBuildOutputKind()) && StringUtils.isNotBlank(genCtx.getOpenshiftBuildOutputKind())) { buildConfigBuilder.openshiftBuildOutputKind(genCtx.getOpenshiftBuildOutputKind()); } - if (StringUtils.isBlank(build.getOpenshiftBuildRecreateMode()) && StringUtils.isNotBlank(genCtx.getOpenshiftBuildRecreate())) { + if (build.getOpenshiftBuildRecreateMode() == null) { buildConfigBuilder.openshiftBuildRecreateMode(genCtx.getOpenshiftBuildRecreate()); } return buildConfigBuilder.build(); diff --git a/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/GeneratorContext.java b/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/GeneratorContext.java index d94905f6ec..f7890eabd0 100644 --- a/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/GeneratorContext.java +++ b/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/GeneratorContext.java @@ -19,6 +19,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; +import org.eclipse.jkube.kit.common.BuildRecreateMode; import org.eclipse.jkube.kit.common.JavaProject; import org.eclipse.jkube.kit.common.KitLogger; import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy; @@ -56,7 +57,7 @@ public class GeneratorContext { private String openshiftPullSecret; private String openshiftPushSecret; private String openshiftBuildOutputKind; - private String openshiftBuildRecreate; + private BuildRecreateMode openshiftBuildRecreate; public GeneratorMode getGeneratorMode() { diff --git a/jkube-kit/generator/api/src/test/java/org/eclipse/jkube/generator/api/DefaultGeneratorManagerTest.java b/jkube-kit/generator/api/src/test/java/org/eclipse/jkube/generator/api/DefaultGeneratorManagerTest.java index 13ad555ee6..c426840e9d 100644 --- a/jkube-kit/generator/api/src/test/java/org/eclipse/jkube/generator/api/DefaultGeneratorManagerTest.java +++ b/jkube-kit/generator/api/src/test/java/org/eclipse/jkube/generator/api/DefaultGeneratorManagerTest.java @@ -21,6 +21,7 @@ import java.util.stream.Collectors; import org.assertj.core.api.AssertionsForInterfaceTypes; +import org.eclipse.jkube.kit.common.BuildRecreateMode; import org.eclipse.jkube.kit.common.JKubeException; import org.eclipse.jkube.kit.common.JavaProject; import org.eclipse.jkube.kit.common.KitLogger; @@ -206,7 +207,7 @@ void whenProvidedInImageConfiguration_thenDoNotUpdateBuildConfig() { .openshiftPushSecret("push-secret") .openshiftPullSecret("pull-secret") .openshiftBuildOutputKind("ImageStreamTag") - .openshiftBuildRecreateMode("buildConfig") + .openshiftBuildRecreateMode(BuildRecreateMode.buildConfig) .build()) .build(); List images = Collections.singletonList(imageConfig); @@ -224,7 +225,7 @@ void whenProvidedInImageConfiguration_thenDoNotUpdateBuildConfig() { .hasFieldOrPropertyWithValue("openshiftPullSecret", "pull-secret") .hasFieldOrPropertyWithValue("openshiftPushSecret", "push-secret") .hasFieldOrPropertyWithValue("openshiftBuildOutputKind", "ImageStreamTag") - .hasFieldOrPropertyWithValue("openshiftBuildRecreateMode", "buildConfig"); + .hasFieldOrPropertyWithValue("openshiftBuildRecreateMode", BuildRecreateMode.buildConfig); } @Test @@ -238,7 +239,7 @@ void whenProvidedViaPluginConfiguration_thenSetInBuildConfig() { .openshiftPullSecret("pull-secret") .openshiftPushSecret("push-secret") .openshiftBuildOutputKind("ImageStreamTag") - .openshiftBuildRecreate("buildConfig") + .openshiftBuildRecreate(BuildRecreateMode.buildConfig) .build(); List images = Collections.singletonList(imageConfig); @@ -255,7 +256,7 @@ void whenProvidedViaPluginConfiguration_thenSetInBuildConfig() { .hasFieldOrPropertyWithValue("openshiftPullSecret", "pull-secret") .hasFieldOrPropertyWithValue("openshiftPushSecret", "push-secret") .hasFieldOrPropertyWithValue("openshiftBuildOutputKind", "ImageStreamTag") - .hasFieldOrPropertyWithValue("openshiftBuildRecreateMode", "buildConfig"); + .hasFieldOrPropertyWithValue("openshiftBuildRecreateMode", BuildRecreateMode.buildConfig); } @Test @@ -270,7 +271,7 @@ void whenProvidedViaBothPluginAndImageConfiguration_thenDoNotModifyConfiguration .openshiftPushSecret("push-secret-via-image-config") .openshiftPullSecret("pull-secret-via-image-config") .openshiftBuildOutputKind("ImageStreamTag-via-image-config") - .openshiftBuildRecreateMode("buildConfig-via-image-config") + .openshiftBuildRecreateMode(BuildRecreateMode.buildConfig) .build()) .build(); generatorContext = generatorContext.toBuilder() @@ -280,7 +281,7 @@ void whenProvidedViaBothPluginAndImageConfiguration_thenDoNotModifyConfiguration .openshiftPullSecret("pull-secret") .openshiftPushSecret("push-secret") .openshiftBuildOutputKind("ImageStreamTag") - .openshiftBuildRecreate("buildConfig") + .openshiftBuildRecreate(BuildRecreateMode.buildConfig) .build(); List images = Collections.singletonList(imageConfig); @@ -297,7 +298,7 @@ void whenProvidedViaBothPluginAndImageConfiguration_thenDoNotModifyConfiguration .hasFieldOrPropertyWithValue("openshiftPullSecret", "pull-secret-via-image-config") .hasFieldOrPropertyWithValue("openshiftPushSecret", "push-secret-via-image-config") .hasFieldOrPropertyWithValue("openshiftBuildOutputKind", "ImageStreamTag-via-image-config") - .hasFieldOrPropertyWithValue("openshiftBuildRecreateMode", "buildConfig-via-image-config"); + .hasFieldOrPropertyWithValue("openshiftBuildRecreateMode", BuildRecreateMode.buildConfig); } } } diff --git a/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftBuildMojo.java b/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftBuildMojo.java index 6185f48ea9..0eb377bbea 100644 --- a/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftBuildMojo.java +++ b/openshift-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenshiftBuildMojo.java @@ -19,6 +19,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.eclipse.jkube.generator.api.GeneratorContext; +import org.eclipse.jkube.kit.common.BuildRecreateMode; import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy; import org.eclipse.jkube.kit.config.resource.RuntimeMode; import org.eclipse.jkube.maven.plugin.mojo.OpenShift; @@ -97,7 +98,7 @@ protected GeneratorContext.GeneratorContextBuilder generatorContextBuilder() { .openshiftPullSecret(openshiftPullSecret) .openshiftPushSecret(openshiftPushSecret) .openshiftBuildOutputKind(buildOutputKind) - .openshiftBuildRecreate(buildRecreate); + .openshiftBuildRecreate(BuildRecreateMode.fromParameter(buildRecreate)); } @Override