Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm: Fix possible conflicts when using custom templates #1066

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
public abstract class AbstractAddProbeDecorator extends ApplicationContainerDecorator<ContainerFluent<?>>
implements WithConfigReferences {

private static final String JSONPATH_CONTAINERS_EXPRESSION = "*.spec.containers.";
private static final String PATH_ALL_EXPRESSION = "*.spec.containers.";
private static final String PATH_DEPLOYMENT_CONTAINER_EXPRESSION = "(metadata.name == %s).spec.template.spec.containers.(name == %s).";
private static final String PATH_DEPLOYMENT_EXPRESSION = "(metadata.name == %s).spec.template.spec.containers.";
private static final String PATH_CONTAINER_EXPRESSION = "*.spec.containers.(name == %s).";
private static final Object AUTO_DISCOVER = null;

protected final Probe probe;
Expand Down Expand Up @@ -96,14 +99,24 @@ public List<ConfigReference> getConfigReferences() {
} else {
// default to http action
configReferences.add(buildConfigReference("httpGet.path", probe.getHttpActionPath()));
configReferences.add(buildConfigReference("httpGet.port", AUTO_DISCOVER));
configReferences.add(buildConfigReference("httpGet.scheme", AUTO_DISCOVER));
}
return configReferences;
}

private ConfigReference buildConfigReference(String propertyName, Object value) {
String expression = PATH_ALL_EXPRESSION;
if (Strings.isNotNullOrEmpty(getDeploymentName()) && Strings.isNotNullOrEmpty(getContainerName())) {
expression = String.format(PATH_DEPLOYMENT_CONTAINER_EXPRESSION, getDeploymentName(), getContainerName());
} else if (Strings.isNotNullOrEmpty(getDeploymentName())) {
expression = String.format(PATH_DEPLOYMENT_EXPRESSION, getDeploymentName());
} else if (Strings.isNotNullOrEmpty(getContainerName())) {
expression = String.format(PATH_CONTAINER_EXPRESSION, getContainerName());
}
String property = joinProperties(getProbeName(), propertyName);
String jsonPath = JSONPATH_CONTAINERS_EXPRESSION + getProbeName() + "." + propertyName;
return new ConfigReference(property, jsonPath, value);
String yamlPath = expression + getProbeName() + "." + propertyName;
return new ConfigReference(property, yamlPath, value);
}

private boolean isExecOrTcpOrGrpcActionSet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dekorate.helm.dependencies[2].condition=app.database.enabled
dekorate.helm.dependencies[2].tags=web,frontend
# Normal use case
dekorate.helm.values[0].property=name
dekorate.helm.values[0].paths=metadata.name,(kind == Ingress).spec.rules.http.paths.backend.service.name
dekorate.helm.values[0].paths=(kind == Ingress).spec.rules.http.paths.backend.service.name
# When json path is not found
dekorate.helm.values[1].property=not-found
dekorate.helm.values[1].paths=metadata.not-found
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This custom template is used to reproduce https://github.com/dekorateio/dekorate/issues/1065
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
spec:
replicas: 1
selector:
matchLabels:
name: app
template:
metadata:
labels:
name: app
spec:
containers:
- image: app-image
readinessProbe:
httpGet:
path: /health/ready
port: 8080
scheme: HTTP
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public void valuesShouldContainExpectedData() throws IOException {
assertProbe(readinessValues, 10, 30);
Map<String, Object> httpGetValues = (Map<String, Object>) readinessValues.get("httpGet");
assertEquals("/readiness", httpGetValues.get("path"));
assertEquals(8080, httpGetValues.get("port"));
assertEquals("HTTP", httpGetValues.get("scheme"));
// 3. exec action
Map<String, Object> startupValues = (Map<String, Object>) helmExampleValues.get("startupProbe");
assertProbe(startupValues, 12, 32);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
labels:
app.kubernetes.io/name: helm-on-kubernetes-example
app.kubernetes.io/version: {{ .Values.app.ingress.label.value }}
name: {{ .Values.app.name }}
name: helm-on-kubernetes-example
spec:
rules:
- host: {{ .Values.app.host }}
Expand Down