Skip to content

Commit

Permalink
refactor : Move BuildRecreateMode enum to jkube-kit/common
Browse files Browse the repository at this point in the history
Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Apr 25, 2024
1 parent d7c6aec commit 9998085
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -398,7 +399,7 @@ public class BuildConfiguration implements Serializable {
* <p>
* This field is applicable in case of OpenShift <code>s2i</code> build strategy
*/
private String openshiftBuildRecreateMode;
private BuildRecreateMode openshiftBuildRecreateMode;

public boolean isDockerFileMode() {
return dockerFile != null || contextDir != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -206,7 +207,7 @@ void whenProvidedInImageConfiguration_thenDoNotUpdateBuildConfig() {
.openshiftPushSecret("push-secret")
.openshiftPullSecret("pull-secret")
.openshiftBuildOutputKind("ImageStreamTag")
.openshiftBuildRecreateMode("buildConfig")
.openshiftBuildRecreateMode(BuildRecreateMode.buildConfig)
.build())
.build();
List<ImageConfiguration> images = Collections.singletonList(imageConfig);
Expand All @@ -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
Expand All @@ -238,7 +239,7 @@ void whenProvidedViaPluginConfiguration_thenSetInBuildConfig() {
.openshiftPullSecret("pull-secret")
.openshiftPushSecret("push-secret")
.openshiftBuildOutputKind("ImageStreamTag")
.openshiftBuildRecreate("buildConfig")
.openshiftBuildRecreate(BuildRecreateMode.buildConfig)
.build();
List<ImageConfiguration> images = Collections.singletonList(imageConfig);

Expand All @@ -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
Expand All @@ -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()
Expand All @@ -280,7 +281,7 @@ void whenProvidedViaBothPluginAndImageConfiguration_thenDoNotModifyConfiguration
.openshiftPullSecret("pull-secret")
.openshiftPushSecret("push-secret")
.openshiftBuildOutputKind("ImageStreamTag")
.openshiftBuildRecreate("buildConfig")
.openshiftBuildRecreate(BuildRecreateMode.buildConfig)
.build();
List<ImageConfiguration> images = Collections.singletonList(imageConfig);

Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,7 +98,7 @@ protected GeneratorContext.GeneratorContextBuilder generatorContextBuilder() {
.openshiftPullSecret(openshiftPullSecret)
.openshiftPushSecret(openshiftPushSecret)
.openshiftBuildOutputKind(buildOutputKind)
.openshiftBuildRecreate(buildRecreate);
.openshiftBuildRecreate(BuildRecreateMode.fromParameter(buildRecreate));
}

@Override
Expand Down

0 comments on commit 9998085

Please sign in to comment.