fix 909 (Drop @Deprecated things in some modules) (#910)

* fix

* test

* fix @Nested tests not running

* trigger again

* clean-up
This commit is contained in:
erabii
2022-01-24 23:46:58 +02:00
committed by GitHub
parent 5675f03335
commit 12f3b52145
21 changed files with 45 additions and 350 deletions

View File

@@ -42,13 +42,6 @@ public class KubernetesClientConfigMapPropertySource extends ConfigMapPropertySo
private static final Log LOG = LogFactory.getLog(KubernetesClientConfigMapPropertySource.class);
@Deprecated
public KubernetesClientConfigMapPropertySource(CoreV1Api coreV1Api, String name, String namespace,
Environment environment) {
super(getName(name, getApplicationNamespace(namespace, "Config Map", null)), getData(coreV1Api, name,
getApplicationNamespace(namespace, "Config Map", null), environment, "", true, false));
}
public KubernetesClientConfigMapPropertySource(CoreV1Api coreV1Api, String name, String namespace,
Environment environment, String prefix, boolean includeProfileSpecificSources, boolean failFast) {
super(getName(name, getApplicationNamespace(namespace, "Config Map", null)),

View File

@@ -18,11 +18,9 @@ package org.springframework.cloud.kubernetes.client.config;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.config.ConfigMapConfigProperties;
import org.springframework.cloud.kubernetes.commons.config.ConfigMapPropertySourceLocator;
import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.util.StringUtils;
@@ -35,32 +33,13 @@ public class KubernetesClientConfigMapPropertySourceLocator extends ConfigMapPro
private final CoreV1Api coreV1Api;
private final KubernetesClientProperties kubernetesClientProperties;
private final KubernetesNamespaceProvider kubernetesNamespaceProvider;
/**
* This constructor is deprecated. Its usage might cause unexpected behavior when
* looking for different properties. For example, in general, if a namespace is not
* provided, we might look it up via other means: different documented environment
* variables or from a kubernetes client itself. Using this constructor might not
* reflect that.
*/
@Deprecated
public KubernetesClientConfigMapPropertySourceLocator(CoreV1Api coreV1Api, ConfigMapConfigProperties properties,
KubernetesClientProperties kubernetesClientProperties) {
super(properties);
this.coreV1Api = coreV1Api;
this.kubernetesClientProperties = kubernetesClientProperties;
this.kubernetesNamespaceProvider = null;
}
public KubernetesClientConfigMapPropertySourceLocator(CoreV1Api coreV1Api, ConfigMapConfigProperties properties,
KubernetesNamespaceProvider kubernetesNamespaceProvider) {
super(properties);
this.coreV1Api = coreV1Api;
this.kubernetesNamespaceProvider = kubernetesNamespaceProvider;
this.kubernetesClientProperties = null;
}
@Override
@@ -74,15 +53,6 @@ public class KubernetesClientConfigMapPropertySourceLocator extends ConfigMapPro
if (StringUtils.hasText(normalizedNamespace)) {
namespace = normalizedNamespace;
}
else if (kubernetesClientProperties != null) {
if (StringUtils.hasText(kubernetesClientProperties.getNamespace())) {
namespace = kubernetesClientProperties.getNamespace();
}
else {
throw new NamespaceResolutionFailedException(
"could not resolve namespace in normalized source or KubernetesClientProperties");
}
}
else {
namespace = KubernetesClientConfigUtils.getApplicationNamespace(normalizedNamespace, "Config Map",
kubernetesNamespaceProvider);

View File

@@ -19,11 +19,8 @@ package org.springframework.cloud.kubernetes.client.config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.config.ConfigMapConfigProperties;
import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException;
import org.springframework.cloud.kubernetes.commons.config.SecretsConfigProperties;
import org.springframework.util.StringUtils;
/**
@@ -36,42 +33,6 @@ public final class KubernetesClientConfigUtils {
private KubernetesClientConfigUtils() {
}
@Deprecated
public static String getNamespace(ConfigMapConfigProperties.NormalizedSource normalizedSource,
KubernetesClientProperties kubernetesClientProperties) {
if (!StringUtils.hasText(normalizedSource.getNamespace())) {
return kubernetesClientProperties.getNamespace();
}
else {
return normalizedSource.getNamespace();
}
}
@Deprecated
public static String getNamespace(SecretsConfigProperties.NormalizedSource normalizedSource,
KubernetesClientProperties kubernetesClientProperties) {
if (!StringUtils.hasText(normalizedSource.getNamespace())) {
return kubernetesClientProperties.getNamespace();
}
else {
return normalizedSource.getNamespace();
}
}
@Deprecated
public static String getNamespace(ConfigMapConfigProperties.NormalizedSource normalizedSource,
String fallbackNamespace) {
String normalizedNamespace = normalizedSource.getNamespace();
return StringUtils.hasText(normalizedNamespace) ? normalizedNamespace : fallbackNamespace;
}
@Deprecated
public static String getNamespace(SecretsConfigProperties.NormalizedSource normalizedSource,
String fallbackNamespace) {
String normalizedNamespace = normalizedSource.getNamespace();
return StringUtils.hasText(normalizedNamespace) ? normalizedNamespace : fallbackNamespace;
}
/**
* this method does the namespace resolution for both config map and secrets
* implementations. It tries these places to find the namespace:

View File

@@ -18,9 +18,7 @@ package org.springframework.cloud.kubernetes.client.config;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException;
import org.springframework.cloud.kubernetes.commons.config.SecretsConfigProperties;
import org.springframework.cloud.kubernetes.commons.config.SecretsPropertySourceLocator;
import org.springframework.core.env.ConfigurableEnvironment;
@@ -37,32 +35,13 @@ public class KubernetesClientSecretsPropertySourceLocator extends SecretsPropert
private final CoreV1Api coreV1Api;
private final KubernetesClientProperties kubernetesClientProperties;
private final KubernetesNamespaceProvider kubernetesNamespaceProvider;
/**
* This constructor is deprecated. Its usage might cause unexpected behavior when
* looking for different properties. For example, in general, if a namespace is not
* provided, we might look it up via other means: different documented environment
* variables or from a kubernetes client itself. Using this constructor might not
* reflect that.
*/
@Deprecated
public KubernetesClientSecretsPropertySourceLocator(CoreV1Api coreV1Api,
KubernetesClientProperties kubernetesClientProperties, SecretsConfigProperties secretsConfigProperties) {
super(secretsConfigProperties);
this.coreV1Api = coreV1Api;
this.kubernetesClientProperties = kubernetesClientProperties;
this.kubernetesNamespaceProvider = null;
}
public KubernetesClientSecretsPropertySourceLocator(CoreV1Api coreV1Api,
KubernetesNamespaceProvider kubernetesNamespaceProvider, SecretsConfigProperties secretsConfigProperties) {
super(secretsConfigProperties);
this.coreV1Api = coreV1Api;
this.kubernetesNamespaceProvider = kubernetesNamespaceProvider;
this.kubernetesClientProperties = null;
}
@Override
@@ -76,15 +55,6 @@ public class KubernetesClientSecretsPropertySourceLocator extends SecretsPropert
if (StringUtils.hasText(normalizedNamespace)) {
namespace = normalizedNamespace;
}
else if (kubernetesClientProperties != null) {
if (StringUtils.hasText(kubernetesClientProperties.getNamespace())) {
namespace = kubernetesClientProperties.getNamespace();
}
else {
throw new NamespaceResolutionFailedException(
"could not resolve namespace in normalized source or KubernetesClientProperties");
}
}
else {
namespace = KubernetesClientConfigUtils.getApplicationNamespace(normalizedNamespace, "Secret",
kubernetesNamespaceProvider);

View File

@@ -56,18 +56,6 @@ public class KubernetesClientEventBasedConfigMapChangeDetector extends Configura
private KubernetesNamespaceProvider kubernetesNamespaceProvider;
@Deprecated
public KubernetesClientEventBasedConfigMapChangeDetector(CoreV1Api coreV1Api, ConfigurableEnvironment environment,
ConfigReloadProperties properties, ConfigurationUpdateStrategy strategy,
KubernetesClientConfigMapPropertySourceLocator propertySourceLocator,
KubernetesClientProperties kubernetesClientProperties) {
super(environment, properties, strategy);
this.propertySourceLocator = propertySourceLocator;
this.coreV1Api = coreV1Api;
this.factory = new SharedInformerFactory(createApiClientForInformerClient());
this.kubernetesClientProperties = kubernetesClientProperties;
}
public KubernetesClientEventBasedConfigMapChangeDetector(CoreV1Api coreV1Api, ConfigurableEnvironment environment,
ConfigReloadProperties properties, ConfigurationUpdateStrategy strategy,
KubernetesClientConfigMapPropertySourceLocator propertySourceLocator,
@@ -86,17 +74,6 @@ public class KubernetesClientEventBasedConfigMapChangeDetector extends Configura
this.kubernetesNamespaceProvider = kubernetesNamespaceProvider;
}
@Deprecated
public KubernetesClientEventBasedConfigMapChangeDetector(ConfigurableEnvironment environment,
ConfigReloadProperties properties, ConfigurationUpdateStrategy strategy,
KubernetesClientConfigMapPropertySourceLocator propertySourceLocator,
KubernetesClientProperties kubernetesClientProperties) {
super(environment, properties, strategy);
this.propertySourceLocator = propertySourceLocator;
this.kubernetesClientProperties = kubernetesClientProperties;
this.factory = new SharedInformerFactory(createApiClientForInformerClient());
}
private String getNamespace() {
return kubernetesNamespaceProvider != null ? kubernetesNamespaceProvider.getNamespace()
: kubernetesClientProperties.getNamespace();

View File

@@ -55,18 +55,6 @@ public class KubernetesClientEventBasedSecretsChangeDetector extends Configurati
private KubernetesNamespaceProvider kubernetesNamespaceProvider;
@Deprecated
public KubernetesClientEventBasedSecretsChangeDetector(CoreV1Api coreV1Api, ConfigurableEnvironment environment,
ConfigReloadProperties properties, ConfigurationUpdateStrategy strategy,
KubernetesClientSecretsPropertySourceLocator propertySourceLocator,
KubernetesClientProperties kubernetesClientProperties) {
super(environment, properties, strategy);
this.propertySourceLocator = propertySourceLocator;
this.factory = new SharedInformerFactory(createApiClientForInformerClient());
this.coreV1Api = coreV1Api;
this.kubernetesClientProperties = kubernetesClientProperties;
}
public KubernetesClientEventBasedSecretsChangeDetector(CoreV1Api coreV1Api, ConfigurableEnvironment environment,
ConfigReloadProperties properties, ConfigurationUpdateStrategy strategy,
KubernetesClientSecretsPropertySourceLocator propertySourceLocator,
@@ -74,10 +62,10 @@ public class KubernetesClientEventBasedSecretsChangeDetector extends Configurati
super(environment, properties, strategy);
this.propertySourceLocator = propertySourceLocator;
// We need to pass an APIClient to the SharedInformerFactory because if we use the
// default
// constructor it will use the configured default APIClient but that may not
// contain
// an APIClient configured within the cluster and does not contain the necessary
// default constructor it will use the configured default APIClient but that may
// not
// contain an APIClient configured within the cluster and does not contain the
// necessary
// certificate authorities for the cluster. This results in SSL errors.
// See https://github.com/spring-cloud/spring-cloud-kubernetes/issues/885
this.factory = new SharedInformerFactory(createApiClientForInformerClient());
@@ -85,17 +73,6 @@ public class KubernetesClientEventBasedSecretsChangeDetector extends Configurati
this.kubernetesNamespaceProvider = kubernetesNamespaceProvider;
}
@Deprecated
public KubernetesClientEventBasedSecretsChangeDetector(ConfigurableEnvironment environment,
ConfigReloadProperties properties, ConfigurationUpdateStrategy strategy,
KubernetesClientSecretsPropertySourceLocator propertySourceLocator,
KubernetesClientProperties kubernetesClientProperties) {
super(environment, properties, strategy);
this.propertySourceLocator = propertySourceLocator;
this.factory = new SharedInformerFactory(createApiClientForInformerClient());
this.kubernetesClientProperties = kubernetesClientProperties;
}
private String getNamespace() {
return kubernetesNamespaceProvider != null ? kubernetesNamespaceProvider.getNamespace()
: kubernetesClientProperties.getNamespace();

View File

@@ -98,10 +98,10 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties();
configMapConfigProperties.setName("bootstrap-640");
KubernetesClientProperties kubernetesClientProperties = new KubernetesClientProperties();
kubernetesClientProperties.setNamespace("default");
MockEnvironment mockEnvironment = new MockEnvironment();
mockEnvironment.setProperty("spring.cloud.kubernetes.client.namespace", "default");
PropertySource<?> propertySource = new KubernetesClientConfigMapPropertySourceLocator(api,
configMapConfigProperties, kubernetesClientProperties).locate(ENV);
configMapConfigProperties, new KubernetesNamespaceProvider(mockEnvironment)).locate(ENV);
assertThat(propertySource.containsProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
.isTrue();
}
@@ -121,21 +121,20 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
KubernetesClientProperties kubernetesClientProperties = new KubernetesClientProperties();
kubernetesClientProperties.setNamespace("dev");
PropertySource<?> propertySource = new KubernetesClientConfigMapPropertySourceLocator(api,
configMapConfigProperties, kubernetesClientProperties).locate(ENV);
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment())).locate(ENV);
assertThat(propertySource.containsProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
.isTrue();
}
/**
* <pre>
* 1. using the deprecated constructor, and
* 2. not providing the namespace
* 1. not providing the namespace
* </pre>
*
* will result in an Exception
*/
@Test
void testLocateWithoutNamespaceDeprecatedConstructor() {
void testLocateWithoutNamespaceConstructor() {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
@@ -144,13 +143,13 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
KubernetesClientProperties kubernetesClientProperties = new KubernetesClientProperties();
kubernetesClientProperties.setNamespace(""); // empty on purpose
assertThatThrownBy(() -> new KubernetesClientConfigMapPropertySourceLocator(api, configMapConfigProperties,
kubernetesClientProperties).locate(ENV)).isInstanceOf(NamespaceResolutionFailedException.class);
new KubernetesNamespaceProvider(new MockEnvironment())).locate(ENV))
.isInstanceOf(NamespaceResolutionFailedException.class);
}
/**
* <pre>
* 1. using the non-deprecated constructor, and
* 2. not providing the namespace
* 1. not providing the namespace
* </pre>
*
* will result in an Exception

View File

@@ -145,24 +145,12 @@ class KubernetesClientConfigMapPropertySourceTests {
.isEqualTo("TRACE");
}
@Test
void deprecatedConstructorWithoutNamespaceMustFail() {
assertThatThrownBy(() -> new KubernetesClientConfigMapPropertySource(new CoreV1Api(), "configmap", null,
new MockEnvironment())).isInstanceOf(NamespaceResolutionFailedException.class);
}
@Test
void constructorWithoutNamespaceMustFail() {
assertThatThrownBy(() -> new KubernetesClientConfigMapPropertySource(new CoreV1Api(), "configmap", null,
new MockEnvironment(), "", false, false)).isInstanceOf(NamespaceResolutionFailedException.class);
}
@Test
void deprecatedConstructorWithNamespaceMustNotFail() {
assertThat(new KubernetesClientConfigMapPropertySource(new CoreV1Api(), "configmap", "namespace",
new MockEnvironment())).isNotNull();
}
@Test
void constructorWithNamespaceMustNotFail() {
assertThat(new KubernetesClientConfigMapPropertySource(new CoreV1Api(), "configmap", "namespace",

View File

@@ -30,7 +30,6 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException;
import org.springframework.cloud.kubernetes.commons.config.SecretsConfigProperties;
@@ -121,7 +120,7 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
secretsConfigProperties.setSources(sources);
secretsConfigProperties.setEnableApi(true);
PropertySource<?> propertySource = new KubernetesClientSecretsPropertySourceLocator(api,
new KubernetesClientProperties(), secretsConfigProperties).locate(ENV);
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties).locate(ENV);
assertThat(propertySource.containsProperty("password")).isTrue();
assertThat(propertySource.getProperty("password")).isEqualTo("p455w0rd");
}
@@ -135,29 +134,29 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
secretsConfigProperties.setNamespace("default");
secretsConfigProperties.setEnableApi(true);
PropertySource<?> propertySource = new KubernetesClientSecretsPropertySourceLocator(api,
new KubernetesClientProperties(), secretsConfigProperties).locate(ENV);
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties).locate(ENV);
assertThat(propertySource.containsProperty("password")).isTrue();
assertThat(propertySource.getProperty("password")).isEqualTo("p455w0rd");
}
/**
* <pre>
* 1. using the deprecated constructor, and
* 2. not providing the namespace
* 1. not providing the namespace
* </pre>
*
* will result in an Exception
*/
@Test
void testLocateWithoutNamespaceDeprecatedConstructor() {
void testLocateWithoutNamespaceConstructor() {
CoreV1Api api = new CoreV1Api();
stubFor(get(LIST_API).willReturn(aResponse().withStatus(200).withBody(LIST_BODY)));
SecretsConfigProperties secretsConfigProperties = new SecretsConfigProperties();
secretsConfigProperties.setName("db-secret");
secretsConfigProperties.setNamespace(""); // empty on purpose
secretsConfigProperties.setEnableApi(true);
assertThatThrownBy(() -> new KubernetesClientSecretsPropertySourceLocator(api, new KubernetesClientProperties(),
secretsConfigProperties).locate(ENV)).isInstanceOf(NamespaceResolutionFailedException.class);
assertThatThrownBy(() -> new KubernetesClientSecretsPropertySourceLocator(api,
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties).locate(ENV))
.isInstanceOf(NamespaceResolutionFailedException.class);
}
@Test

View File

@@ -61,8 +61,6 @@ class KubernetesClientSecretsPropertySourceTests {
.withNamespace("default").build())
.addToData("password", "p455w0rd".getBytes()).addToData("username", "user".getBytes()).build()).build();
private static final String LIST_API = "/api/v1/secrets";
private static final String LIST_API_WITH_LABEL = "/api/v1/namespaces/default/secrets?labelSelector=spring.cloud.kubernetes.secret%3Dtrue";
private static final String LIST_BODY = "{\n" + "\t\"kind\": \"SecretList\",\n" + "\t\"apiVersion\": \"v1\",\n"
@@ -104,6 +102,7 @@ class KubernetesClientSecretsPropertySourceTests {
@AfterAll
static void after() {
WireMock.shutdownServer();
wireMockServer.stop();
}

View File

@@ -185,14 +185,6 @@ public class ConfigMapConfigProperties extends AbstractConfigProperties {
return !StringUtils.hasLength(this.name) && !StringUtils.hasLength(this.namespace);
}
// not used, but not removed because of potential compatibility reasons
@Deprecated
public NormalizedSource normalize(String defaultName, String defaultNamespace) {
String normalizedName = StringUtils.hasLength(this.name) ? this.name : defaultName;
String normalizedNamespace = StringUtils.hasLength(this.namespace) ? this.namespace : defaultNamespace;
return new NormalizedSource(normalizedName, normalizedNamespace, "", true);
}
public NormalizedSource normalize(String defaultName, String defaultNamespace, boolean defaultUseNameAsPrefix,
boolean defaultIncludeProfileSpecificSources) {
String normalizedName = StringUtils.hasLength(this.name) ? this.name : defaultName;
@@ -233,15 +225,6 @@ public class ConfigMapConfigProperties extends AbstractConfigProperties {
private final boolean includeProfileSpecificSources;
// not used, but not removed because of potential compatibility reasons
@Deprecated
NormalizedSource(String name, String namespace) {
this.name = name;
this.namespace = namespace;
this.prefix = "";
this.includeProfileSpecificSources = true;
}
NormalizedSource(String name, String namespace, String prefix, boolean includeProfileSpecificSources) {
this.name = name;
this.namespace = namespace;

View File

@@ -23,7 +23,6 @@ import jakarta.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.task.TaskSchedulerBuilder;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.MapPropertySource;
@@ -50,16 +49,6 @@ public class PollingConfigMapChangeDetector extends ConfigurationChangeDetector
private Duration period = Duration.ofMillis(1500);
@Deprecated
public PollingConfigMapChangeDetector(AbstractEnvironment environment, ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy, Class propertySourceClass,
PropertySourceLocator propertySourceLocator) {
super(environment, properties, strategy);
this.propertySourceLocator = propertySourceLocator;
this.propertySourceClass = propertySourceClass;
this.taskExecutor = new TaskSchedulerBuilder().build();
}
public PollingConfigMapChangeDetector(AbstractEnvironment environment, ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy, Class propertySourceClass,
PropertySourceLocator propertySourceLocator, TaskScheduler taskExecutor) {

View File

@@ -23,7 +23,6 @@ import jakarta.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.task.TaskSchedulerBuilder;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.MapPropertySource;
@@ -50,16 +49,6 @@ public class PollingSecretsChangeDetector extends ConfigurationChangeDetector {
private Duration period = Duration.ofMillis(1500);
@Deprecated
public PollingSecretsChangeDetector(AbstractEnvironment environment, ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy, Class propertySourceClass,
PropertySourceLocator propertySourceLocator) {
super(environment, properties, strategy);
this.propertySourceClass = propertySourceClass;
this.propertySourceLocator = propertySourceLocator;
this.taskExecutor = new TaskSchedulerBuilder().build();
}
public PollingSecretsChangeDetector(AbstractEnvironment environment, ConfigReloadProperties properties,
ConfigurationUpdateStrategy strategy, Class propertySourceClass,
PropertySourceLocator propertySourceLocator, TaskScheduler taskExecutor) {

View File

@@ -44,26 +44,6 @@ public class Fabric8ConfigMapPropertySource extends ConfigMapPropertySource {
private static final Log LOG = LogFactory.getLog(Fabric8ConfigMapPropertySource.class);
/**
* this constructor is present only for compatibility reasons, its usage is
* discouraged.
*/
@Deprecated
public Fabric8ConfigMapPropertySource(KubernetesClient client, String name) {
this(client, name, null, null, "", true, false);
}
/**
* this constructor is present only for compatibility reasons, its usage is
* discouraged.
*/
@Deprecated
public Fabric8ConfigMapPropertySource(KubernetesClient client, String name, String namespace,
Environment environment) {
super(getName(name, getApplicationNamespace(client, namespace, "Config Map", null)), getData(client, name,
getApplicationNamespace(client, namespace, "Config Map", null), environment, "", true, false));
}
public Fabric8ConfigMapPropertySource(KubernetesClient client, String name, String namespace,
Environment environment, String prefix, boolean includeProfileSpecificSources, boolean failFast) {
super(getName(name, getApplicationNamespace(client, namespace, "Config Map", null)),

View File

@@ -43,20 +43,6 @@ public class Fabric8ConfigMapPropertySourceLocator extends ConfigMapPropertySour
private final KubernetesNamespaceProvider provider;
/**
* This constructor is deprecated. Its usage might cause unexpected behavior when
* looking for different properties. For example, in general, if a namespace is not
* provided, we might look it up via other means: different documented environment
* variables or from a kubernetes client itself. Using this constructor might not
* reflect that.
*/
@Deprecated
public Fabric8ConfigMapPropertySourceLocator(KubernetesClient client, ConfigMapConfigProperties properties) {
super(properties);
this.client = client;
this.provider = null;
}
public Fabric8ConfigMapPropertySourceLocator(KubernetesClient client, ConfigMapConfigProperties properties,
KubernetesNamespaceProvider provider) {
super(properties);

View File

@@ -40,29 +40,6 @@ public final class Fabric8ConfigUtils {
private Fabric8ConfigUtils() {
}
/*
* this is not used, it is here for compatibility reasons only.
*/
@Deprecated
public static String getApplicationNamespace(KubernetesClient client, String namespace,
String configurationTarget) {
if (!StringUtils.hasLength(namespace)) {
LOG.debug(configurationTarget + " namespace has not been set, taking it from client (ns="
+ client.getNamespace() + ")");
namespace = client.getNamespace();
}
return namespace;
}
/*
* this is not used, it is here for compatibility reasons only.
*/
@Deprecated
public static String getApplicationNamespace(KubernetesClient client, String namespace) {
return !StringUtils.hasLength(namespace) ? client.getNamespace() : namespace;
}
/**
* this method does the namespace resolution for both config map and secrets
* implementations. It tries these places to find the namespace:

View File

@@ -45,20 +45,6 @@ public class Fabric8SecretsPropertySourceLocator extends SecretsPropertySourceLo
private final KubernetesNamespaceProvider provider;
/**
* This constructor is deprecated. Its usage might cause unexpected behavior when
* looking for different properties. For example, in general, if a namespace is not
* provided, we might look it up via other means: different documented environment
* variables or from a kubernetes client itself. Using this constructor might not
* reflect that.
*/
@Deprecated
public Fabric8SecretsPropertySourceLocator(KubernetesClient client, SecretsConfigProperties properties) {
super(properties);
this.client = client;
this.provider = null;
}
public Fabric8SecretsPropertySourceLocator(KubernetesClient client, SecretsConfigProperties properties,
KubernetesNamespaceProvider provider) {
super(properties);

View File

@@ -25,6 +25,8 @@ import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import org.junit.jupiter.api.Test;
import org.springframework.mock.env.MockEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
/**
@@ -72,7 +74,8 @@ public class ConfigMapsTest {
mockClient.configMaps().inNamespace("test").create(configMap);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName, "test",
new MockEnvironment(), "", false, false);
assertThat(cmps.getProperty("dummy.property.string1")).isEqualTo("a");
assertThat(cmps.getProperty("dummy.property.int1")).isEqualTo("1");
@@ -87,7 +90,8 @@ public class ConfigMapsTest {
mockClient.configMaps().inNamespace("test").create(configMap);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName, "test",
new MockEnvironment(), "", false, false);
assertThat(cmps.getProperty("dummy.property.string2")).isEqualTo("a");
assertThat(cmps.getProperty("dummy.property.int2")).isEqualTo(1);
@@ -102,7 +106,8 @@ public class ConfigMapsTest {
mockClient.configMaps().inNamespace("test").create(configMap);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName, "test",
new MockEnvironment(), "", false, false);
assertThat(cmps.getProperty("dummy.property.string3")).isEqualTo("a");
assertThat(cmps.getProperty("dummy.property.int3")).isEqualTo(1);
@@ -117,7 +122,8 @@ public class ConfigMapsTest {
mockClient.configMaps().inNamespace("test").create(configMap);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName, "namespace",
new MockEnvironment(), "", false, false);
// no exception is thrown for unparseable content
}
@@ -130,7 +136,8 @@ public class ConfigMapsTest {
mockClient.configMaps().inNamespace("test").create(configMap);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName, "namespace",
new MockEnvironment(), "", false, false);
// no exception is thrown for unparseable content
}
@@ -144,7 +151,8 @@ public class ConfigMapsTest {
mockClient.configMaps().inNamespace("test").create(configMap);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName);
Fabric8ConfigMapPropertySource cmps = new Fabric8ConfigMapPropertySource(mockClient, configMapName, "test",
new MockEnvironment(), "", true, false);
// application.properties should be read correctly
assertThat(cmps.getProperty("dummy.property.string1")).isEqualTo("a");

View File

@@ -65,65 +65,29 @@ class Fabric8ConfigMapPropertySourceTests {
new MockEnvironment(), "", false, false));
}
@Test
void deprecatedConstructorWithoutClientNamespaceMustFail() {
Mockito.when(client.getNamespace()).thenReturn(null);
assertThatThrownBy(() -> new Fabric8ConfigMapPropertySource(client, "configmap"))
.isInstanceOf(NamespaceResolutionFailedException.class);
}
@Test
void deprecatedConstructorWithClientNamespaceMustNotFail() {
Mockito.when(client.getNamespace()).thenReturn("some");
assertThat(new Fabric8ConfigMapPropertySource(client, "configmap")).isNotNull();
}
@Test
void anotherDeprecatedConstructorWithoutClientNamespaceMustFail() {
Mockito.when(client.getNamespace()).thenReturn(null);
assertThatThrownBy(() -> new Fabric8ConfigMapPropertySource(client, "configmap", null, new MockEnvironment()))
.isInstanceOf(NamespaceResolutionFailedException.class);
}
@Test
void anotherDeprecatedConstructorWithClientNamespaceMustNotFail() {
Mockito.when(client.getNamespace()).thenReturn("some-namespace");
assertThat(new Fabric8ConfigMapPropertySource(client, "configmap", null, new MockEnvironment())).isNotNull();
}
@Test
void anotherDeprecatedConstructorWithNamespaceMustNotFail() {
Mockito.when(client.getNamespace()).thenReturn(null);
assertThat(new Fabric8ConfigMapPropertySource(client, "configmap", "namespace", new MockEnvironment()))
.isNotNull();
}
@Test
void constructorWithoutClientNamespaceMustFail() {
Mockito.when(client.getNamespace()).thenReturn(null);
assertThatThrownBy(() -> new Fabric8ConfigMapPropertySource(client, "configmap", null, new MockEnvironment()))
.isInstanceOf(NamespaceResolutionFailedException.class);
assertThatThrownBy(() -> new Fabric8ConfigMapPropertySource(client, "configmap", null, new MockEnvironment(),
"", false, false)).isInstanceOf(NamespaceResolutionFailedException.class);
}
@Test
void constructorWithClientNamespaceMustNotFail() {
Mockito.when(client.getNamespace()).thenReturn("namespace");
assertThat(new Fabric8ConfigMapPropertySource(client, "configmap", null, new MockEnvironment())).isNotNull();
assertThat(
new Fabric8ConfigMapPropertySource(client, "configmap", null, new MockEnvironment(), "", false, false))
.isNotNull();
}
@Test
void constructorWithNamespaceMustNotFail() {
Mockito.when(client.getNamespace()).thenReturn(null);
assertThat(new Fabric8ConfigMapPropertySource(client, "configmap", "namespace", new MockEnvironment()))
.isNotNull();
assertThat(new Fabric8ConfigMapPropertySource(client, "configmap", "namespace", new MockEnvironment(), "",
false, false)).isNotNull();
}
}

View File

@@ -42,13 +42,13 @@ public class Fabric8ConfigUtilsTests {
@Test
public void testGetApplicationNamespaceNotPresent() {
String result = Fabric8ConfigUtils.getApplicationNamespace(client, "", "target");
String result = Fabric8ConfigUtils.getApplicationNamespace(client, "", "target", null);
assertThat(result).isEqualTo("test");
}
@Test
public void testGetApplicationNamespacePresent() {
String result = Fabric8ConfigUtils.getApplicationNamespace(client, "namespace", "target");
String result = Fabric8ConfigUtils.getApplicationNamespace(client, "namespace", "target", null);
assertThat(result).isEqualTo("namespace");
}

View File

@@ -64,7 +64,7 @@ public class EventBasedConfigurationChangeDetectorTests {
when(k8sClient.getNamespace()).thenReturn("default");
Fabric8ConfigMapPropertySource fabric8ConfigMapPropertySource = new Fabric8ConfigMapPropertySource(k8sClient,
"myconfigmap");
"myconfigmap", "default", new MockEnvironment(), "", true, false);
env.getPropertySources().addFirst(new BootstrapPropertySource<>(fabric8ConfigMapPropertySource));
ConfigurationUpdateStrategy configurationUpdateStrategy = mock(ConfigurationUpdateStrategy.class);