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 14, 2018
1 parent fe2247f commit e5ec454
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se
* 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 222: The SeviceEnricher could check the Docker image configuration for specific labels
* 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 @@ -154,6 +154,29 @@ public ConfigMap getConfigMap() {
public static class Builder {
private ResourceConfig config = new ResourceConfig();

public Builder() { }

public Builder(ResourceConfig config) {
if(config != null) {
this.config.env = config.getEnv().orElse(null);
this.config.controllerName = config.getControllerName();
this.config.imagePullPolicy = config.getImagePullPolicy();
this.config.replicas = config.getReplicas();
this.config.liveness = config.getLiveness();
this.config.readiness = config.getReadiness();
this.config.annotations = config.getAnnotations();
this.config.serviceAccount = config.getServiceAccount();
this.config.configMap = config.getConfigMap();
this.config.volumes = config.getVolumes();
this.config.labels = config.getLabels();
this.config.annotations = config.getAnnotations();
this.config.secrets = config.getSecrets();
this.config.services = config.getServices();
this.config.metrics = config.getMetrics();
this.config.namespace = config.getNamespace();
}
}

public Builder env(Map<String, String> env) {
config.env = env;
return this;
Expand Down Expand Up @@ -189,6 +212,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 @@ -89,6 +89,7 @@ private List<EnvVar> getEnvVars(ResourceConfig config) {
List<EnvVar> envVars = KubernetesResourceUtil.convertToEnvVarList(config.getEnv().orElse(Collections.emptyMap()));

// TODO: This should go into an extra enricher so that this behaviour can be switched on / off
envVars.removeIf(obj -> obj.getName().equals("KUBERNETES_NAMESPACE"));
envVars.add(0,
new EnvVarBuilder()
.withName("KUBERNETES_NAMESPACE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,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 @@ -272,7 +272,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 @@ -300,4 +300,4 @@ public void getTCPProbeWithInvalidURLTest() {

probe = probeHandler.getProbe(probeConfig);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ 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 config = new ResourceConfig.Builder(getConfiguration().getResource().orElse(null))
.controllerName(name)
.imagePullPolicy(getConfig(Config.pullPolicy))
.withReplicas(Configs.asInt(getConfig(Config.replicaCount)))
.build();

final List<ImageConfiguration> images = getImages().orElse(Collections.emptyList());

Expand Down
4 changes: 2 additions & 2 deletions it/src/it/env-metadata/expected/kubernetes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ items:
spec:
containers:
- env:
- name: MY_ENV_key
value: MY_ENV_value
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_ENV_key
value: MY_ENV_value
image: "@matches('fabric8/fabric8-maven-sample-env-metadata:.*$')@"
imagePullPolicy: IfNotPresent
name: spring-boot
Expand Down
4 changes: 2 additions & 2 deletions it/src/it/env-metadata/expected/openshift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ items:
spec:
containers:
- env:
- name: MY_ENV_key
value: MY_ENV_value
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_ENV_key
value: MY_ENV_value
image: "@matches('fabric8/fabric8-maven-sample-env-metadata:.*$')@"
imagePullPolicy: IfNotPresent
name: spring-boot
Expand Down

0 comments on commit e5ec454

Please sign in to comment.