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 24, 2021
1 parent d0fbd9b commit 7e66e2c
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 1 deletion.
18 changes: 18 additions & 0 deletions gradle-plugin/it/src/it/extension-configuration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ 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'
access {
namespace = 'default'
}
Expand All @@ -56,6 +66,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 @@ -31,6 +31,16 @@ skipresource: 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"
access:
namespace: "default"
enricher:
Expand All @@ -42,6 +52,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 @@ -233,6 +235,26 @@ public abstract class KubernetesExtension {

public abstract Property<Boolean> getSkipBuild();

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 WatchMode watchMode;

public JKubeBuildStrategy buildStrategy;

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

public ProcessorConfig generator;

public ProcessorConfig watcher;

public List<ImageConfiguration> images;

public DockerMachineConfiguration machine;
Expand Down Expand Up @@ -295,6 +319,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 @@ -384,6 +412,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 @@ -613,6 +646,42 @@ public boolean getSkipBuildOrDefault() {
return getOrDefaultBoolean("jkube.skip.build", this::getSkipBuild, false);
}

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

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

public String getWatchPostExecOrNull() {
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 getWatchShowLogsOrNull() {
return getOrDefaultString("jkube.watch.showLogs", this::getWatchShowLogs, 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 @@ -125,7 +127,17 @@ 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[] { "getWatchPostExecOrNull", "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[] { "getWatchShowLogsOrNull", "jkube.watch.showLogs", "true", "true", null});
}

@Parameterized.Parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,53 @@ public Property<Boolean> getSkipResource() {
return new DefaultProperty<>(Boolean.class);
}

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

@Override
public Property<Boolean> getSkipBuild() {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,53 @@ public Property<Boolean> getSkipResource() {
return new DefaultProperty<>(Boolean.class);
}

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

@Override
public Property<Boolean> getSkipBuild() {
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);
}
}

0 comments on commit 7e66e2c

Please sign in to comment.