Skip to content

Commit

Permalink
Fix fabric8io#1019: Custom Liveness/Readiness probes are not being cr…
Browse files Browse the repository at this point in the history
…eated

Added CustomProbeEnricher for adding probes via XML config
  • Loading branch information
rohanKanojia committed Dec 13, 2018
1 parent 0a5d1dc commit 13dacac
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se
* Fix 1425: Added metadata visitors for imagestreams, build and buildconfig.
* Fix 712: Add possibility to configure cluster access fexibly.
* Upgraded Jgit to version 5.2.0.201812061821-r - https://github.com/fabric8io/fabric8-maven-plugin/pull/1452
* Fix 1019: Custom liveness/readiness probes are not being created

### 3.5-SNAPSHOT
* Fix 1021: Avoids empty deployment selector value in generated yaml resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ public Builder withConfigMap(ConfigMap configMap) {
return this;
}

public Builder withLiveness(ProbeConfig liveness) {
config.liveness = liveness;
return this;
}

public Builder withReadiness(ProbeConfig readiness) {
config.readiness = readiness;
return this;
}

public ResourceConfig build() {
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ private HTTPGetAction getHTTPGetAction(String getUrl) {
}
try {
URL url = new URL(getUrl);
return new HTTPGetAction(url.getHost(),
null /* headers */,
url.getPath(),
new IntOrString(url.getPort()),
url.getProtocol());
return new HTTPGetAction(url.getHost(),
null /* headers */,
url.getPath(),
new IntOrString(url.getPort()),
url.getProtocol().toUpperCase());
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid URL " + getUrl + " given for HTTP GET readiness check");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void getHTTPProbeWithHTTPURLTest() {
assertEquals(null,probe.getHttpGet().getHttpHeaders());
assertEquals("/healthz",probe.getHttpGet().getPath());
assertEquals(8080,probe.getHttpGet().getPort().getIntVal().intValue());
assertEquals("http",probe.getHttpGet().getScheme());
assertEquals("HTTP",probe.getHttpGet().getScheme());
assertNull(probe.getExec());
assertNull(probe.getTcpSocket());
}
Expand Down Expand Up @@ -199,7 +199,7 @@ public void getTCPProbeWithHTTPURLAndPortTest() {
assertEquals(null,probe.getHttpGet().getHttpHeaders());
assertEquals("/healthz",probe.getHttpGet().getPath());
assertEquals(8080,probe.getHttpGet().getPort().getIntVal().intValue());
assertEquals("http",probe.getHttpGet().getScheme());
assertEquals("HTTP",probe.getHttpGet().getScheme());
}

@Test
Expand Down Expand Up @@ -265,7 +265,7 @@ public void getTCPWithHTTPURLAndWithoutPort() {
assertEquals(null,probe.getHttpGet().getHttpHeaders());
assertEquals("/healthz",probe.getHttpGet().getPath());
assertEquals(8080,probe.getHttpGet().getPort().getIntVal().intValue());
assertEquals("http",probe.getHttpGet().getScheme());
assertEquals("HTTP",probe.getHttpGet().getScheme());
}

@Test
Expand Down Expand Up @@ -293,4 +293,4 @@ public void getTCPProbeWithInvalidURLTest() {

probe = probeHandler.getProbe(probeConfig);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,20 @@ public DefaultControllerEnricher(MavenEnricherContext buildContext) {
@Override
public void addMissingResources(KubernetesListBuilder builder) {
final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getContext().getGav().getSanitizedArtifactId()));
final ResourceConfig config = new ResourceConfig.Builder()
.controllerName(name)
.imagePullPolicy(getConfig(Config.pullPolicy))
.withReplicas(Configs.asInt(getConfig(Config.replicaCount)))
.build();
ResourceConfig resourceConfig = getConfiguration().getResource().orElse(null);
ResourceConfig.Builder configBuilder = new ResourceConfig.Builder()
.controllerName(name)
.imagePullPolicy(getConfig(Config.pullPolicy))
.withReplicas(Configs.asInt(getConfig(Config.replicaCount)));
if(resourceConfig != null) {
configBuilder.volumes(resourceConfig.getVolumes())
.withLiveness(resourceConfig.getLiveness())
.withReadiness(resourceConfig.getReadiness())
.withConfigMap(resourceConfig.getConfigMap())
.withServiceAccount(resourceConfig.getServiceAccount());
}

final ResourceConfig config = configBuilder.build();
final List<ImageConfiguration> images = getImages().orElse(Collections.emptyList());

// Check if at least a replica set is added. If not add a default one
Expand Down

0 comments on commit 13dacac

Please sign in to comment.