Skip to content

Commit

Permalink
Add Configuration options for KubernetesWatchTask to KubernetesExtension
Browse files Browse the repository at this point in the history
Add KubernetesWatchTask related configugration fields in
KubenetesExtension.

Related to eclipse-jkube#1109

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
  • Loading branch information
rohanKanojia committed Nov 19, 2021
1 parent 1e3b4a7 commit f3b8b1d
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 1 deletion.
19 changes: 19 additions & 0 deletions gradle-plugin/it/src/it/extension-configuration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ kubernetes {
pushRegistry = 'quay.io'
pushRetries = 5
kubernetesTemplate = file('build/META-INF/jkube/kubernetes')
watchMode = 'copy'
watchInterval = 1000
watchKeepRunning = true
watchPostExec = 'ls -lt'
watchAutoCreateCustomNetworks = true
watchKeepContainer = true
watchRemoveVolumes = true
watchContainerNamePattern = '%g-%l'
watchFollow = true
watchShowLogs = 'true'
watchPostTask = 'someTask'
access {
namespace = 'default'
}
Expand All @@ -54,6 +65,14 @@ kubernetes {
includes = ['openliberty', 'spring-boot']
excludes = ['webapp']
}
watcher {
includes = ['spring-boot']
config {
'spring-boot' {
serviceUrlWaitTimeSeconds = 10
}
}
}
resources {
controllerName = 'test'
configMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ skiptag: true
pushregistry: quay.io
pushretries: 5
kubernetestemplate: "@endsWith('extension-configuration/build/META-INF/jkube/kubernetes')@"
watchMode: "copy"
watchinterval: 1000
watchkeeprunning: true
watchpostexec: "ls -lt"
watchautocreatecustomnetworks: true
watchkeepcontainer: true
watchremovevolumes: true
watchcontainernamepattern: "%g-%l"
watchfollow: true
watchshowlogs: "true"
watchposttask: "someTask"
access:
namespace: "default"
enricher:
Expand All @@ -40,6 +51,12 @@ generator:
- "spring-boot"
excludes:
- "webapp"
watcher:
includes:
- "spring-boot"
config:
spring-boot:
serviceUrlWaitTimeSeconds: 10
resources:
controllerName: "test"
configMap:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
import java.util.stream.Collectors;

import org.eclipse.jkube.kit.build.service.docker.config.DockerMachineConfiguration;
import org.eclipse.jkube.kit.build.service.docker.helper.ContainerNamingUtil;
import org.eclipse.jkube.kit.common.JavaProject;
import org.eclipse.jkube.kit.common.KitLogger;
import org.eclipse.jkube.kit.common.ResourceFileType;
import org.eclipse.jkube.kit.common.util.OpenshiftHelper;
import org.eclipse.jkube.kit.common.util.ResourceClassifier;
import org.eclipse.jkube.kit.config.access.ClusterConfiguration;
import org.eclipse.jkube.kit.config.image.ImageConfiguration;
import org.eclipse.jkube.kit.config.image.WatchMode;
import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy;
import org.eclipse.jkube.kit.config.image.build.RegistryAuthConfiguration;
import org.eclipse.jkube.kit.config.resource.MappingConfig;
Expand Down Expand Up @@ -229,6 +231,28 @@ public abstract class KubernetesExtension {

public abstract Property<File> getKubernetesTemplate();

public abstract Property<Boolean> getWatchKeepRunning();

public abstract Property<Integer> getWatchInterval();

public abstract Property<String> getWatchPostExec();

public abstract Property<Boolean> getWatchAutoCreateCustomNetworks();

public abstract Property<Boolean> getWatchKeepContainer();

public abstract Property<Boolean> getWatchRemoveVolumes();

public abstract Property<Boolean> getWatchFollow();

public abstract Property<String> getWatchShowLogs();

public abstract Property<String> getWatchContainerNamePattern();

public abstract Property<String> getWatchPostTask();

public WatchMode watchMode;

public JKubeBuildStrategy buildStrategy;

public ClusterConfiguration access;
Expand All @@ -239,6 +263,8 @@ public abstract class KubernetesExtension {

public ProcessorConfig generator;

public ProcessorConfig watcher;

public List<ImageConfiguration> images;

public DockerMachineConfiguration machine;
Expand Down Expand Up @@ -291,6 +317,10 @@ public void generator(Closure<?> closure) {
generator = closureTo(closure, ProcessorConfig.class);
}

public void watcher(Closure<?> closure) {
watcher = closureTo(closure, ProcessorConfig.class);
}

/**
* Provide support for image configurations as:
*
Expand Down Expand Up @@ -380,6 +410,11 @@ public JKubeBuildStrategy getBuildStrategyOrDefault() {
.orElse(buildStrategy != null ? buildStrategy : JKubeBuildStrategy.docker);
}

public WatchMode getWatchModeOrDefault() {
return getProperty("jkube.watch.mode", WatchMode::valueOf)
.orElse(watchMode != null ? watchMode : WatchMode.both);
}

public boolean getOfflineOrDefault() {
return getOrDefaultBoolean("jkube.offline", this::getOffline, DEFAULT_OFFLINE);
}
Expand Down Expand Up @@ -601,6 +636,46 @@ public File getKubernetesTemplateOrDefault() {
return getOrDefaultFile("jkube.kubernetesTemplate", this::getKubernetesTemplate, javaProject.getOutputDirectory().toPath().resolve(DEFAULT_KUBERNETES_TEMPLATE).toFile());
}

public Integer getWatchIntervalOrDefault() {
return getOrDefaultInteger("jkube.watch.interval", this::getWatchInterval, 5000);
}

public boolean getWatchKeepRunningOrDefault() {
return getOrDefaultBoolean("jkube.watch.keepRunning", this::getWatchKeepRunning, false);
}

public String getWatchPostExecOrDefault() {
return getOrDefaultString("jkube.watch.postExec", this::getWatchPostExec, null);
}

public boolean getWatchAutoCreateCustomNetworksOrDefault() {
return getOrDefaultBoolean("jkube.watch.autoCreateCustomNetworks", this::getWatchAutoCreateCustomNetworks, false);
}

public boolean getWatchKeepContainerOrDefault() {
return getOrDefaultBoolean("jkube.watch.keepContainer", this::getWatchKeepContainer, false);
}

public boolean getWatchRemoveVolumesOrDefault() {
return getOrDefaultBoolean("jkube.watch.removeVolumes", this::getWatchRemoveVolumes, false);
}

public String getWatchContainerNamePatternOrDefault() {
return getOrDefaultString("jkube.watch.containerNamePattern", this::getWatchContainerNamePattern, ContainerNamingUtil.DEFAULT_CONTAINER_NAME_PATTERN);
}

public boolean getWatchFollowOrDefault() {
return getOrDefaultBoolean("jkube.watch.follow", this::getWatchFollow, false);
}

public String getWatchShowLogsOrDefault() {
return getOrDefaultString("jkube.watch.showLogs", this::getWatchShowLogs, null);
}

public String getWatchPostTaskOrDefault() {
return getOrDefaultString("jkube.watch.postTask", this::getWatchPostTask, null);
}

protected boolean getOrDefaultBoolean(String property, Supplier<Property<Boolean>> dslGetter, boolean defaultValue) {
return getOrDefault(property, Boolean::parseBoolean, dslGetter, defaultValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import java.util.Arrays;
import java.util.Collection;

import org.eclipse.jkube.kit.build.service.docker.helper.ContainerNamingUtil;
import org.eclipse.jkube.kit.common.JavaProject;

import org.eclipse.jkube.kit.common.ResourceFileType;
import org.eclipse.jkube.kit.config.image.WatchMode;
import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -123,7 +125,18 @@ public static Collection<Object[]> data() {
Paths.get("META-INF", "jkube", "other").toString(),
Paths.get("META-INF", "jkube", "other").toFile(),
new File(BASE, "build").toPath().resolve(Paths.get("META-INF", "jkube", "kubernetes")).toFile()
});
},
new Object[] { "getWatchModeOrDefault", "jkube.watch.mode", "copy", WatchMode.copy, WatchMode.both},
new Object[] { "getWatchIntervalOrDefault", "jkube.watch.interval", "10000", 10000, 5000},
new Object[] { "getWatchKeepRunningOrDefault", "jkube.watch.keepRunning", "true", true, false},
new Object[] { "getWatchPostExecOrDefault", "jkube.watch.postExec", "ls -lt", "ls -lt", null},
new Object[] { "getWatchAutoCreateCustomNetworksOrDefault", "jkube.watch.autoCreateCustomNetworks", "true", true, false},
new Object[] { "getWatchKeepContainerOrDefault", "jkube.watch.keepContainer", "true", true, false},
new Object[] { "getWatchRemoveVolumesOrDefault", "jkube.watch.removeVolumes", "true", true, false},
new Object[] { "getWatchContainerNamePatternOrDefault", "jkube.watch.containerNamePattern", "%n-%g", "%n-%g", ContainerNamingUtil.DEFAULT_CONTAINER_NAME_PATTERN},
new Object[] { "getWatchFollowOrDefault", "jkube.watch.follow", "true", true, false},
new Object[] { "getWatchShowLogsOrDefault", "jkube.watch.showLogs", "true", "true", null},
new Object[] { "getWatchPostTaskOrDefault", "jkube.watch.postTask", "someTask", "someTask", null});
}

@Parameterized.Parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,54 @@ public Property<Boolean> getDebugSuspend() {
public Property<File> getKubernetesTemplate() {
return new DefaultProperty<>(File.class);
}

@Override
public Property<Boolean> getWatchKeepRunning() {
return new DefaultProperty<>(Boolean.class);
}

@Override
public Property<Integer> getWatchInterval() {
return new DefaultProperty<>(Integer.class);
}

@Override
public Property<String> getWatchPostExec() {
return new DefaultProperty<>(String.class);
}

@Override
public Property<Boolean> getWatchAutoCreateCustomNetworks() {
return new DefaultProperty<>(Boolean.class);
}

@Override
public Property<Boolean> getWatchKeepContainer() {
return new DefaultProperty<>(Boolean.class);
}

@Override
public Property<Boolean> getWatchRemoveVolumes() {
return new DefaultProperty<>(Boolean.class);
}

@Override
public Property<Boolean> getWatchFollow() {
return new DefaultProperty<>(Boolean.class);
}

@Override
public Property<String> getWatchShowLogs() {
return new DefaultProperty<>(String.class);
}

@Override
public Property<String> getWatchContainerNamePattern() {
return new DefaultProperty<>(String.class);
}

@Override
public Property<String> getWatchPostTask() {
return new DefaultProperty<>(String.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,54 @@ public Property<File> getImageStreamManifest() {
public Property<File> getKubernetesTemplate() {
return new DefaultProperty<>(File.class);
}

@Override
public Property<Boolean> getWatchKeepRunning() {
return new DefaultProperty<>(Boolean.class);
}

@Override
public Property<Integer> getWatchInterval() {
return new DefaultProperty<>(Integer.class);
}

@Override
public Property<String> getWatchPostExec() {
return new DefaultProperty<>(String.class);
}

@Override
public Property<Boolean> getWatchAutoCreateCustomNetworks() {
return new DefaultProperty<>(Boolean.class);
}

@Override
public Property<Boolean> getWatchKeepContainer() {
return new DefaultProperty<>(Boolean.class);
}

@Override
public Property<Boolean> getWatchRemoveVolumes() {
return new DefaultProperty<>(Boolean.class);
}

@Override
public Property<Boolean> getWatchFollow() {
return new DefaultProperty<>(Boolean.class);
}

@Override
public Property<String> getWatchShowLogs() {
return new DefaultProperty<>(String.class);
}

@Override
public Property<String> getWatchContainerNamePattern() {
return new DefaultProperty<>(String.class);
}

@Override
public Property<String> getWatchPostTask() {
return new DefaultProperty<>(String.class);
}
}

0 comments on commit f3b8b1d

Please sign in to comment.