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 f4be4ef88e..a94a1f01ae 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 50173d3918..dea32e078c 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 @@ -193,7 +193,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 66b1211e11..b4ebe313c7 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); @@ -491,7 +489,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") @@ -499,7 +497,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") @@ -514,7 +512,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 946691eb22..90f0853f0e 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(); @@ -497,7 +493,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()); @@ -542,7 +538,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(); @@ -554,7 +550,7 @@ void cache(CapturedOutput output) { Assertions.assertThat(output.getOut()).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 95cf263616..8d65b02420 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; @@ -273,13 +271,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 -> { @@ -288,33 +284,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 428949d427..c140ad5a39 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 org.apache.commons.logging.Log; @@ -39,16 +37,12 @@ public abstract class LabeledSourceData { private static final Log LOG = LogFactory.getLog(LabeledSourceData.class); 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 is using provided labels, @@ -98,6 +92,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 d2b36f0260..08c71c904f 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.assertThat(left.hashCode()).isEqualTo(right.hashCode()); Assertions.assertThat(left).isEqualTo(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.assertThat(left.hashCode()).isEqualTo(right.hashCode()); Assertions.assertThat(left).isEqualTo(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.assertThat(source.type()).isSameAs(NormalizedSourceType.LABELED_SECRET); } @Test void testImmutableGetLabels() { - LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false, false); + LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false); Assertions.assertThatThrownBy(() -> source.labels().put("c", "d")).isInstanceOf(RuntimeException.class); } @Test void testTarget() { - LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false, false); + LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, false); Assertions.assertThat(source.target()).isEqualTo("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.assertThat(source.name().isEmpty()).isTrue(); Assertions.assertThat(source.namespace().get()).isEqualTo("namespace"); Assertions.assertThat(source.failFast()).isFalse(); - Assertions.assertThat(source.profileSpecificSources()).isTrue(); } @Test void testConstructorWithoutPrefixFields() { - LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, true, true); + LabeledSecretNormalizedSource source = new LabeledSecretNormalizedSource("namespace", labels, true); Assertions.assertThat(source.namespace().get()).isEqualTo("namespace"); Assertions.assertThat(source.failFast()).isTrue(); Assertions.assertThat(ConfigUtils.Prefix.DEFAULT).isSameAs(source.prefix()); - Assertions.assertThat(source.profileSpecificSources()).isTrue(); } } 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 3ce6463ad8..ff604a8b2d 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.assertThat(labeled1.prefix().prefixProvider().get()).isEqualTo("one"); - Assertions.assertThat(labeled1.profileSpecificSources()).isFalse(); LabeledSecretNormalizedSource labeled3 = (LabeledSecretNormalizedSource) sources.get(3); Assertions.assertThat(labeled3.prefix().prefixProvider().get()).isEqualTo("two"); - Assertions.assertThat(labeled3.profileSpecificSources()).isTrue(); LabeledSecretNormalizedSource labeled5 = (LabeledSecretNormalizedSource) sources.get(5); Assertions.assertThat(labeled5.prefix().prefixProvider().get()).isEqualTo("three"); - Assertions.assertThat(labeled5.profileSpecificSources()).isFalse(); LabeledSecretNormalizedSource labeled7 = (LabeledSecretNormalizedSource) sources.get(7); Assertions.assertThat(labeled7.prefix()).isSameAs(ConfigUtils.Prefix.DEFAULT); - Assertions.assertThat(labeled7.profileSpecificSources()).isFalse(); Set set = new LinkedHashSet<>(sources); Assertions.assertThat(set.size()).isEqualTo(5); 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 4b579a592b..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 @@ -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.assertThat(result.data()).isEmpty(); Assertions.assertThat(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.assertThat(result.names()).containsExactlyInAnyOrder("my-secret"); Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("property", "value")); } @@ -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.assertThat(result.names()).containsExactlyInAnyOrder("my-secret"); Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("key1", "value1")); } @@ -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.assertThat(result.names()).contains("my-secret"); Assertions.assertThat(result.names()).contains("my-secret-2"); @@ -140,10 +140,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 @@ -189,14 +187,12 @@ 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.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. 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 a0a246eded..461e707a2d 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 @@ -70,7 +70,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(); @@ -97,7 +97,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 46906685b9..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 @@ -303,8 +303,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() { @@ -324,7 +323,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); @@ -341,7 +339,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() { @@ -361,7 +359,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); @@ -376,48 +373,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.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"); - - } - /** *
 	 *     - configmap "color-configmap" with label "{color:blue}"
@@ -428,7 +383,7 @@ void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() {
 	 * 
*/ @Test - void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() { + void searchWithLabelsTwoConfigMapsFound() { ConfigMap colorConfigMap = new ConfigMapBuilder().withNewMetadata() .withName("color-configmap") .withLabels(Collections.singletonMap("color", "blue")) @@ -471,7 +426,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); @@ -480,26 +434,10 @@ void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() { 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"); } 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 22964de0c8..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 @@ -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()); @@ -147,7 +145,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()); @@ -176,7 +174,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()); @@ -206,7 +204,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()); @@ -237,7 +235,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()); @@ -278,7 +276,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()); @@ -305,8 +303,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() { @@ -326,10 +323,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(); @@ -343,7 +339,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() { @@ -363,10 +359,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(); @@ -378,47 +373,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.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"); - - } - /** *
 	 *     - secret "color-secret" with label "{color:blue}"
@@ -429,7 +383,7 @@ void searchWithLabelsOneSecretFoundAndOneFromProfileFound() {
 	 * 
*/ @Test - void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() { + void searchWithLabelsTwoSecretsFound() { Secret colorSecret = new SecretBuilder().withNewMetadata() .withName("color-secret") .withLabels(Collections.singletonMap("color", "blue")) @@ -472,31 +426,18 @@ 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.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"); } @@ -515,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()); @@ -557,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(); @@ -568,7 +509,7 @@ void cache(CapturedOutput output) { Assertions.assertThat(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: