From 032014e7b841bb3346f2a9a097fe9bd5983a30e9 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 4 Dec 2021 07:59:07 -0800 Subject: [PATCH 01/12] test --- delme.sh | 1 + 1 file changed, 1 insertion(+) create mode 100644 delme.sh diff --git a/delme.sh b/delme.sh new file mode 100644 index 0000000000..707d90cb73 --- /dev/null +++ b/delme.sh @@ -0,0 +1 @@ +dadsa \ No newline at end of file From 10889fd1fc9c5ec3a32699d70d4a0e914aae7577 Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 16 Dec 2021 04:15:40 -0800 Subject: [PATCH 02/12] fix @Nested tests not running --- .circleci/config.yml | 2 +- pom.xml | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2f197c14d8..7eed9f3449 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,7 +44,7 @@ jobs: echo $CLASSNAMES TEST_ARG=$(echo $CLASSNAMES | sed 's/ /,/g') echo $TEST_ARG - ./mvnw -s .settings.xml -DfailIfNoTests=false -Dtest=$TEST_ARG -e clean org.jacoco:jacoco-maven-plugin:prepare-agent test -U -P sonar -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + ./mvnw -s .settings.xml -DfailIfNoTests=false -DtestsToRun=$TEST_ARG -e clean org.jacoco:jacoco-maven-plugin:prepare-agent test -U -P sonar -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn mkdir -p $HOME/artifacts/junit/ find . -type f -regex ".*/spring-cloud-*.*/target/*.*" -exec cp {} $HOME/artifacts/ \; find . -type f -regex ".*/target/.*-reports/.*" -exec cp {} $HOME/artifacts/junit/ \; diff --git a/pom.xml b/pom.xml index 191dae7c2d..e25caca33c 100644 --- a/pom.xml +++ b/pom.xml @@ -204,6 +204,11 @@ all false + + + + ${testsToRun} + @@ -356,6 +361,11 @@ all false + + + + ${testsToRun} + ${surefireArgLine} From b041c00ea5cac0bb3e7bd43bc75ee470920cc3fe Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 13 Jan 2022 15:33:08 +0200 Subject: [PATCH 03/12] trigger again From a34ac473971fca316b05a0b886de000f05220b1e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 13 Jul 2022 08:43:39 +0000 Subject: [PATCH 04/12] Add renovate.json --- renovate.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000000..7bd954555f --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ] +} From 618f25aeccb763010ba7777653994148514c8d99 Mon Sep 17 00:00:00 2001 From: erabii Date: Tue, 14 Mar 2023 10:39:50 +0200 Subject: [PATCH 05/12] Delete renovate.json --- renovate.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 renovate.json diff --git a/renovate.json b/renovate.json deleted file mode 100644 index 7bd954555f..0000000000 --- a/renovate.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:base" - ] -} From 100a9cd110d5c5e614573d8c3726b21788c1b550 Mon Sep 17 00:00:00 2001 From: erabii Date: Tue, 14 Mar 2023 10:40:02 +0200 Subject: [PATCH 06/12] Delete delme.sh --- delme.sh | 1 - 1 file changed, 1 deletion(-) delete mode 100644 delme.sh diff --git a/delme.sh b/delme.sh deleted file mode 100644 index 707d90cb73..0000000000 --- a/delme.sh +++ /dev/null @@ -1 +0,0 @@ -dadsa \ No newline at end of file From 4e89d23493fb7d9a0eb11308d4ed815e7fdf665e Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 21 Sep 2024 10:54:56 +0300 Subject: [PATCH 07/12] fix --- .../config/KubernetesClientConfigUtils.java | 20 ++-- ...dConfigMapContextToSourceDataProvider.java | 8 +- ...eledSecretContextToSourceDataProvider.java | 8 +- ...netesClientSecretsPropertySourceTests.java | 2 +- ...igMapContextToSourceDataProviderTests.java | 13 +-- ...ecretContextToSourceDataProviderTests.java | 40 ++++---- .../LabeledConfigMapWithProfileTests.java | 6 +- .../LabeledSecretWithProfileTests.java | 7 +- ...ConfigMapWithProfileConfigurationStub.java | 9 +- ...ledSecretWithProfileConfigurationStub.java | 9 +- .../commons/config/ConfigUtils.java | 33 +------ .../config/LabeledSecretNormalizedSource.java | 13 +-- .../commons/config/LabeledSourceData.java | 12 +-- .../config/SecretsConfigProperties.java | 4 +- .../LabeledSecretNormalizedSourceTests.java | 23 ++--- .../config/SecretsConfigPropertiesTests.java | 5 - .../fabric8/config/Fabric8ConfigUtils.java | 20 ++-- ...dConfigMapContextToSourceDataProvider.java | 8 +- ...eledSecretContextToSourceDataProvider.java | 8 +- .../config/Fabric8ConfigUtilsTests.java | 18 ++-- ...Fabric8SecretsPropertySourceMockTests.java | 4 +- ...igMapContextToSourceDataProviderTests.java | 68 ++----------- ...ecretContextToSourceDataProviderTests.java | 96 +++++-------------- .../LabeledConfigMapWithProfile.java | 22 ++--- .../LabeledSecretWithProfile.java | 22 ++--- .../labeled-configmap-with-profile.yaml | 2 - .../labeled-secret-with-profile.yaml | 2 - 27 files changed, 138 insertions(+), 344 deletions(-) diff --git a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigUtils.java b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigUtils.java index 21bc92b9ee..0dc869b322 100644 --- a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigUtils.java +++ b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigUtils.java @@ -65,38 +65,34 @@ public static Set namespaces(KubernetesNamespaceProvider provider, Confi *
 	 *     1. read all secrets in the provided namespace
 	 *     2. from the above, filter the ones that we care about (filter by labels)
-	 *     3. with secret names from (2), find out if there are any profile based secrets (if profiles is not empty)
-	 *     4. concat (2) and (3) and these are the secrets we are interested in
-	 *     5. see if any of the secrets from (4) has a single yaml/properties file
-	 *     6. gather all the names of the secrets (from 4) + data they hold
+	 *     3. see if any of the secrets from (2) has a single yaml/properties file
+	 *     4. gather all the names of the secrets + data they hold
 	 * 
*/ static MultipleSourcesContainer secretsDataByLabels(CoreV1Api coreV1Api, String namespace, - Map labels, Environment environment, Set profiles) { + Map labels, Environment environment) { List strippedSecrets = strippedSecrets(coreV1Api, namespace); if (strippedSecrets.isEmpty()) { return MultipleSourcesContainer.empty(); } - return ConfigUtils.processLabeledData(strippedSecrets, environment, labels, namespace, profiles, DECODE); + return ConfigUtils.processLabeledData(strippedSecrets, environment, labels, namespace, DECODE); } /** *
 	 *     1. read all config maps in the provided namespace
 	 *     2. from the above, filter the ones that we care about (filter by labels)
-	 *     3. with config maps names from (2), find out if there are any profile based ones (if profiles is not empty)
-	 *     4. concat (2) and (3) and these are the config maps we are interested in
-	 *     5. see if any from (4) has a single yaml/properties file
-	 *     6. gather all the names of the config maps (from 4) + data they hold
+	 *     3. see if any from (2) has a single yaml/properties file
+	 *     4. gather all the names of the config maps + data they hold
 	 * 
*/ static MultipleSourcesContainer configMapsDataByLabels(CoreV1Api coreV1Api, String namespace, - Map labels, Environment environment, Set profiles) { + Map labels, Environment environment) { List strippedConfigMaps = strippedConfigMaps(coreV1Api, namespace); if (strippedConfigMaps.isEmpty()) { return MultipleSourcesContainer.empty(); } - return ConfigUtils.processLabeledData(strippedConfigMaps, environment, labels, namespace, profiles, DECODE); + return ConfigUtils.processLabeledData(strippedConfigMaps, environment, labels, namespace, DECODE); } /** diff --git a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProvider.java b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProvider.java index 6d4381ffd2..ee135b3835 100644 --- a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProvider.java +++ b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProvider.java @@ -17,7 +17,6 @@ package org.springframework.cloud.kubernetes.client.config; import java.util.Map; -import java.util.Set; import java.util.function.Supplier; import org.springframework.cloud.kubernetes.commons.config.LabeledConfigMapNormalizedSource; @@ -49,13 +48,12 @@ public KubernetesClientContextToSourceData get() { return new LabeledSourceData() { @Override - public MultipleSourcesContainer dataSupplier(Map labels, Set profiles) { + public MultipleSourcesContainer dataSupplier(Map labels) { return KubernetesClientConfigUtils.configMapsDataByLabels(context.client(), context.namespace(), - labels, context.environment(), profiles); + labels, context.environment()); } - }.compute(source.labels(), source.prefix(), source.target(), source.profileSpecificSources(), - source.failFast(), context.namespace(), context.environment().getActiveProfiles()); + }.compute(source.labels(), source.prefix(), source.target(), source.failFast(), context.namespace()); }; } diff --git a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProvider.java b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProvider.java index 9cf72cbc0b..723e680ebd 100644 --- a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProvider.java +++ b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProvider.java @@ -17,7 +17,6 @@ package org.springframework.cloud.kubernetes.client.config; import java.util.Map; -import java.util.Set; import java.util.function.Supplier; import org.springframework.cloud.kubernetes.commons.config.LabeledSecretNormalizedSource; @@ -55,13 +54,12 @@ public KubernetesClientContextToSourceData get() { return new LabeledSourceData() { @Override - public MultipleSourcesContainer dataSupplier(Map labels, Set profiles) { + public MultipleSourcesContainer dataSupplier(Map labels) { return KubernetesClientConfigUtils.secretsDataByLabels(context.client(), context.namespace(), - labels, context.environment(), profiles); + labels, context.environment()); } - }.compute(source.labels(), source.prefix(), source.target(), source.profileSpecificSources(), - source.failFast(), context.namespace(), context.environment().getActiveProfiles()); + }.compute(source.labels(), source.prefix(), source.target(), source.failFast(), context.namespace()); }; } diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsPropertySourceTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsPropertySourceTests.java index 4cc2b8d231..90b792337c 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsPropertySourceTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsPropertySourceTests.java @@ -167,7 +167,7 @@ void secretLabelsTest() { Map labels = new HashMap<>(); labels.put("spring.cloud.kubernetes.secret", "true"); - NormalizedSource source = new LabeledSecretNormalizedSource("default", labels, false, false); + NormalizedSource source = new LabeledSecretNormalizedSource("default", labels, false); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, "default", new MockEnvironment()); diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProviderTests.java index 44840858e0..d84280bb0e 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProviderTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProviderTests.java @@ -408,9 +408,8 @@ void searchWithLabelsOneConfigMapFound() { /** * two configmaps are deployed: "color-configmap" with label: "{color:blue}" and - * "color-configmap-k8s" with label: "{color:red}". We search by "{color:blue}" and - * find one configmap. Since profiles are enabled, we will also be reading - * "color-configmap-k8s", even if its labels do not match provided ones. + * "color-configmap-k8s" with label: "{color:blue}". We search by "{color:blue}" and + * find them both. */ @Test void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() { @@ -425,7 +424,7 @@ void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() { V1ConfigMap two = new V1ConfigMapBuilder() .withMetadata(new V1ObjectMetaBuilder().withName("color-configmap-k8s") - .withLabels(RED_LABEL) + .withLabels(BLUE_LABEL) .withNamespace(NAMESPACE) .build()) .addToData("two", "2") @@ -436,7 +435,6 @@ void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() { stubCall(configMapList); CoreV1Api api = new CoreV1Api(); MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); NormalizedSource source = new LabeledConfigMapNormalizedSource(NAMESPACE, BLUE_LABEL, true, ConfigUtils.Prefix.DELAYED, true); @@ -490,7 +488,7 @@ void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() { V1ConfigMap colorConfigmapK8s = new V1ConfigMapBuilder() .withMetadata(new V1ObjectMetaBuilder().withName("color-configmap-k8s") - .withLabels(RED_LABEL) + .withLabels(BLUE_LABEL) .withNamespace(NAMESPACE) .build()) .addToData("four", "4") @@ -498,7 +496,7 @@ void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() { V1ConfigMap shapeConfigmapK8s = new V1ConfigMapBuilder() .withMetadata(new V1ObjectMetaBuilder().withName("shape-configmap-k8s") - .withLabels(Map.of("shape", "triangle")) + .withLabels(BLUE_LABEL) .withNamespace(NAMESPACE) .build()) .addToData("five", "5") @@ -513,7 +511,6 @@ void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() { stubCall(configMapList); CoreV1Api api = new CoreV1Api(); MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); NormalizedSource source = new LabeledConfigMapNormalizedSource(NAMESPACE, BLUE_LABEL, true, ConfigUtils.Prefix.DELAYED, true); diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProviderTests.java index 9a666509ce..34a743e828 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProviderTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProviderTests.java @@ -107,7 +107,7 @@ void noMatch() { // blue does not match red NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "blue"), false, false); + Collections.singletonMap("color", "blue"), false); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, new MockEnvironment()); @@ -135,7 +135,7 @@ void singleSecretMatchAgainstLabels() { stubCall(secretList); CoreV1Api api = new CoreV1Api(); - NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, LABELS, false, false); + NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, LABELS, false); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, new MockEnvironment()); @@ -167,7 +167,7 @@ void twoSecretsMatchAgainstLabels() { stubCall(secretList); CoreV1Api api = new CoreV1Api(); - NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, RED_LABEL, false, false); + NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, RED_LABEL, false); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, new MockEnvironment()); @@ -192,7 +192,7 @@ void namespaceMatch() { stubCall(secretList); CoreV1Api api = new CoreV1Api(); - NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE + "nope", LABELS, false, false); + NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE + "nope", LABELS, false); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, new MockEnvironment()); @@ -225,8 +225,7 @@ void testWithPrefix() { CoreV1Api api = new CoreV1Api(); ConfigUtils.Prefix prefix = ConfigUtils.findPrefix("me", false, false, null); - NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false, prefix, - false); + NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false, prefix); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, new MockEnvironment()); @@ -271,7 +270,7 @@ void testTwoSecretsWithPrefix() { CoreV1Api api = new CoreV1Api(); NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false, - ConfigUtils.Prefix.DELAYED, false); + ConfigUtils.Prefix.DELAYED); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, new MockEnvironment()); @@ -303,7 +302,7 @@ void testTwoSecretsWithPrefix() { /** * two secrets are deployed: secret "color-secret" with label: "{color:blue}" and * "shape-secret" with label: "{shape:round}". We search by "{color:blue}" and find - * one secret. profile based sources are enabled, but it has no effect. + * one secret. */ @Test void searchWithLabelsOneSecretFound() { @@ -330,7 +329,7 @@ void searchWithLabelsOneSecretFound() { CoreV1Api api = new CoreV1Api(); NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false, - ConfigUtils.Prefix.DEFAULT, true); + ConfigUtils.Prefix.DEFAULT); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, new MockEnvironment()); @@ -345,9 +344,8 @@ void searchWithLabelsOneSecretFound() { /** * two secrets are deployed: secret "color-secret" with label: "{color:blue}" and - * "color-secret-k8s" with label: "{color:red}". We search by "{color:blue}" and find - * one secret. Since profiles are enabled, we will also be reading "color-secret-k8s", - * even if its labels do not match provided ones. + * "color-secret-k8s" with label: "{color:blue}". We search by "{color:blue}" and find + * both. */ @Test void searchWithLabelsOneSecretFoundAndOneFromProfileFound() { @@ -361,7 +359,7 @@ void searchWithLabelsOneSecretFoundAndOneFromProfileFound() { .build(); V1Secret shapeSecret = new V1SecretBuilder() - .withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "red")) + .withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue")) .withNamespace(NAMESPACE) .withName("color-secret-k8s") .build()) @@ -373,10 +371,9 @@ void searchWithLabelsOneSecretFoundAndOneFromProfileFound() { stubCall(secretList); CoreV1Api api = new CoreV1Api(); MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false, - ConfigUtils.Prefix.DELAYED, true); + ConfigUtils.Prefix.DELAYED); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, environment); KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); @@ -426,7 +423,7 @@ void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() { .build(); V1Secret colorSecretK8s = new V1SecretBuilder() - .withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "red")) + .withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue")) .withNamespace(NAMESPACE) .withName("color-secret-k8s") .build()) @@ -434,7 +431,7 @@ void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() { .build(); V1Secret shapeSecretK8s = new V1SecretBuilder() - .withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("shape", "triangle")) + .withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue")) .withNamespace(NAMESPACE) .withName("shape-secret-k8s") .build()) @@ -450,10 +447,9 @@ void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() { stubCall(secretList); CoreV1Api api = new CoreV1Api(); MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false, - ConfigUtils.Prefix.DELAYED, true); + ConfigUtils.Prefix.DELAYED); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, environment); KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); @@ -493,7 +489,7 @@ void testYaml() { CoreV1Api api = new CoreV1Api(); NormalizedSource source = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "blue"), false, - ConfigUtils.Prefix.DEFAULT, true); + ConfigUtils.Prefix.DEFAULT); KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, NAMESPACE, new MockEnvironment()); @@ -538,7 +534,7 @@ void cache(CapturedOutput output) { CoreV1Api api = new CoreV1Api(); NormalizedSource redSource = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "red"), false, - ConfigUtils.Prefix.DEFAULT, false); + ConfigUtils.Prefix.DEFAULT); KubernetesClientConfigContext redContext = new KubernetesClientConfigContext(api, redSource, NAMESPACE, new MockEnvironment()); KubernetesClientContextToSourceData redData = new LabeledSecretContextToSourceDataProvider().get(); @@ -550,7 +546,7 @@ void cache(CapturedOutput output) { Assertions.assertTrue(output.getAll().contains("Loaded all secrets in namespace '" + NAMESPACE + "'")); NormalizedSource greenSource = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "green"), false, - ConfigUtils.Prefix.DEFAULT, false); + ConfigUtils.Prefix.DEFAULT); KubernetesClientConfigContext greenContext = new KubernetesClientConfigContext(api, greenSource, NAMESPACE, new MockEnvironment()); KubernetesClientContextToSourceData greenData = new LabeledSecretContextToSourceDataProvider().get(); diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_config_map_with_profile/LabeledConfigMapWithProfileTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_config_map_with_profile/LabeledConfigMapWithProfileTests.java index cc4b6798b2..b5d4422a19 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_config_map_with_profile/LabeledConfigMapWithProfileTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_config_map_with_profile/LabeledConfigMapWithProfileTests.java @@ -66,10 +66,8 @@ void testBlue() { /** *
-	 *   this one is taken from : ""green-configmap.green-configmap-k8s.green-configmap-prod.green-purple-configmap.green-purple-configmap-k8s"".
-	 *   We find "green-configmap" by labels, also "green-configmap-k8s", "green-configmap-prod" exists,
-	 *   because "includeProfileSpecificSources=true" is set. Also "green-purple-configmap" and "green-purple-configmap-k8s"
-	 *   are found.
+	 *   this one is taken from : "green-configmap.green-configmap-k8s.green-configmap-prod.green-purple-configmap.green-purple-configmap-k8s".
+	 *   We find "green-configmap", "green-configmap-k8s", "green-configmap-prod" by labels.
 	 * 
*/ @Test diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_secret_with_profile/LabeledSecretWithProfileTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_secret_with_profile/LabeledSecretWithProfileTests.java index b66dab4a1c..fc409b2ce6 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_secret_with_profile/LabeledSecretWithProfileTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/labeled_secret_with_profile/LabeledSecretWithProfileTests.java @@ -60,8 +60,7 @@ static void afterAll() { /** *
-	 *     this one is taken from : "blue.one". We find "color-secret" by labels, and
-	 *     "color-secrets-k8s" exists, but "includeProfileSpecificSources=false", thus not taken.
+	 *     this one is taken from : "blue.one". We find "color-secret" by labels.
 	 *     Since "explicitPrefix=blue", we take "blue.one"
 	 * 
*/ @@ -79,9 +78,7 @@ void testBlue() { /** *
 	 *   this one is taken from : "green-purple-secret.green-purple-secret-k8s.green-secret.green-secret-k8s.green-secret-prod".
-	 *   We find "green-secret" by labels, also "green-secrets-k8s" and "green-secrets-prod" exists,
-	 *   because "includeProfileSpecificSources=true" is set. Also "green-purple-secret" and "green-purple-secret-k8s"
-	 * 	 are found.
+	 *   We find "green-secret", "green-secrets-k8s" and "green-secrets-prod" by labels.
 	 * 
*/ @Test diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/bootstrap/stubs/LabeledConfigMapWithProfileConfigurationStub.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/bootstrap/stubs/LabeledConfigMapWithProfileConfigurationStub.java index 8e1ed61203..3133bd27e5 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/bootstrap/stubs/LabeledConfigMapWithProfileConfigurationStub.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/bootstrap/stubs/LabeledConfigMapWithProfileConfigurationStub.java @@ -73,9 +73,6 @@ public ApiClient apiClient(WireMockServer wireMockServer) { * - configmap with name "color-configmap-k8s", with labels : "{color: not-blue}" * - configmap with name "green-configmap-k8s", with labels : "{color: green-k8s}" * - configmap with name "green-configmap-prod", with labels : "{color: green-prod}" - * - * # a test that proves order: first read non-profile based configmaps, thus profile based - * # configmaps override non-profile ones. * - configmap with name "green-purple-configmap", labels "{color: green, shape: round}", data: "{eight: 8}" * - configmap with name "green-purple-configmap-k8s", labels "{color: black}", data: "{eight: eight-ish}" * @@ -112,7 +109,7 @@ public static void stubData() { V1ConfigMap greenConfigMapK8s = new V1ConfigMapBuilder() .withMetadata(new V1ObjectMetaBuilder().withName("green-configmap-k8s") .withNamespace("spring-k8s") - .withLabels(Map.of("color", "green-k8s")) + .withLabels(Map.of("color", "green")) .build()) .addToData(Collections.singletonMap("six", "6")) .build(); @@ -121,7 +118,7 @@ public static void stubData() { V1ConfigMap greenConfigMapProd = new V1ConfigMapBuilder() .withMetadata(new V1ObjectMetaBuilder().withName("green-configmap-prod") .withNamespace("spring-k8s") - .withLabels(Map.of("color", "green-prod")) + .withLabels(Map.of("color", "green")) .build()) .addToData(Collections.singletonMap("seven", "7")) .build(); @@ -157,7 +154,7 @@ public static void stubData() { V1ConfigMap greenPurpleConfigMapK8s = new V1ConfigMapBuilder() .withMetadata(new V1ObjectMetaBuilder().withName("green-purple-configmap-k8s") .withNamespace("spring-k8s") - .withLabels(Map.of("color", "black")) + .withLabels(Map.of("color", "green")) .build()) .addToData(Collections.singletonMap("eight", "eight-ish")) .build(); diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/bootstrap/stubs/LabeledSecretWithProfileConfigurationStub.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/bootstrap/stubs/LabeledSecretWithProfileConfigurationStub.java index c59ca39f1c..072bc291f8 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/bootstrap/stubs/LabeledSecretWithProfileConfigurationStub.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/bootstrap/stubs/LabeledSecretWithProfileConfigurationStub.java @@ -74,9 +74,6 @@ public ApiClient apiClient(WireMockServer wireMockServer) { * - secret with name "color-secret-k8s", with labels : "{color: not-blue}" * - secret with name "green-secret-k8s", with labels : "{color: green-k8s}" * - secret with name "green-secret-prod", with labels : "{color: green-prod}" - * - * # a test that proves order: first read non-profile based secrets, thus profile based - * # secrets override non-profile ones. * - secret with name "green-purple-secret", labels "{color: green, shape: round}", data: "{eight: 8}" * - secret with name "green-purple-secret-k8s", labels "{color: black}", data: "{eight: eight-ish}" * @@ -113,7 +110,7 @@ public static void stubData() { V1Secret greenSecretK8s = new V1SecretBuilder() .withMetadata(new V1ObjectMetaBuilder().withName("green-secret-k8s") .withNamespace("spring-k8s") - .withLabels(Map.of("color", "green-k8s")) + .withLabels(Map.of("color", "green")) .build()) .addToData(Collections.singletonMap("six", "6".getBytes(StandardCharsets.UTF_8))) .build(); @@ -122,7 +119,7 @@ public static void stubData() { V1Secret shapeSecretProd = new V1SecretBuilder() .withMetadata(new V1ObjectMetaBuilder().withName("green-secret-prod") .withNamespace("spring-k8s") - .withLabels(Map.of("color", "green-prod")) + .withLabels(Map.of("color", "green")) .build()) .addToData(Collections.singletonMap("seven", "7".getBytes(StandardCharsets.UTF_8))) .build(); @@ -158,7 +155,7 @@ public static void stubData() { V1Secret greenPurpleSecretK8s = new V1SecretBuilder() .withMetadata(new V1ObjectMetaBuilder().withName("green-purple-secret-k8s") .withNamespace("spring-k8s") - .withLabels(Map.of("color", "black")) + .withLabels(Map.of("color", "green")) .build()) .addToData(Collections.singletonMap("eight", "eight-ish".getBytes(StandardCharsets.UTF_8))) .build(); diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtils.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtils.java index 5f40858eab..d1c9c00d75 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtils.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtils.java @@ -16,7 +16,6 @@ package org.springframework.cloud.kubernetes.commons.config; -import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; import java.util.HashMap; @@ -24,7 +23,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.function.BiPredicate; import java.util.function.BooleanSupplier; import java.util.function.Function; @@ -266,13 +264,11 @@ static BooleanSupplier rawDataContainsProfileBasedSource(List activeProf /** * transforms raw data from one or multiple sources into an entry of source names and * flattened data that they all hold (potentially overriding entries without any - * defined order). This method first searches by labels, find the sources, then uses - * these names to find any profile based sources. + * defined order). */ public static MultipleSourcesContainer processLabeledData(List containers, - Environment environment, Map labels, String namespace, Set profiles, - boolean decode) { + Environment environment, Map labels, String namespace, boolean decode) { // find sources by provided labels List byLabels = containers.stream().filter(one -> { @@ -281,33 +277,10 @@ public static MultipleSourcesContainer processLabeledData(List sourceNamesByLabelsWithProfile = new ArrayList<>(); - if (profiles != null && !profiles.isEmpty()) { - for (StrippedSourceContainer one : byLabels) { - for (String profile : profiles) { - String name = one.name() + "-" + profile; - sourceNamesByLabelsWithProfile.add(name); - } - } - } - - // once we know sources by labels (and thus their names), we can find out - // profiles based sources from the above. This would get all sources - // we are interested in. - List byProfile = containers.stream() - .filter(one -> sourceNamesByLabelsWithProfile.contains(one.name())) - .toList(); - - // this makes sure that we first have "app" and then "app-dev" in the list - List all = new ArrayList<>(byLabels.size() + byProfile.size()); - all.addAll(byLabels); - all.addAll(byProfile); - LinkedHashSet sourceNames = new LinkedHashSet<>(); Map result = new HashMap<>(); - all.forEach(source -> { + byLabels.forEach(source -> { String foundSourceName = source.name(); LOG.debug("Loaded source with name : '" + foundSourceName + " in namespace: '" + namespace + "'"); sourceNames.add(foundSourceName); diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/LabeledSecretNormalizedSource.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/LabeledSecretNormalizedSource.java index aecd0f35fe..4f32097c0e 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/LabeledSecretNormalizedSource.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/LabeledSecretNormalizedSource.java @@ -31,22 +31,17 @@ public final class LabeledSecretNormalizedSource extends NormalizedSource { private final ConfigUtils.Prefix prefix; - private final boolean includeProfileSpecificSources; - public LabeledSecretNormalizedSource(String namespace, Map labels, boolean failFast, - ConfigUtils.Prefix prefix, boolean includeProfileSpecificSources) { + ConfigUtils.Prefix prefix) { super(null, namespace, failFast); this.labels = Collections.unmodifiableMap(Objects.requireNonNull(labels)); this.prefix = Objects.requireNonNull(prefix); - this.includeProfileSpecificSources = includeProfileSpecificSources; } - public LabeledSecretNormalizedSource(String namespace, Map labels, boolean failFast, - boolean includeProfileSpecificSources) { + public LabeledSecretNormalizedSource(String namespace, Map labels, boolean failFast) { super(null, namespace, failFast); this.labels = Collections.unmodifiableMap(Objects.requireNonNull(labels)); this.prefix = ConfigUtils.Prefix.DEFAULT; - this.includeProfileSpecificSources = includeProfileSpecificSources; } /** @@ -60,10 +55,6 @@ public ConfigUtils.Prefix prefix() { return prefix; } - public boolean profileSpecificSources() { - return this.includeProfileSpecificSources; - } - @Override public NormalizedSourceType type() { return NormalizedSourceType.LABELED_SECRET; diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/LabeledSourceData.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/LabeledSourceData.java index df4e6aab1f..40a6005ea0 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/LabeledSourceData.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/LabeledSourceData.java @@ -16,9 +16,7 @@ package org.springframework.cloud.kubernetes.commons.config; -import java.util.Arrays; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.onException; @@ -33,16 +31,12 @@ public abstract class LabeledSourceData { public final SourceData compute(Map labels, ConfigUtils.Prefix prefix, String target, - boolean profileSources, boolean failFast, String namespace, String[] activeProfiles) { + boolean failFast, String namespace) { MultipleSourcesContainer data = MultipleSourcesContainer.empty(); try { - Set profiles = Set.of(); - if (profileSources) { - profiles = Arrays.stream(activeProfiles).collect(Collectors.toSet()); - } - data = dataSupplier(labels, profiles); + data = dataSupplier(labels); // need this check because when there is no data, the name of the property // source @@ -91,6 +85,6 @@ public final SourceData compute(Map labels, ConfigUtils.Prefix p * @return a container that holds the names of the source that were found and their * data */ - public abstract MultipleSourcesContainer dataSupplier(Map labels, Set profiles); + public abstract MultipleSourcesContainer dataSupplier(Map labels); } diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigProperties.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigProperties.java index c8ddda3def..4c94d37018 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigProperties.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigProperties.java @@ -59,7 +59,7 @@ public List determineSources(Environment environment) { if (!labels.isEmpty()) { result.add(new LabeledSecretNormalizedSource(this.namespace, this.labels, this.failFast, - ConfigUtils.Prefix.DEFAULT, false)); + ConfigUtils.Prefix.DEFAULT)); } return result; } @@ -105,7 +105,7 @@ private Stream normalize(String defaultName, String defaultNam if (!normalizedLabels.isEmpty()) { NormalizedSource labeledBasedSource = new LabeledSecretNormalizedSource(normalizedNamespace, labels, - failFast, prefix, includeProfileSpecificSources); + failFast, prefix); normalizedSources.add(labeledBasedSource); } diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/LabeledSecretNormalizedSourceTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/LabeledSecretNormalizedSourceTests.java index 9f0774f35a..a30120d2e2 100644 --- a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/LabeledSecretNormalizedSourceTests.java +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/LabeledSecretNormalizedSourceTests.java @@ -31,8 +31,8 @@ class LabeledSecretNormalizedSourceTests { @Test void testEqualsAndHashCode() { - LabeledSecretNormalizedSource left = new LabeledSecretNormalizedSource("namespace", labels, false, false); - LabeledSecretNormalizedSource right = new LabeledSecretNormalizedSource("namespace", labels, true, false); + LabeledSecretNormalizedSource left = new LabeledSecretNormalizedSource("namespace", labels, false); + LabeledSecretNormalizedSource right = new LabeledSecretNormalizedSource("namespace", labels, true); Assertions.assertEquals(left.hashCode(), right.hashCode()); Assertions.assertEquals(left, right); @@ -48,10 +48,8 @@ void testEqualsAndHashCodePrefixDoesNotMatter() { ConfigUtils.Prefix knownLeft = ConfigUtils.findPrefix("left", false, false, "some"); ConfigUtils.Prefix knownRight = ConfigUtils.findPrefix("right", false, false, "some"); - LabeledSecretNormalizedSource left = new LabeledSecretNormalizedSource("namespace", labels, true, knownLeft, - false); - LabeledSecretNormalizedSource right = new LabeledSecretNormalizedSource("namespace", labels, true, knownRight, - false); + LabeledSecretNormalizedSource left = new LabeledSecretNormalizedSource("namespace", labels, true, knownLeft); + LabeledSecretNormalizedSource right = new LabeledSecretNormalizedSource("namespace", labels, true, knownRight); Assertions.assertEquals(left.hashCode(), right.hashCode()); Assertions.assertEquals(left, right); @@ -59,40 +57,37 @@ void testEqualsAndHashCodePrefixDoesNotMatter() { @Test void testType() { - LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false, false); + LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false); Assertions.assertSame(source.type(), NormalizedSourceType.LABELED_SECRET); } @Test void testImmutableGetLabels() { - LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false, false); + LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false); Assertions.assertThrows(RuntimeException.class, () -> source.labels().put("c", "d")); } @Test void testTarget() { - LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false, false); + LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false); Assertions.assertEquals(source.target(), "secret"); } @Test void testConstructorFields() { ConfigUtils.Prefix prefix = ConfigUtils.findPrefix("prefix", false, false, "some"); - LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false, prefix, - true); + LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false, prefix); Assertions.assertTrue(source.name().isEmpty()); Assertions.assertEquals(source.namespace().get(), "namespace"); Assertions.assertFalse(source.failFast()); - Assertions.assertTrue(source.profileSpecificSources()); } @Test void testConstructorWithoutPrefixFields() { - LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, true, true); + LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, true); Assertions.assertEquals(source.namespace().get(), "namespace"); Assertions.assertTrue(source.failFast()); Assertions.assertSame(ConfigUtils.Prefix.DEFAULT, source.prefix()); - Assertions.assertTrue(source.profileSpecificSources()); } } diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigPropertiesTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigPropertiesTests.java index cb3cd6439f..75731be1e6 100644 --- a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigPropertiesTests.java +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigPropertiesTests.java @@ -307,7 +307,6 @@ void testMultipleCases() { * - labels: * - name: second-label * value: secret-two - * includeProfileSpecificSources: true * useNameAsPrefix: true * explicitPrefix: two * - labels: @@ -348,19 +347,15 @@ void testLabelsMultipleCases() { LabeledSecretNormalizedSource labeled1 = (LabeledSecretNormalizedSource) sources.get(1); Assertions.assertEquals(labeled1.prefix().prefixProvider().get(), "one"); - Assertions.assertFalse(labeled1.profileSpecificSources()); LabeledSecretNormalizedSource labeled3 = (LabeledSecretNormalizedSource) sources.get(3); Assertions.assertEquals(labeled3.prefix().prefixProvider().get(), "two"); - Assertions.assertTrue(labeled3.profileSpecificSources()); LabeledSecretNormalizedSource labeled5 = (LabeledSecretNormalizedSource) sources.get(5); Assertions.assertEquals(labeled5.prefix().prefixProvider().get(), "three"); - Assertions.assertFalse(labeled5.profileSpecificSources()); LabeledSecretNormalizedSource labeled7 = (LabeledSecretNormalizedSource) sources.get(7); Assertions.assertSame(labeled7.prefix(), ConfigUtils.Prefix.DEFAULT); - Assertions.assertFalse(labeled7.profileSpecificSources()); Set set = new LinkedHashSet<>(sources); Assertions.assertEquals(5, set.size()); diff --git a/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtils.java b/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtils.java index 9c533d473e..9d0e59e07c 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtils.java +++ b/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtils.java @@ -62,39 +62,35 @@ public static Set namespaces(KubernetesClient client, KubernetesNamespac *
 	 *     1. read all secrets in the provided namespace
 	 *     2. from the above, filter the ones that we care about (filter by labels)
-	 *     3. with secret names from (2), find out if there are any profile based secrets (if profiles is not empty)
-	 *     4. concat (2) and (3) and these are the secrets we are interested in
-	 *     5. see if any of the secrets from (4) has a single yaml/properties file
-	 *     6. gather all the names of the secrets (from 4) + data they hold
+	 *     3. see if any of the secrets from (2) has a single yaml/properties file
+	 *     4. gather all the names of the secrets + data they hold
 	 * 
*/ static MultipleSourcesContainer secretsDataByLabels(KubernetesClient client, String namespace, - Map labels, Environment environment, Set profiles) { + Map labels, Environment environment) { List strippedSecrets = strippedSecrets(client, namespace); if (strippedSecrets.isEmpty()) { return MultipleSourcesContainer.empty(); } - return ConfigUtils.processLabeledData(strippedSecrets, environment, labels, namespace, profiles, true); + return ConfigUtils.processLabeledData(strippedSecrets, environment, labels, namespace, true); } /** *
 	 *     1. read all config maps in the provided namespace
 	 *     2. from the above, filter the ones that we care about (filter by labels)
-	 *     3. with config maps names from (2), find out if there are any profile based ones (if profiles is not empty)
-	 *     4. concat (2) and (3) and these are the config maps we are interested in
-	 *     5. see if any from (4) has a single yaml/properties file
-	 *     6. gather all the names of the config maps (from 4) + data they hold
+	 *     3. see if any from (2) has a single yaml/properties file
+	 *     4. gather all the names of the config maps + data they hold
 	 * 
*/ static MultipleSourcesContainer configMapsDataByLabels(KubernetesClient client, String namespace, - Map labels, Environment environment, Set profiles) { + Map labels, Environment environment) { List strippedConfigMaps = strippedConfigMaps(client, namespace); if (strippedConfigMaps.isEmpty()) { return MultipleSourcesContainer.empty(); } - return ConfigUtils.processLabeledData(strippedConfigMaps, environment, labels, namespace, profiles, false); + return ConfigUtils.processLabeledData(strippedConfigMaps, environment, labels, namespace, false); } /** diff --git a/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProvider.java b/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProvider.java index 8058f041dd..16199d3e0b 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProvider.java +++ b/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProvider.java @@ -17,7 +17,6 @@ package org.springframework.cloud.kubernetes.fabric8.config; import java.util.Map; -import java.util.Set; import java.util.function.Supplier; import org.springframework.cloud.kubernetes.commons.config.LabeledConfigMapNormalizedSource; @@ -55,13 +54,12 @@ public Fabric8ContextToSourceData get() { return new LabeledSourceData() { @Override - public MultipleSourcesContainer dataSupplier(Map labels, Set profiles) { + public MultipleSourcesContainer dataSupplier(Map labels) { return Fabric8ConfigUtils.configMapsDataByLabels(context.client(), context.namespace(), labels, - context.environment(), profiles); + context.environment()); } - }.compute(source.labels(), source.prefix(), source.target(), source.profileSpecificSources(), - source.failFast(), context.namespace(), context.environment().getActiveProfiles()); + }.compute(source.labels(), source.prefix(), source.target(), source.failFast(), context.namespace()); }; } diff --git a/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProvider.java b/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProvider.java index efad27a7ba..cea86c6092 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProvider.java +++ b/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProvider.java @@ -17,7 +17,6 @@ package org.springframework.cloud.kubernetes.fabric8.config; import java.util.Map; -import java.util.Set; import java.util.function.Supplier; import org.springframework.cloud.kubernetes.commons.config.LabeledSecretNormalizedSource; @@ -54,13 +53,12 @@ public Fabric8ContextToSourceData get() { return new LabeledSourceData() { @Override - public MultipleSourcesContainer dataSupplier(Map labels, Set profiles) { + public MultipleSourcesContainer dataSupplier(Map labels) { return Fabric8ConfigUtils.secretsDataByLabels(context.client(), context.namespace(), labels, - context.environment(), profiles); + context.environment()); } - }.compute(source.labels(), source.prefix(), source.target(), source.profileSpecificSources(), - source.failFast(), context.namespace(), context.environment().getActiveProfiles()); + }.compute(source.labels(), source.prefix(), source.target(), source.failFast(), context.namespace()); }; } diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtilsTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtilsTests.java index 843a2e82ad..938c41e16c 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtilsTests.java @@ -61,7 +61,7 @@ void testSecretDataByLabelsSecretNotFound() { .resource(new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName("my-secret").build()).build()) .create(); MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByLabels(client, "spring-k8s", - Map.of("color", "red"), new MockEnvironment(), Set.of()); + Map.of("color", "red"), new MockEnvironment()); Assertions.assertEquals(Map.of(), result.data()); Assertions.assertTrue(result.names().isEmpty()); } @@ -79,7 +79,7 @@ void testSecretDataByLabelsSecretFound() { .create(); MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByLabels(client, "spring-k8s", - Map.of("color", "pink"), new MockEnvironment(), Set.of()); + Map.of("color", "pink"), new MockEnvironment()); Assertions.assertEquals(Set.of("my-secret"), result.names()); Assertions.assertEquals(Map.of("property", "value"), result.data()); } @@ -98,7 +98,7 @@ void testSecretDataByLabelsSecretFoundWithPropertyFile() { .create(); MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByLabels(client, "spring-k8s", - Map.of("color", "pink"), new MockEnvironment(), Set.of()); + Map.of("color", "pink"), new MockEnvironment()); Assertions.assertEquals(Set.of("my-secret"), result.names()); Assertions.assertEquals(Map.of("key1", "value1"), result.data()); } @@ -125,7 +125,7 @@ void testSecretDataByLabelsTwoSecretsFound() { .create(); MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByLabels(client, "spring-k8s", - Map.of("color", "pink"), new MockEnvironment(), Set.of()); + Map.of("color", "pink"), new MockEnvironment()); Assertions.assertTrue(result.names().contains("my-secret")); Assertions.assertTrue(result.names().contains("my-secret-2")); @@ -141,10 +141,8 @@ void testSecretDataByLabelsTwoSecretsFound() { * - secret deployed with name "blue-triangle-secret" and labels "color=blue, shape=triangle, tag=no-fit" * - secret deployed with name "blue-square-secret-k8s" and labels "color=blue, shape=triangle, tag=no-fit" * - * - we search by labels "color=blue, tag=fits", as such first find two secrets: "blue-circle-secret" + * - we search by labels "color=blue, tag=fits", as such find two secrets: "blue-circle-secret" * and "blue-square-secret". - * - since "k8s" profile is enabled, we also take "blue-square-secret-k8s". Notice that this one does not match - * the initial labels (it has "tag=no-fit"), but it does not matter, we take it anyway. * */ @Test @@ -190,16 +188,14 @@ void testSecretDataByLabelsThreeSecretsFound() { .create(); MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByLabels(client, "spring-k8s", - Map.of("tag", "fit", "color", "blue"), new MockEnvironment(), Set.of("k8s")); + Map.of("tag", "fit", "color", "blue"), new MockEnvironment()); Assertions.assertTrue(result.names().contains("blue-circle-secret")); Assertions.assertTrue(result.names().contains("blue-square-secret")); - Assertions.assertTrue(result.names().contains("blue-square-secret-k8s")); - Assertions.assertEquals(3, result.data().size()); + Assertions.assertEquals(2, result.data().size()); Assertions.assertEquals("1", result.data().get("one")); Assertions.assertEquals("2", result.data().get("two")); - Assertions.assertEquals("4", result.data().get("four")); } // secret "my-secret" is deployed; we search for it by name and do not find it. diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8SecretsPropertySourceMockTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8SecretsPropertySourceMockTests.java index c048667484..90f917aa9c 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8SecretsPropertySourceMockTests.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8SecretsPropertySourceMockTests.java @@ -64,7 +64,7 @@ void labeledStrategyShouldThrowExceptionOnFailureWhenFailFastIsEnabled() { final Map labels = Collections.singletonMap("a", "b"); final String path = String.format("/api/v1/namespaces/%s/secrets", namespace); - LabeledSecretNormalizedSource labeled = new LabeledSecretNormalizedSource(namespace, labels, true, false); + LabeledSecretNormalizedSource labeled = new LabeledSecretNormalizedSource(namespace, labels, true); Fabric8ConfigContext context = new Fabric8ConfigContext(client, labeled, "default", new MockEnvironment()); mockServer.expect().withPath(path).andReturn(500, "Internal Server Error").always(); @@ -91,7 +91,7 @@ void labeledStrategyShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() { final Map labels = Collections.singletonMap("a", "b"); final String path = String.format("/api/v1/namespaces/%s/secrets", namespace); - LabeledSecretNormalizedSource labeled = new LabeledSecretNormalizedSource(namespace, labels, false, false); + LabeledSecretNormalizedSource labeled = new LabeledSecretNormalizedSource(namespace, labels, false); Fabric8ConfigContext context = new Fabric8ConfigContext(client, labeled, "default", new MockEnvironment()); mockServer.expect().withPath(path).andReturn(500, "Internal Server Error").always(); diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProviderTests.java index 7342c4c568..2227d2038e 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProviderTests.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProviderTests.java @@ -301,8 +301,7 @@ void testTwoConfigmapsWithPrefix() { /** * two configmaps are deployed: "color-configmap" with label: "{color:blue}" and * "color-configmap-k8s" with no labels. We search by "{color:red}", do not find - * anything and thus have an empty SourceData. profile based sources are enabled, but - * it has no effect. + * anything and thus have an empty SourceData. */ @Test void searchWithLabelsNoConfigmapsFound() { @@ -322,7 +321,6 @@ void searchWithLabelsNoConfigmapsFound() { mockClient.configMaps().inNamespace(NAMESPACE).resource(colorConfigmap).create(); mockClient.configMaps().inNamespace(NAMESPACE).resource(colorConfigmapK8s).create(); MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource(NAMESPACE, Collections.singletonMap("color", "red"), true, ConfigUtils.Prefix.DEFAULT, true); @@ -339,7 +337,7 @@ void searchWithLabelsNoConfigmapsFound() { /** * two configmaps are deployed: "color-configmap" with label: "{color:blue}" and * "shape-configmap" with label: "{shape:round}". We search by "{color:blue}" and find - * one configmap. profile based sources are enabled, but it has no effect. + * one configmap. */ @Test void searchWithLabelsOneConfigMapFound() { @@ -359,7 +357,6 @@ void searchWithLabelsOneConfigMapFound() { mockClient.configMaps().inNamespace(NAMESPACE).resource(colorConfigmap).create(); mockClient.configMaps().inNamespace(NAMESPACE).resource(shapeConfigmap).create(); MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource(NAMESPACE, Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DEFAULT, true); @@ -374,47 +371,6 @@ void searchWithLabelsOneConfigMapFound() { } - /** - * two configmaps are deployed: "color-configmap" with label: "{color:blue}" and - * "color-configmap-k8s" with label: "{color:red}". We search by "{color:blue}" and - * find one configmap. Since profiles are enabled, we will also be reading - * "color-configmap-k8s", even if its labels do not match provided ones. - */ - @Test - void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() { - ConfigMap colorConfigmap = new ConfigMapBuilder().withNewMetadata() - .withName("color-configmap") - .withLabels(Collections.singletonMap("color", "blue")) - .endMetadata() - .addToData("one", "1") - .build(); - - ConfigMap colorConfigmapK8s = new ConfigMapBuilder().withNewMetadata() - .withName("color-configmap-k8s") - .withLabels(Collections.singletonMap("color", "red")) - .endMetadata() - .addToData("two", "2") - .build(); - - mockClient.configMaps().inNamespace(NAMESPACE).resource(colorConfigmap).create(); - mockClient.configMaps().inNamespace(NAMESPACE).resource(colorConfigmapK8s).create(); - MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); - - NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DELAYED, true); - Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, environment); - - Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); - SourceData sourceData = data.apply(context); - - Assertions.assertEquals(sourceData.sourceData().size(), 2); - Assertions.assertEquals(sourceData.sourceData().get("color-configmap.color-configmap-k8s.one"), "1"); - Assertions.assertEquals(sourceData.sourceData().get("color-configmap.color-configmap-k8s.two"), "2"); - Assertions.assertEquals(sourceData.sourceName(), "configmap.color-configmap.color-configmap-k8s.default"); - - } - /** *
 	 *     - configmap "color-configmap" with label "{color:blue}"
@@ -425,7 +381,7 @@ void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() {
 	 * 
*/ @Test - void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() { + void searchWithLabelsTwoConfigMapsFound() { ConfigMap colorConfigMap = new ConfigMapBuilder().withNewMetadata() .withName("color-configmap") .withLabels(Collections.singletonMap("color", "blue")) @@ -468,7 +424,6 @@ void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() { mockClient.configMaps().inNamespace(NAMESPACE).resource(shapeConfigmapK8s).create(); MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource(NAMESPACE, Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DELAYED, true); @@ -477,18 +432,11 @@ void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() { Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceData().size(), 4); - Assertions.assertEquals(sourceData.sourceData() - .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.one"), "1"); - Assertions.assertEquals(sourceData.sourceData() - .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.two"), "2"); - Assertions.assertEquals(sourceData.sourceData() - .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.four"), "4"); - Assertions.assertEquals(sourceData.sourceData() - .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.five"), "5"); - - Assertions.assertEquals(sourceData.sourceName(), - "configmap.color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.default"); + Assertions.assertEquals(sourceData.sourceData().size(), 2); + Assertions.assertEquals(sourceData.sourceData().get("color-configmap.shape-configmap.one"), "1"); + Assertions.assertEquals(sourceData.sourceData().get("color-configmap.shape-configmap.two"), "2"); + + Assertions.assertEquals(sourceData.sourceName(), "configmap.color-configmap.shape-configmap.default"); } diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java index 835e831c89..ff383321fb 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java @@ -62,14 +62,12 @@ class LabeledSecretContextToSourceDataProviderTests { private static KubernetesClient mockClient; - static { - LABELS.put("label2", "value2"); - LABELS.put("label1", "value1"); - } - @BeforeAll static void beforeAll() { + LABELS.put("label2", "value2"); + LABELS.put("label1", "value1"); + // Configure the kubernetes master url to point to the mock server System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl()); System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); @@ -102,7 +100,7 @@ void singleSecretMatchAgainstLabels() { mockClient.secrets().inNamespace(NAMESPACE).resource(secret).create(); - NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, LABELS, true, false); + NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, LABELS, true); Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, new MockEnvironment()); @@ -146,7 +144,7 @@ void twoSecretsMatchAgainstLabels() { mockClient.secrets().inNamespace(NAMESPACE).resource(redTwo).create(); mockClient.secrets().inNamespace(NAMESPACE).resource(blue).create(); - NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, RED_LABEL, true, false); + NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, RED_LABEL, true); Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, new MockEnvironment()); @@ -175,7 +173,7 @@ void secretNoMatch() { mockClient.secrets().inNamespace(NAMESPACE).resource(pink).create(); - NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, BLUE_LABEL, true, false); + NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, BLUE_LABEL, true); Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, new MockEnvironment()); @@ -205,7 +203,7 @@ void namespaceMatch() { mockClient.secrets().inNamespace(NAMESPACE).resource(secret).create(); // different namespace - NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE + "nope", LABELS, true, false); + NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE + "nope", LABELS, true); Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, new MockEnvironment()); @@ -235,7 +233,7 @@ void testWithPrefix() { ConfigUtils.Prefix mePrefix = ConfigUtils.findPrefix("me", false, false, "irrelevant"); NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "blue"), true, mePrefix, false); + Collections.singletonMap("color", "blue"), true, mePrefix); Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, new MockEnvironment()); @@ -275,7 +273,7 @@ void testTwoSecretsWithPrefix() { mockClient.secrets().inNamespace(NAMESPACE).resource(anotherBlue).create(); NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DELAYED, false); + Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DELAYED); Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, new MockEnvironment()); @@ -302,8 +300,7 @@ void testTwoSecretsWithPrefix() { /** * two secrets are deployed: secret "color-secret" with label: "{color:blue}" and * "color-secret-k8s" with no labels. We search by "{color:red}", do not find anything - * and thus have an empty SourceData. profile based sources are enabled, but it has no - * effect. + * and thus have an empty SourceData. */ @Test void searchWithLabelsNoSecretFound() { @@ -323,10 +320,9 @@ void searchWithLabelsNoSecretFound() { mockClient.secrets().inNamespace(NAMESPACE).resource(colorSecret).create(); mockClient.secrets().inNamespace(NAMESPACE).resource(colorSecretK8s).create(); MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "red"), true, ConfigUtils.Prefix.DEFAULT, true); + Collections.singletonMap("color", "red"), true, ConfigUtils.Prefix.DEFAULT); Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, environment); Fabric8ContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); @@ -340,7 +336,7 @@ void searchWithLabelsNoSecretFound() { /** * two secrets are deployed: secret "color-secret" with label: "{color:blue}" and * "shape-secret" with label: "{shape:round}". We search by "{color:blue}" and find - * one secret. profile based sources are enabled, but it has no effect. + * one secret. */ @Test void searchWithLabelsOneSecretFound() { @@ -360,10 +356,9 @@ void searchWithLabelsOneSecretFound() { mockClient.secrets().inNamespace(NAMESPACE).resource(colorSecret).create(); mockClient.secrets().inNamespace(NAMESPACE).resource(shapeSecret).create(); MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DEFAULT, true); + Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DEFAULT); Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, environment); Fabric8ContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); @@ -375,47 +370,6 @@ void searchWithLabelsOneSecretFound() { } - /** - * two secrets are deployed: secret "color-secret" with label: "{color:blue}" and - * "color-secret-k8s" with label: "{color:red}". We search by "{color:blue}" and find - * one secret. Since profiles are enabled, we will also be reading "color-secret-k8s", - * even if its labels do not match provided ones. - */ - @Test - void searchWithLabelsOneSecretFoundAndOneFromProfileFound() { - Secret colorSecret = new SecretBuilder().withNewMetadata() - .withName("color-secret") - .withLabels(Collections.singletonMap("color", "blue")) - .endMetadata() - .addToData("one", Base64.getEncoder().encodeToString("1".getBytes())) - .build(); - - Secret colorSecretK8s = new SecretBuilder().withNewMetadata() - .withName("color-secret-k8s") - .withLabels(Collections.singletonMap("color", "red")) - .endMetadata() - .addToData("two", Base64.getEncoder().encodeToString("2".getBytes())) - .build(); - - mockClient.secrets().inNamespace(NAMESPACE).resource(colorSecret).create(); - mockClient.secrets().inNamespace(NAMESPACE).resource(colorSecretK8s).create(); - MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); - - NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DELAYED, true); - Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, environment); - - Fabric8ContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); - SourceData sourceData = data.apply(context); - - Assertions.assertEquals(sourceData.sourceData().size(), 2); - Assertions.assertEquals(sourceData.sourceData().get("color-secret.color-secret-k8s.one"), "1"); - Assertions.assertEquals(sourceData.sourceData().get("color-secret.color-secret-k8s.two"), "2"); - Assertions.assertEquals(sourceData.sourceName(), "secret.color-secret.color-secret-k8s.default"); - - } - /** *
 	 *     - secret "color-secret" with label "{color:blue}"
@@ -426,7 +380,7 @@ void searchWithLabelsOneSecretFoundAndOneFromProfileFound() {
 	 * 
*/ @Test - void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() { + void searchWithLabelsTwoSecretsFound() { Secret colorSecret = new SecretBuilder().withNewMetadata() .withName("color-secret") .withLabels(Collections.singletonMap("color", "blue")) @@ -469,27 +423,21 @@ void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() { mockClient.secrets().inNamespace(NAMESPACE).resource(shapeSecretK8s).create(); MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DELAYED, true); + Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DELAYED); Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, environment); Fabric8ContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceData().size(), 4); - Assertions.assertEquals( - sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.one"), "1"); - Assertions.assertEquals( - sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.two"), "2"); + Assertions.assertEquals(sourceData.sourceData().size(), 2); Assertions.assertEquals( - sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.four"), "4"); + sourceData.sourceData().get("color-secret.shape-secret.one"), "1"); Assertions.assertEquals( - sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.five"), "5"); + sourceData.sourceData().get("color-secret.shape-secret.two"), "2"); - Assertions.assertEquals(sourceData.sourceName(), - "secret.color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.default"); + Assertions.assertEquals(sourceData.sourceName(), "secret.color-secret.shape-secret.default"); } @@ -508,7 +456,7 @@ void testYaml() { mockClient.secrets().inNamespace(NAMESPACE).resource(colorSecret).create(); NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DEFAULT, true); + Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DEFAULT); Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, new MockEnvironment()); @@ -550,7 +498,7 @@ void cache(CapturedOutput output) { MockEnvironment environment = new MockEnvironment(); NormalizedSource redNormalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "red"), true, ConfigUtils.Prefix.DELAYED, true); + Collections.singletonMap("color", "red"), true, ConfigUtils.Prefix.DELAYED); Fabric8ConfigContext redContext = new Fabric8ConfigContext(mockClient, redNormalizedSource, NAMESPACE, environment); Fabric8ContextToSourceData redData = new LabeledSecretContextToSourceDataProvider().get(); @@ -561,7 +509,7 @@ void cache(CapturedOutput output) { Assertions.assertTrue(output.getAll().contains("Loaded all secrets in namespace '" + NAMESPACE + "'")); NormalizedSource greenNormalizedSource = new LabeledSecretNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "green"), true, ConfigUtils.Prefix.DELAYED, true); + Collections.singletonMap("color", "green"), true, ConfigUtils.Prefix.DELAYED); Fabric8ConfigContext greenContext = new Fabric8ConfigContext(mockClient, greenNormalizedSource, NAMESPACE, environment); Fabric8ContextToSourceData greenData = new LabeledSecretContextToSourceDataProvider().get(); diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/labeled_config_map_with_profile/LabeledConfigMapWithProfile.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/labeled_config_map_with_profile/LabeledConfigMapWithProfile.java index 298f337e8a..0a28020a29 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/labeled_config_map_with_profile/LabeledConfigMapWithProfile.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/labeled_config_map_with_profile/LabeledConfigMapWithProfile.java @@ -53,9 +53,6 @@ abstract class LabeledConfigMapWithProfile { * - configmap with name "color-configmap-k8s", with labels : "{color: not-blue}" * - configmap with name "green-configmap-k8s", with labels : "{color: green-k8s}" * - configmap with name "green-configmap-prod", with labels : "{color: green-prod}" - * - * # a test that proves order: first read non-profile based configmaps, thus profile based - * # configmaps override non-profile ones. * - configmap with name "green-purple-configmap", labels "{color: green, shape: round}", data: "{eight: 8}" * - configmap with name "green-purple-configmap-k8s", labels "{color: black}", data: "{eight: eight-ish}" * @@ -74,7 +71,7 @@ static void setUpBeforeClass(KubernetesClient mockClient) { Map colorConfigMap = Collections.singletonMap("one", "1"); createConfigMap("color-configmap", colorConfigMap, Collections.singletonMap("color", "blue")); - // is not taken, since "profileSpecificSources=false" for the above + // is not taken Map colorConfigMapK8s = Collections.singletonMap("five", "5"); createConfigMap("color-configmap-k8s", colorConfigMapK8s, Collections.singletonMap("color", "not-blue")); @@ -82,13 +79,13 @@ static void setUpBeforeClass(KubernetesClient mockClient) { Map greenConfigMap = Collections.singletonMap("two", "2"); createConfigMap("green-configmap", greenConfigMap, Collections.singletonMap("color", "green")); - // is taken because k8s profile is active and "profileSpecificSources=true" + // is taken Map greenConfigMapK8s = Collections.singletonMap("six", "6"); - createConfigMap("green-configmap-k8s", greenConfigMapK8s, Collections.singletonMap("color", "green-k8s")); + createConfigMap("green-configmap-k8s", greenConfigMapK8s, Collections.singletonMap("color", "green")); - // is taken because prod profile is active and "profileSpecificSources=true" + // is taken Map greenConfigMapProd = Collections.singletonMap("seven", "7"); - createConfigMap("green-configmap-prod", greenConfigMapProd, Collections.singletonMap("color", "green-prod")); + createConfigMap("green-configmap-prod", greenConfigMapProd, Collections.singletonMap("color", "green")); // not taken Map redConfigMap = Collections.singletonMap("three", "3"); @@ -104,7 +101,7 @@ static void setUpBeforeClass(KubernetesClient mockClient) { // is taken and thus overrides the above Map greenPurpleK8s = Collections.singletonMap("eight", "eight-ish"); - createConfigMap("green-purple-configmap-k8s", greenPurpleK8s, Map.of("color", "black")); + createConfigMap("green-purple-configmap-k8s", greenPurpleK8s, Map.of("color", "green")); } @@ -123,7 +120,7 @@ private static void createConfigMap(String name, Map data, Map * this one is taken from : "blue.one". We find "color-configmap" by labels, and - * "color-configmap-k8s" exists, but "includeProfileSpecificSources=false", thus not taken. + * "color-configmap-k8s" exists, but not taken. * Since "explicitPrefix=blue", we take "blue.one" * */ @@ -141,9 +138,8 @@ void testBlue() { /** *
 	 *   this one is taken from : "green-configmap.green-configmap-k8s.green-configmap-prod.green-purple-configmap.green-purple-configmap-k8s".
-	 *   We find "green-configmap" by labels, also "green-configmap-k8s" and "green-configmap-prod" exists,
-	 *   because "includeProfileSpecificSources=true" is set. Also "green-purple-configmap" and "green-purple-configmap-k8s"
-	 * 	 are found.
+	 *   We find "green-configmap", "green-configmap-k8s", "green-configmap-prod"  by labels.
+	 *   Also "green-purple-configmap" and "green-purple-configmap-k8s" are found.
 	 * 
*/ @Test diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/labeled_secret_with_profile/LabeledSecretWithProfile.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/labeled_secret_with_profile/LabeledSecretWithProfile.java index 184a8242bf..73212476b6 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/labeled_secret_with_profile/LabeledSecretWithProfile.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/labeled_secret_with_profile/LabeledSecretWithProfile.java @@ -54,9 +54,6 @@ abstract class LabeledSecretWithProfile { * - secret with name "color-secret-k8s", with labels : "{color: not-blue}" * - secret with name "green-secret-k8s", with labels : "{color: green-k8s}" * - secret with name "green-secret-prod", with labels : "{color: green-prod}" - * - * # a test that proves order: first read non-profile based secrets, thus profile based - * # secrets override non-profile ones. * - secret with name "green-purple-secret", labels "{color: green, shape: round}", data: "{eight: 8}" * - secret with name "green-purple-secret-k8s", labels "{color: black}", data: "{eight: eight-ish}" * @@ -76,7 +73,7 @@ static void setUpBeforeClass(KubernetesClient mockClient) { Base64.getEncoder().encodeToString("1".getBytes(StandardCharsets.UTF_8))); createSecret("color-secret", colorSecret, Collections.singletonMap("color", "blue")); - // is not taken, since "profileSpecificSources=false" for the above + // is not taken Map colorSecretK8s = Collections.singletonMap("five", Base64.getEncoder().encodeToString("5".getBytes(StandardCharsets.UTF_8))); createSecret("color-secret-k8s", colorSecretK8s, Collections.singletonMap("color", "not-blue")); @@ -86,15 +83,15 @@ static void setUpBeforeClass(KubernetesClient mockClient) { Base64.getEncoder().encodeToString("2".getBytes(StandardCharsets.UTF_8))); createSecret("green-secret", greenSecret, Collections.singletonMap("color", "green")); - // is taken because k8s profile is active and "profileSpecificSources=true" + // is taken Map shapeSecretK8s = Collections.singletonMap("six", Base64.getEncoder().encodeToString("6".getBytes(StandardCharsets.UTF_8))); - createSecret("green-secret-k8s", shapeSecretK8s, Collections.singletonMap("color", "green-k8s")); + createSecret("green-secret-k8s", shapeSecretK8s, Collections.singletonMap("color", "green")); - // // is taken because prod profile is active and "profileSpecificSources=true" + // // is taken Map shapeSecretProd = Collections.singletonMap("seven", Base64.getEncoder().encodeToString("7".getBytes(StandardCharsets.UTF_8))); - createSecret("green-secret-prod", shapeSecretProd, Collections.singletonMap("color", "green-prod")); + createSecret("green-secret-prod", shapeSecretProd, Collections.singletonMap("color", "green")); // not taken Map redSecret = Collections.singletonMap("three", @@ -114,7 +111,7 @@ static void setUpBeforeClass(KubernetesClient mockClient) { // is taken and thus overrides the above Map greenPurpleK8s = Collections.singletonMap("eight", Base64.getEncoder().encodeToString("eight-ish".getBytes(StandardCharsets.UTF_8))); - createSecret("green-purple-secret-k8s", greenPurpleK8s, Map.of("color", "black")); + createSecret("green-purple-secret-k8s", greenPurpleK8s, Map.of("color", "green")); } @@ -133,7 +130,7 @@ private static void createSecret(String name, Map data, Map * this one is taken from : "blue.one". We find "color-secret" by labels, and - * "color-secrets-k8s" exists, but "includeProfileSpecificSources=false", thus not taken. + * "color-secrets-k8s". * Since "explicitPrefix=blue", we take "blue.one" * */ @@ -151,9 +148,8 @@ void testBlue() { /** *
 	 *   this one is taken from : "green-purple-secret.green-purple-secret-k8s.green-secret.green-secret-k8s.green-secret-prod".
-	 *   We find "green-secret" by labels, also "green-secrets-k8s" and "green-secrets-prod" exists,
-	 *   because "includeProfileSpecificSources=true" is set. Also "green-purple-secret" and "green-purple-secret-k8s"
-	 * 	 are found.
+	 *   We find "green-secret", "green-secrets-k8s" and "green-secrets-prod" by labels.
+	 *   Also "green-purple-secret" and "green-purple-secret-k8s" are found.
 	 * 
*/ @Test diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/resources/labeled-configmap-with-profile.yaml b/spring-cloud-kubernetes-fabric8-config/src/test/resources/labeled-configmap-with-profile.yaml index 8aa88d2deb..5cde6f0742 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/resources/labeled-configmap-with-profile.yaml +++ b/spring-cloud-kubernetes-fabric8-config/src/test/resources/labeled-configmap-with-profile.yaml @@ -7,12 +7,10 @@ spring: enableApi: true useNameAsPrefix: true namespace: spring-k8s - includeProfileSpecificSources: true sources: - labels: color: blue explicitPrefix: blue - includeProfileSpecificSources: false - labels: color: green - labels: diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/resources/labeled-secret-with-profile.yaml b/spring-cloud-kubernetes-fabric8-config/src/test/resources/labeled-secret-with-profile.yaml index 89255f0810..b22cac4bf9 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/resources/labeled-secret-with-profile.yaml +++ b/spring-cloud-kubernetes-fabric8-config/src/test/resources/labeled-secret-with-profile.yaml @@ -7,12 +7,10 @@ spring: enableApi: true useNameAsPrefix: true namespace: spring-k8s - includeProfileSpecificSources: true sources: - labels: color: blue explicitPrefix: blue - includeProfileSpecificSources: false - labels: color: green - labels: From b9c07e4ba4b44c513283b0b330dff761baf34794 Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 16 Jan 2025 08:45:34 +0200 Subject: [PATCH 08/12] placeholder commit From 8298be4bf8fb528d066da190c9f12a6801741c7c Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 16 Jan 2025 08:47:47 +0200 Subject: [PATCH 09/12] checkstyle Signed-off-by: wind57 --- .../LabeledSecretContextToSourceDataProviderTests.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java index ff383321fb..accfd82718 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java @@ -432,10 +432,8 @@ void searchWithLabelsTwoSecretsFound() { SourceData sourceData = data.apply(context); Assertions.assertEquals(sourceData.sourceData().size(), 2); - Assertions.assertEquals( - sourceData.sourceData().get("color-secret.shape-secret.one"), "1"); - Assertions.assertEquals( - sourceData.sourceData().get("color-secret.shape-secret.two"), "2"); + Assertions.assertEquals(sourceData.sourceData().get("color-secret.shape-secret.one"), "1"); + Assertions.assertEquals(sourceData.sourceData().get("color-secret.shape-secret.two"), "2"); Assertions.assertEquals(sourceData.sourceName(), "secret.color-secret.shape-secret.default"); From c6d1ae22efeea17daa9b0ca7660e833546c436c5 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 5 Apr 2025 15:55:11 +0300 Subject: [PATCH 10/12] fix tests Signed-off-by: wind57 --- .../kubernetes/fabric8/config/Fabric8ConfigUtilsTests.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtilsTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtilsTests.java index 637c09c8c4..94e878b432 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtilsTests.java @@ -190,10 +190,9 @@ void testSecretDataByLabelsThreeSecretsFound() { Map.of("tag", "fit", "color", "blue"), new MockEnvironment()); Assertions.assertThat(result.names()).contains("blue-circle-secret"); Assertions.assertThat(result.names()).contains("blue-square-secret"); - Assertions.assertThat(result.names()).contains("blue-square-secret-k8s"); Assertions.assertThat(result.data()) - .containsExactlyInAnyOrderEntriesOf(Map.of("one", "1", "two", "2", "four", "4")); + .containsExactlyInAnyOrderEntriesOf(Map.of("one", "1", "two", "2")); } // secret "my-secret" is deployed; we search for it by name and do not find it. From 91265acf2619f1e8aeb20e7b19dd4e5c4cf5bb62 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 5 Apr 2025 23:32:16 +0300 Subject: [PATCH 11/12] fix test Signed-off-by: wind57 --- ...igMapContextToSourceDataProviderTests.java | 69 ++----------------- 1 file changed, 4 insertions(+), 65 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProviderTests.java index 0daaeff454..917b2a1dda 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProviderTests.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledConfigMapContextToSourceDataProviderTests.java @@ -374,51 +374,6 @@ void searchWithLabelsOneConfigMapFound() { } /** -<<<<<<< HEAD -======= - * two configmaps are deployed: "color-configmap" with label: "{color:blue}" and - * "color-configmap-k8s" with label: "{color:red}". We search by "{color:blue}" and - * find one configmap. Since profiles are enabled, we will also be reading - * "color-configmap-k8s", even if its labels do not match provided ones. - */ - @Test - void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() { - ConfigMap colorConfigmap = new ConfigMapBuilder().withNewMetadata() - .withName("color-configmap") - .withLabels(Collections.singletonMap("color", "blue")) - .endMetadata() - .addToData("one", "1") - .build(); - - ConfigMap colorConfigmapK8s = new ConfigMapBuilder().withNewMetadata() - .withName("color-configmap-k8s") - .withLabels(Collections.singletonMap("color", "red")) - .endMetadata() - .addToData("two", "2") - .build(); - - mockClient.configMaps().inNamespace(NAMESPACE).resource(colorConfigmap).create(); - mockClient.configMaps().inNamespace(NAMESPACE).resource(colorConfigmapK8s).create(); - MockEnvironment environment = new MockEnvironment(); - environment.setActiveProfiles("k8s"); - - NormalizedSource normalizedSource = new LabeledConfigMapNormalizedSource(NAMESPACE, - Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DELAYED, true); - Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, environment); - - Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); - SourceData sourceData = data.apply(context); - - Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2); - Assertions.assertThat(sourceData.sourceData().get("color-configmap.color-configmap-k8s.one")).isEqualTo("1"); - Assertions.assertThat(sourceData.sourceData().get("color-configmap.color-configmap-k8s.two")).isEqualTo("2"); - Assertions.assertThat(sourceData.sourceName()) - .isEqualTo("configmap.color-configmap.color-configmap-k8s.default"); - - } - - /** ->>>>>>> main *
 	 *     - configmap "color-configmap" with label "{color:blue}"
 	 *     - configmap "shape-configmap" with labels "{color:blue, shape:round}"
@@ -479,26 +434,10 @@ void searchWithLabelsTwoConfigMapsFound() {
 		Fabric8ContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get();
 		SourceData sourceData = data.apply(context);
 
-		Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(4);
-		Assertions
-			.assertThat(sourceData.sourceData()
-				.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.one"))
-			.isEqualTo("1");
-		Assertions
-			.assertThat(sourceData.sourceData()
-				.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.two"))
-			.isEqualTo("2");
-		Assertions
-			.assertThat(sourceData.sourceData()
-				.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.four"))
-			.isEqualTo("4");
-		Assertions
-			.assertThat(sourceData.sourceData()
-				.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.five"))
-			.isEqualTo("5");
-
-		Assertions.assertThat(sourceData.sourceName())
-			.isEqualTo("configmap.color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.default");
+		Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2);
+		Assertions.assertThat(sourceData.sourceData().get("color-configmap.shape-configmap.one")).isEqualTo("1");
+		Assertions.assertThat(sourceData.sourceData().get("color-configmap.shape-configmap.two")).isEqualTo("2");
+		Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.color-configmap.shape-configmap.default");
 
 	}
 

From 379846c52e3f7ac55c343232d7aa47764cb2e221 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sun, 6 Apr 2025 15:32:22 +0300
Subject: [PATCH 12/12] fix test

Signed-off-by: wind57 
---
 ...ecretContextToSourceDataProviderTests.java | 64 ++-----------------
 1 file changed, 4 insertions(+), 60 deletions(-)

diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java
index ec8394a1fc..7188251188 100644
--- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java
+++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/LabeledSecretContextToSourceDataProviderTests.java
@@ -374,50 +374,6 @@ void searchWithLabelsOneSecretFound() {
 	}
 
 	/**
-<<<<<<< HEAD
-=======
-	 * two secrets are deployed: secret "color-secret" with label: "{color:blue}" and
-	 * "color-secret-k8s" with label: "{color:red}". We search by "{color:blue}" and find
-	 * one secret. Since profiles are enabled, we will also be reading "color-secret-k8s",
-	 * even if its labels do not match provided ones.
-	 */
-	@Test
-	void searchWithLabelsOneSecretFoundAndOneFromProfileFound() {
-		Secret colorSecret = new SecretBuilder().withNewMetadata()
-			.withName("color-secret")
-			.withLabels(Collections.singletonMap("color", "blue"))
-			.endMetadata()
-			.addToData("one", Base64.getEncoder().encodeToString("1".getBytes()))
-			.build();
-
-		Secret colorSecretK8s = new SecretBuilder().withNewMetadata()
-			.withName("color-secret-k8s")
-			.withLabels(Collections.singletonMap("color", "red"))
-			.endMetadata()
-			.addToData("two", Base64.getEncoder().encodeToString("2".getBytes()))
-			.build();
-
-		mockClient.secrets().inNamespace(NAMESPACE).resource(colorSecret).create();
-		mockClient.secrets().inNamespace(NAMESPACE).resource(colorSecretK8s).create();
-		MockEnvironment environment = new MockEnvironment();
-		environment.setActiveProfiles("k8s");
-
-		NormalizedSource normalizedSource = new LabeledSecretNormalizedSource(NAMESPACE,
-				Collections.singletonMap("color", "blue"), true, ConfigUtils.Prefix.DELAYED);
-		Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, normalizedSource, NAMESPACE, environment);
-
-		Fabric8ContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get();
-		SourceData sourceData = data.apply(context);
-
-		Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2);
-		Assertions.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.one")).isEqualTo("1");
-		Assertions.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.two")).isEqualTo("2");
-		Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.color-secret.color-secret-k8s.default");
-
-	}
-
-	/**
->>>>>>> main
 	 * 
 	 *     - secret "color-secret" with label "{color:blue}"
 	 *     - secret "shape-secret" with labels "{color:blue, shape:round}"
@@ -478,22 +434,10 @@ void searchWithLabelsTwoSecretsFound() {
 		Fabric8ContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get();
 		SourceData sourceData = data.apply(context);
 
-		Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(4);
-		Assertions
-			.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.one"))
-			.isEqualTo("1");
-		Assertions
-			.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.two"))
-			.isEqualTo("2");
-		Assertions
-			.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.four"))
-			.isEqualTo("4");
-		Assertions
-			.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.five"))
-			.isEqualTo("5");
-
-		Assertions.assertThat(sourceData.sourceName())
-			.isEqualTo("secret.color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.default");
+		Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2);
+		Assertions.assertThat(sourceData.sourceData().get("color-secret.shape-secret.one")).isEqualTo("1");
+		Assertions.assertThat(sourceData.sourceData().get("color-secret.shape-secret.two")).isEqualTo("2");
+		Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.color-secret.shape-secret.default");
 
 	}