diff --git a/gradle-plugin/it/src/it/well-known-labels/build.gradle b/gradle-plugin/it/src/it/well-known-labels/build.gradle new file mode 100644 index 0000000000..10ed873d9e --- /dev/null +++ b/gradle-plugin/it/src/it/well-known-labels/build.gradle @@ -0,0 +1,42 @@ +/* + * 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/well-known-labels:latest' + build { + from = 'quay.io/jkube/jkube-java-11' + ports = ['8080'] + } + } + } +} + +kubernetes(extensionConfig) +openshift(extensionConfig) diff --git a/gradle-plugin/it/src/it/well-known-labels/expected/custom/kubernetes.yml b/gradle-plugin/it/src/it/well-known-labels/expected/custom/kubernetes.yml new file mode 100644 index 0000000000..1cf8834bce --- /dev/null +++ b/gradle-plugin/it/src/it/well-known-labels/expected/custom/kubernetes.yml @@ -0,0 +1,102 @@ +--- +apiVersion: v1 +kind: List +items: +- apiVersion: v1 + kind: Service + metadata: + annotations: + jkube.eclipse.org/git-url: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of + app.kubernetes.io/version: "@ignore@" + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of +- apiVersion: apps/v1 + kind: Deployment + metadata: + annotations: + jkube.eclipse.org/git-url: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of + app.kubernetes.io/version: "@ignore@" + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + replicas: 1 + revisionHistoryLimit: 2 + selector: + matchLabels: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of + template: + metadata: + annotations: + jkube.eclipse.org/git-url: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of + app.kubernetes.io/version: "@ignore@" + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + spec: + containers: + - env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: HOSTNAME + valueFrom: + fieldRef: + fieldPath: metadata.name + image: repository/well-known-labels:latest + imagePullPolicy: IfNotPresent + name: repository-well-known-labels + ports: + - containerPort: 8080 + name: http + protocol: TCP + securityContext: + privileged: false diff --git a/gradle-plugin/it/src/it/well-known-labels/expected/custom/openshift.yml b/gradle-plugin/it/src/it/well-known-labels/expected/custom/openshift.yml new file mode 100644 index 0000000000..3599ed853d --- /dev/null +++ b/gradle-plugin/it/src/it/well-known-labels/expected/custom/openshift.yml @@ -0,0 +1,143 @@ +--- +apiVersion: v1 +kind: List +items: +- apiVersion: v1 + kind: Service + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of + app.kubernetes.io/version: "@ignore@" + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of +- apiVersion: apps.openshift.io/v1 + kind: DeploymentConfig + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of + app.kubernetes.io/version: "@ignore@" + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + replicas: 1 + revisionHistoryLimit: 2 + selector: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of + strategy: + rollingParams: + timeoutSeconds: 3600 + type: Rolling + template: + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of + app.kubernetes.io/version: "@ignore@" + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + spec: + containers: + - env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + image: repository/well-known-labels:latest + imagePullPolicy: IfNotPresent + name: repository-well-known-labels + ports: + - containerPort: 8080 + name: http + protocol: TCP + securityContext: + privileged: false + triggers: + - type: ConfigChange + - imageChangeParams: + automatic: true + containerNames: + - repository-well-known-labels + from: + kind: ImageStreamTag + name: well-known-labels:latest + type: ImageChange +- apiVersion: route.openshift.io/v1 + kind: Route + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/component: custom-component + app.kubernetes.io/managed-by: custom-managed-by + app.kubernetes.io/name: custom-app + app.kubernetes.io/part-of: custom-part-of + app.kubernetes.io/version: "@ignore@" + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + port: + targetPort: 8080 + to: + kind: Service + name: well-known-labels diff --git a/gradle-plugin/it/src/it/well-known-labels/expected/default/kubernetes.yml b/gradle-plugin/it/src/it/well-known-labels/expected/default/kubernetes.yml new file mode 100644 index 0000000000..80d8d66c2d --- /dev/null +++ b/gradle-plugin/it/src/it/well-known-labels/expected/default/kubernetes.yml @@ -0,0 +1,97 @@ +--- +apiVersion: v1 +kind: List +items: +- apiVersion: v1 + kind: Service + metadata: + annotations: + jkube.eclipse.org/git-url: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/version: "@ignore@" + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle +- apiVersion: apps/v1 + kind: Deployment + metadata: + annotations: + jkube.eclipse.org/git-url: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/version: "@ignore@" + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + replicas: 1 + revisionHistoryLimit: 2 + selector: + matchLabels: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle + template: + metadata: + annotations: + jkube.eclipse.org/git-url: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/version: "@ignore@" + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle + spec: + containers: + - env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: HOSTNAME + valueFrom: + fieldRef: + fieldPath: metadata.name + image: repository/well-known-labels:latest + imagePullPolicy: IfNotPresent + name: repository-well-known-labels + ports: + - containerPort: 8080 + name: http + protocol: TCP + securityContext: + privileged: false diff --git a/gradle-plugin/it/src/it/well-known-labels/expected/default/openshift.yml b/gradle-plugin/it/src/it/well-known-labels/expected/default/openshift.yml new file mode 100644 index 0000000000..69e4eebf78 --- /dev/null +++ b/gradle-plugin/it/src/it/well-known-labels/expected/default/openshift.yml @@ -0,0 +1,137 @@ +--- +apiVersion: v1 +kind: List +items: +- apiVersion: v1 + kind: Service + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/version: "@ignore@" + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle +- apiVersion: apps.openshift.io/v1 + kind: DeploymentConfig + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/version: "@ignore@" + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + replicas: 1 + revisionHistoryLimit: 2 + selector: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle + strategy: + rollingParams: + timeoutSeconds: 3600 + type: Rolling + template: + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/version: "@ignore@" + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + spec: + containers: + - env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + image: repository/well-known-labels:latest + imagePullPolicy: IfNotPresent + name: repository-well-known-labels + ports: + - containerPort: 8080 + name: http + protocol: TCP + securityContext: + privileged: false + triggers: + - type: ConfigChange + - imageChangeParams: + automatic: true + containerNames: + - repository-well-known-labels + from: + kind: ImageStreamTag + name: well-known-labels:latest + type: ImageChange +- apiVersion: route.openshift.io/v1 + kind: Route + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app.kubernetes.io/managed-by: jkube + app.kubernetes.io/name: well-known-labels + app.kubernetes.io/version: "@ignore@" + app.kubernetes.io/part-of: org.eclipse.jkube.integration.tests.gradle + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + port: + targetPort: 8080 + to: + kind: Service + name: well-known-labels diff --git a/gradle-plugin/it/src/it/well-known-labels/expected/disabled/kubernetes.yml b/gradle-plugin/it/src/it/well-known-labels/expected/disabled/kubernetes.yml new file mode 100644 index 0000000000..7fc1d70842 --- /dev/null +++ b/gradle-plugin/it/src/it/well-known-labels/expected/disabled/kubernetes.yml @@ -0,0 +1,79 @@ +--- +apiVersion: v1 +kind: List +items: +- apiVersion: v1 + kind: Service + metadata: + annotations: + jkube.eclipse.org/git-url: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle +- apiVersion: apps/v1 + kind: Deployment + metadata: + annotations: + jkube.eclipse.org/git-url: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + replicas: 1 + revisionHistoryLimit: 2 + selector: + matchLabels: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle + template: + metadata: + annotations: + jkube.eclipse.org/git-url: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + spec: + containers: + - env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: HOSTNAME + valueFrom: + fieldRef: + fieldPath: metadata.name + image: repository/well-known-labels:latest + imagePullPolicy: IfNotPresent + name: repository-well-known-labels + ports: + - containerPort: 8080 + name: http + protocol: TCP + securityContext: + privileged: false diff --git a/gradle-plugin/it/src/it/well-known-labels/expected/disabled/openshift.yml b/gradle-plugin/it/src/it/well-known-labels/expected/disabled/openshift.yml new file mode 100644 index 0000000000..0665baffcb --- /dev/null +++ b/gradle-plugin/it/src/it/well-known-labels/expected/disabled/openshift.yml @@ -0,0 +1,115 @@ +--- +apiVersion: v1 +kind: List +items: +- apiVersion: v1 + kind: Service + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle +- apiVersion: apps.openshift.io/v1 + kind: DeploymentConfig + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + replicas: 1 + revisionHistoryLimit: 2 + selector: + app: "well-known-labels" + provider: "jkube" + group: org.eclipse.jkube.integration.tests.gradle + strategy: + rollingParams: + timeoutSeconds: 3600 + type: Rolling + template: + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + spec: + containers: + - env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + image: repository/well-known-labels:latest + imagePullPolicy: IfNotPresent + name: repository-well-known-labels + ports: + - containerPort: 8080 + name: http + protocol: TCP + securityContext: + privileged: false + triggers: + - type: ConfigChange + - imageChangeParams: + automatic: true + containerNames: + - repository-well-known-labels + from: + kind: ImageStreamTag + name: well-known-labels:latest + type: ImageChange +- apiVersion: route.openshift.io/v1 + kind: Route + metadata: + annotations: + app.openshift.io/vcs-ref: "@ignore@" + jkube.eclipse.org/git-url: "@ignore@" + app.openshift.io/vcs-uri: "@ignore@" + jkube.eclipse.org/git-commit: "@ignore@" + jkube.eclipse.org/git-branch: "@ignore@" + labels: + app: "well-known-labels" + provider: "jkube" + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: well-known-labels + spec: + port: + targetPort: 8080 + to: + kind: Service + name: well-known-labels diff --git a/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/WellKnownLabelsIT.java b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/WellKnownLabelsIT.java new file mode 100644 index 0000000000..af44d3d3c8 --- /dev/null +++ b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/WellKnownLabelsIT.java @@ -0,0 +1,89 @@ +/* + * 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 net.minidev.json.parser.ParseException; +import org.eclipse.jkube.kit.common.ResourceVerify; +import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +class WellKnownLabelsIT { + @RegisterExtension + final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension(); + + static Stream data() { + return Stream.of( + arguments("disabled", new String[] {"-Pjkube.kubernetes.well-known-labels=false"}), + arguments("default" , new String[] {}), + arguments("custom" , new String[] {"-Pjkube.enricher.jkube-well-known-labels.name=custom-app", + "-Pjkube.enricher.jkube-well-known-labels.version=0.0.1-alpha1", + "-Pjkube.enricher.jkube-well-known-labels.component=custom-component", + "-Pjkube.enricher.jkube-well-known-labels.partOf=custom-part-of", + "-Pjkube.enricher.jkube-well-known-labels.managedBy=custom-managed-by", + }) + ); + } + + @ParameterizedTest(name = "k8sResource {0} configured well-known-labels ") + @MethodSource("data") + void k8sResource_whenRun_generatesK8sManifestsWithWellKnownLabels(String expectedDir, String[] arguments) throws IOException, ParseException { + // When + List gradleArgs = new ArrayList<>(Arrays.asList(arguments)); + gradleArgs.add("k8sResource"); + gradleArgs.add("--stacktrace"); + final BuildResult result = gradleRunner.withITProject("well-known-labels") + .withArguments(gradleArgs.toArray(new String[0])) + .build(); + // Then + ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultKubernetesResourceFile(), + gradleRunner.resolveFile("expected", expectedDir, "kubernetes.yml")); + assertThat(result).extracting(BuildResult::getOutput).asString() + .contains("Using resource templates from") + .contains("Adding a default Deployment") + .contains("Adding revision history limit to 2") + .contains("validating"); + } + + @ParameterizedTest(name = "ocResource {0} configured well-known-labels ") + @MethodSource("data") + void ocResource_whenRun_generatesOpenShiftManifestsWithWellKnownLabels(String expectedDir, String[] arguments) throws IOException, ParseException { + // When + List gradleArgs = new ArrayList<>(Arrays.asList(arguments)); + gradleArgs.add("ocResource"); + gradleArgs.add("--stacktrace"); + final BuildResult result = gradleRunner.withITProject("well-known-labels") + .withArguments(gradleArgs.toArray(new String[0])) + .build(); + // Then + ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultOpenShiftResourceFile(), + gradleRunner.resolveFile("expected", expectedDir, "openshift.yml")); + assertThat(result).extracting(BuildResult::getOutput).asString() + .contains("Using resource templates from") + .contains("Adding a default Deployment") + .contains("Adding revision history limit to 2") + .contains("validating"); + } +}