forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Helm supports complex values in
values.yaml
fragments (such as…
… annotations or arrays) Signed-off-by: Marc Nuri <[email protected]>
- Loading branch information
Showing
22 changed files
with
508 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
plugins { | ||
id 'org.eclipse.jkube.kubernetes' version "${jKubeVersion}" | ||
id 'org.eclipse.jkube.openshift' version "${jKubeVersion}" | ||
id 'java' | ||
} | ||
|
||
group = 'org.eclipse.jkube.integration.tests.gradle' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = '11' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
def extensionConfig = { | ||
offline = true | ||
images { | ||
image { | ||
name = 'repository/helm:latest' | ||
build { | ||
from = 'repository/from:latest' | ||
ports = [8080] | ||
} | ||
} | ||
} | ||
helm { | ||
parameters = [ | ||
{ | ||
name = 'deployment.annotations' | ||
value = ''' | ||
{{- toYaml .Values.common.annotations | nindent 4 }} | ||
{{- toYaml .Values.deployment.annotations | nindent 4 }} | ||
''' | ||
}, | ||
{ | ||
name = 'deployment.hostAliases' | ||
value = '{{- toYaml .Values.deployment.hostAliases | nindent 8 }}' | ||
}, | ||
{ | ||
name = 'service.annotations' | ||
value = ''' | ||
{{- toYaml .Values.common.annotations | nindent 4 }} | ||
{{- toYaml .Values.service.annotations | nindent 4 }} | ||
''' | ||
}, { | ||
name = 'replicaCount' | ||
value = 1 | ||
}] | ||
} | ||
} | ||
|
||
kubernetes(extensionConfig) | ||
openshift(extensionConfig) | ||
|
78 changes: 78 additions & 0 deletions
78
gradle-plugin/it/src/it/helm-complex-values/expected/inner-loop.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: List | ||
items: | ||
- apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app: helm-complex-values | ||
provider: jkube | ||
version: "@ignore@" | ||
group: org.eclipse.jkube.integration.tests.gradle | ||
name: helm-complex-values | ||
annotations: | ||
example.org/env: dev | ||
example.org/kind: ServiceDev | ||
spec: | ||
ports: | ||
- name: http | ||
port: 8080 | ||
protocol: TCP | ||
targetPort: 8080 | ||
selector: | ||
app: helm-complex-values | ||
provider: jkube | ||
group: org.eclipse.jkube.integration.tests.gradle | ||
- apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: helm-complex-values | ||
provider: jkube | ||
version: "@ignore@" | ||
group: org.eclipse.jkube.integration.tests.gradle | ||
name: helm-complex-values | ||
annotations: | ||
example.org/env: dev | ||
example.org/kind: DeploymentDev | ||
spec: | ||
replicas: 1 | ||
revisionHistoryLimit: 2 | ||
selector: | ||
matchLabels: | ||
app: helm-complex-values | ||
provider: jkube | ||
group: org.eclipse.jkube.integration.tests.gradle | ||
template: | ||
metadata: | ||
annotations: "@ignore@" | ||
labels: | ||
app: helm-complex-values | ||
provider: jkube | ||
version: "@ignore@" | ||
group: org.eclipse.jkube.integration.tests.gradle | ||
spec: | ||
hostAliases: | ||
- hostnames: | ||
- dev.example.com | ||
ip: 127.0.0.1 | ||
containers: | ||
- env: | ||
- name: KUBERNETES_NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.namespace | ||
- name: HOSTNAME | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.name | ||
image: repository/helm:latest | ||
imagePullPolicy: IfNotPresent | ||
name: repository-helm-complex-values | ||
ports: | ||
- containerPort: 8080 | ||
name: http | ||
protocol: TCP | ||
securityContext: | ||
privileged: false |
20 changes: 20 additions & 0 deletions
20
gradle-plugin/it/src/it/helm-complex-values/expected/values.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
replicaCount: 1 | ||
common: | ||
annotations: | ||
example.org/one: one | ||
example.org/two: two | ||
example.org/env: prod | ||
deployment: | ||
annotations: | ||
example.org/kind: Deployment | ||
hostAliases: | ||
- ip: 1.1.1.1 | ||
hostnames: | ||
- one.example.com | ||
- ip: 1.1.1.2 | ||
hostnames: | ||
- two.example.com | ||
service: | ||
annotations: | ||
example.org/kind: Service |
18 changes: 18 additions & 0 deletions
18
gradle-plugin/it/src/it/helm-complex-values/gradle.dev.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# Copyright (c) 2019 Red Hat, Inc. | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at: | ||
# | ||
# https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Red Hat, Inc. - initial API and implementation | ||
# | ||
|
||
replicaCount = 1 | ||
deployment.annotations = example.org/env: dev\n example.org/kind: DeploymentDev | ||
deployment.hostAliases = - ip: 127.0.0.1\n hostnames: ['dev.example.com'] | ||
service.annotations = example.org/env: dev\n example.org/kind: ServiceDev |
23 changes: 23 additions & 0 deletions
23
gradle-plugin/it/src/it/helm-complex-values/src/main/jkube/deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright (c) 2019 Red Hat, Inc. | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at: | ||
# | ||
# https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Red Hat, Inc. - initial API and implementation | ||
# | ||
|
||
metadata: | ||
annotations: | ||
${deployment.annotations} | ||
spec: | ||
replicas: ${replicaCount} | ||
template: | ||
spec: | ||
hostAliases: | ||
${deployment.hostAliases} |
18 changes: 18 additions & 0 deletions
18
gradle-plugin/it/src/it/helm-complex-values/src/main/jkube/service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# Copyright (c) 2019 Red Hat, Inc. | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at: | ||
# | ||
# https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Red Hat, Inc. - initial API and implementation | ||
# | ||
|
||
metadata: | ||
annotations: | ||
${service.annotations} | ||
|
33 changes: 33 additions & 0 deletions
33
gradle-plugin/it/src/it/helm-complex-values/src/main/jkube/values.helm.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# | ||
# Copyright (c) 2019 Red Hat, Inc. | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at: | ||
# | ||
# https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Red Hat, Inc. - initial API and implementation | ||
# | ||
|
||
common: | ||
annotations: | ||
example.org/one: one | ||
example.org/two: two | ||
example.org/env: prod | ||
|
||
deployment: | ||
annotations: | ||
example.org/kind: Deployment | ||
hostAliases: | ||
- ip: 1.1.1.1 | ||
hostnames: | ||
- one.example.com | ||
- ip: 1.1.1.2 | ||
hostnames: | ||
- two.example.com | ||
service: | ||
annotations: | ||
example.org/kind: Service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...le-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/HelmComplexValuesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.gradle.plugin.tests; | ||
|
||
import org.eclipse.jkube.kit.common.ResourceVerify; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import java.nio.file.Files; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class HelmComplexValuesIT { | ||
|
||
@RegisterExtension | ||
public final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension(); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
gradleRunner.withITProject("helm-complex-values"); | ||
} | ||
@Test | ||
void outerLoop() throws Exception { | ||
// When | ||
gradleRunner.withArguments("clean", "k8sResource", "k8sHelm").build(); | ||
// Then | ||
ResourceVerify.verifyResourceDescriptors( | ||
gradleRunner.resolveFile("build", "jkube", "helm", "helm-complex-values", "kubernetes", "values.yaml"), | ||
gradleRunner.resolveFile("expected", "values.yaml")); | ||
assertThat(ResourceVerify.readFile(gradleRunner.resolveFile( | ||
"build", "jkube", "helm", "helm-complex-values", "kubernetes", "templates", "helm-complex-values-deployment.yaml"))) | ||
.contains("annotations: {{- toYaml .Values.common.annotations | nindent 4 }}\n" + | ||
" {{- toYaml .Values.deployment.annotations | nindent 4 }}") | ||
.contains("hostAliases: {{- toYaml .Values.deployment.hostAliases | nindent 8 }}") | ||
.contains("replicas: {{ .Values.replicaCount }}"); | ||
assertThat(ResourceVerify.readFile(gradleRunner.resolveFile( | ||
"build", "jkube", "helm", "helm-complex-values", "kubernetes", "templates", "helm-complex-values-service.yaml"))) | ||
.contains("annotations: {{- toYaml .Values.common.annotations | nindent 4 }}\n" + | ||
" {{- toYaml .Values.service.annotations | nindent 4 }}"); | ||
} | ||
|
||
@Test | ||
void innerLoop() throws Exception { | ||
try { | ||
// Given | ||
// gradle.properties with properties to resolve placeholders in fragments | ||
Files.copy(gradleRunner.resolveFile("gradle.dev.properties").toPath(), | ||
gradleRunner.resolveFile("gradle.properties").toPath()); | ||
// When | ||
gradleRunner.withArguments("clean", "k8sResource").build(); | ||
// Then | ||
ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultKubernetesResourceFile(), | ||
gradleRunner.resolveFile("expected", "inner-loop.yaml")); | ||
} finally { | ||
Files.deleteIfExists(gradleRunner.resolveFile("gradle.properties").toPath()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.