Fixing merge
This commit is contained in:
@@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.config.ConditionalOnKubernetesConfigOrSecretsRetryEnabled;
|
||||
@@ -40,7 +39,6 @@ import org.springframework.context.annotation.Import;
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@AutoConfigureAfter(KubernetesBootstrapConfiguration.class)
|
||||
@AutoConfigureBefore(KubernetesClientBootstrapConfiguration.class)
|
||||
@Import({ KubernetesCommonsAutoConfiguration.class, KubernetesClientAutoConfiguration.class })
|
||||
|
||||
@@ -31,7 +31,8 @@ import org.springframework.retry.annotation.Retryable;
|
||||
*
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
class RetryableKubernetesClientConfigMapPropertySourceLocator extends KubernetesClientConfigMapPropertySourceLocator {
|
||||
public class RetryableKubernetesClientConfigMapPropertySourceLocator
|
||||
extends KubernetesClientConfigMapPropertySourceLocator {
|
||||
|
||||
RetryableKubernetesClientConfigMapPropertySourceLocator(CoreV1Api coreV1Api, ConfigMapConfigProperties properties,
|
||||
KubernetesNamespaceProvider kubernetesNamespaceProvider) {
|
||||
|
||||
@@ -31,7 +31,8 @@ import org.springframework.retry.annotation.Retryable;
|
||||
*
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
class RetryableKubernetesClientSecretsPropertySourceLocator extends KubernetesClientSecretsPropertySourceLocator {
|
||||
public class RetryableKubernetesClientSecretsPropertySourceLocator
|
||||
extends KubernetesClientSecretsPropertySourceLocator {
|
||||
|
||||
RetryableKubernetesClientSecretsPropertySourceLocator(CoreV1Api coreV1Api,
|
||||
KubernetesNamespaceProvider kubernetesNamespaceProvider, SecretsConfigProperties secretsConfigProperties) {
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.config.configmap_retry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.openapi.models.V1ConfigMapList;
|
||||
import io.kubernetes.client.openapi.models.V1SecretList;
|
||||
import io.kubernetes.client.util.ClientBuilder;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
|
||||
import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration;
|
||||
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
|
||||
import org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.client.KubernetesClientUtils;
|
||||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientBootstrapConfiguration;
|
||||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientRetryBootstrapConfiguration;
|
||||
import org.springframework.cloud.kubernetes.client.config.reload.KubernetesClientConfigReloadAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.config.KubernetesBootstrapConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadAutoConfiguration;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.retry.annotation.RetryConfiguration;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.get;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
|
||||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
public class ConfigMapEnableRetryWithoutFailFastTest {
|
||||
|
||||
private static final String API = "/api/v1/namespaces/default/configmaps";
|
||||
|
||||
private static final String SECRETS_API = "/api/v1/namespaces/default/secrets";
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
private static WireMockServer wireMockServer;
|
||||
|
||||
private static MockedStatic<KubernetesClientUtils> clientUtilsMock;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
wireMockServer = new WireMockServer(options().dynamicPort());
|
||||
wireMockServer.start();
|
||||
WireMock.configureFor(wireMockServer.port());
|
||||
|
||||
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
|
||||
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
|
||||
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
|
||||
stubConfigMapAndSecretsDefaults();
|
||||
}
|
||||
|
||||
private static void stubConfigMapAndSecretsDefaults() {
|
||||
// return empty config map / secret list to not fail context creation
|
||||
stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList()))));
|
||||
stubFor(get(SECRETS_API)
|
||||
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1SecretList()))));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void teardown() {
|
||||
wireMockServer.stop();
|
||||
clientUtilsMock.close();
|
||||
}
|
||||
|
||||
protected void setup(String... env) {
|
||||
List<String> envList = (env != null) ? new ArrayList<>(Arrays.asList(env)) : new ArrayList<>();
|
||||
envList.add("spring.cloud.kubernetes.client.namespace=default");
|
||||
String[] envArray = envList.toArray(new String[0]);
|
||||
|
||||
context = new SpringApplicationBuilder(RetryConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
ConfigReloadAutoConfiguration.class, RefreshAutoConfiguration.class, EndpointAutoConfiguration.class,
|
||||
InfoEndpointAutoConfiguration.class, RefreshEndpointAutoConfiguration.class,
|
||||
ConfigurationPropertiesBindingPostProcessor.class,
|
||||
ConfigurationPropertiesRebinderAutoConfiguration.class, KubernetesClientBootstrapConfiguration.class,
|
||||
KubernetesClientRetryBootstrapConfiguration.class, KubernetesBootstrapConfiguration.class,
|
||||
KubernetesClientConfigReloadAutoConfiguration.class)
|
||||
.web(org.springframework.boot.WebApplicationType.NONE).properties(envArray).run();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void afterEach() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
this.context = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotContainRetryableConfigMapPropertySourceLocator() throws Exception {
|
||||
stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
|
||||
setup("debug=true", "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.test.enable-retry=true");
|
||||
assertThat(context.containsBean("retryableConfigMapPropertySourceLocator")).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ import org.mockito.MockedStatic;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.cloud.kubernetes.client.KubernetesClientUtils;
|
||||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySourceLocator;
|
||||
import org.springframework.cloud.kubernetes.client.config.RetryableKubernetesClientConfigMapPropertySourceLocator;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
@@ -98,7 +98,7 @@ class ConfigRetryEnabled {
|
||||
}
|
||||
|
||||
@SpyBean
|
||||
private KubernetesClientConfigMapPropertySourceLocator propertySourceLocator;
|
||||
private RetryableKubernetesClientConfigMapPropertySourceLocator propertySourceLocator;
|
||||
|
||||
@Test
|
||||
void locateShouldNotRetryWhenThereIsNoFailure() {
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.config.secrets_retry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.openapi.models.V1ConfigMapList;
|
||||
import io.kubernetes.client.openapi.models.V1SecretList;
|
||||
import io.kubernetes.client.util.ClientBuilder;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
|
||||
import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration;
|
||||
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
|
||||
import org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.client.KubernetesClientUtils;
|
||||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientBootstrapConfiguration;
|
||||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientRetryBootstrapConfiguration;
|
||||
import org.springframework.cloud.kubernetes.client.config.reload.KubernetesClientConfigReloadAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.config.KubernetesBootstrapConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadAutoConfiguration;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.retry.annotation.RetryConfiguration;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.get;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
|
||||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
public class SecretsEnableRetryWithoutFailFastTest {
|
||||
|
||||
private static final String API = "/api/v1/namespaces/default/configmaps";
|
||||
|
||||
private static final String SECRETS_API = "/api/v1/namespaces/default/secrets";
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
private static WireMockServer wireMockServer;
|
||||
|
||||
private static MockedStatic<KubernetesClientUtils> clientUtilsMock;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
wireMockServer = new WireMockServer(options().dynamicPort());
|
||||
wireMockServer.start();
|
||||
WireMock.configureFor(wireMockServer.port());
|
||||
|
||||
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
|
||||
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
|
||||
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
|
||||
stubConfigMapAndSecretsDefaults();
|
||||
}
|
||||
|
||||
private static void stubConfigMapAndSecretsDefaults() {
|
||||
// return empty config map / secret list to not fail context creation
|
||||
stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList()))));
|
||||
stubFor(get(SECRETS_API)
|
||||
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1SecretList()))));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void teardown() {
|
||||
wireMockServer.stop();
|
||||
clientUtilsMock.close();
|
||||
}
|
||||
|
||||
protected void setup(String... env) {
|
||||
List<String> envList = (env != null) ? new ArrayList<>(Arrays.asList(env)) : new ArrayList<>();
|
||||
envList.add("spring.cloud.kubernetes.client.namespace=default");
|
||||
String[] envArray = envList.toArray(new String[0]);
|
||||
|
||||
context = new SpringApplicationBuilder(RetryConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
ConfigReloadAutoConfiguration.class, RefreshAutoConfiguration.class, EndpointAutoConfiguration.class,
|
||||
InfoEndpointAutoConfiguration.class, RefreshEndpointAutoConfiguration.class,
|
||||
ConfigurationPropertiesBindingPostProcessor.class,
|
||||
ConfigurationPropertiesRebinderAutoConfiguration.class, KubernetesClientBootstrapConfiguration.class,
|
||||
KubernetesClientRetryBootstrapConfiguration.class, KubernetesBootstrapConfiguration.class,
|
||||
KubernetesClientConfigReloadAutoConfiguration.class)
|
||||
.web(org.springframework.boot.WebApplicationType.NONE).properties(envArray).run();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void afterEach() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
this.context = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotContainRetryableSecretsPropertySourceLocator() throws Exception {
|
||||
stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
|
||||
setup("debug=true", "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.test.enable-retry=true",
|
||||
"spring.cloud.kubernetes.secrets.name=my-secret", "spring.cloud.kubernetes.secrets.enable-api=true");
|
||||
assertThat(context.containsBean("retryableSecretsPropertySourceLocator")).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ import org.mockito.MockedStatic;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.cloud.kubernetes.client.KubernetesClientUtils;
|
||||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientSecretsPropertySourceLocator;
|
||||
import org.springframework.cloud.kubernetes.client.config.RetryableKubernetesClientSecretsPropertySourceLocator;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
@@ -98,7 +98,7 @@ class SecretsRetryEnabled {
|
||||
}
|
||||
|
||||
@SpyBean
|
||||
private KubernetesClientSecretsPropertySourceLocator propertySourceLocator;
|
||||
private RetryableKubernetesClientSecretsPropertySourceLocator propertySourceLocator;
|
||||
|
||||
@Test
|
||||
void locateShouldNotRetryWhenThereIsNoFailure() {
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.config.ConditionalOnKubernetesConfigOrSecretsRetryEnabled;
|
||||
@@ -43,7 +42,6 @@ import org.springframework.context.annotation.Import;
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@AutoConfigureBefore(Fabric8BootstrapConfiguration.class)
|
||||
@Import({ KubernetesCommonsAutoConfiguration.class, Fabric8AutoConfiguration.class })
|
||||
@ConditionalOnClass({ ConfigMap.class, Secret.class })
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.fabric8.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
|
||||
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
|
||||
import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration;
|
||||
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
|
||||
import org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.config.KubernetesBootstrapConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadAutoConfiguration;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.retry.annotation.RetryConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@EnableKubernetesMockClient
|
||||
public class ConfigMapEnableRetryWithoutFailFastTest {
|
||||
|
||||
private static final String API = "/api/v1/namespaces/default/configmaps/application";
|
||||
|
||||
static KubernetesMockServer mockServer;
|
||||
|
||||
static KubernetesClient mockClient;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
protected void setup(String... env) {
|
||||
List<String> envList = (env != null) ? new ArrayList<>(Arrays.asList(env)) : new ArrayList<>();
|
||||
envList.add("spring.cloud.kubernetes.client.namespace=default");
|
||||
String[] envArray = envList.toArray(new String[0]);
|
||||
|
||||
context = new SpringApplicationBuilder(RetryConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
ConfigReloadAutoConfiguration.class, RefreshAutoConfiguration.class, EndpointAutoConfiguration.class,
|
||||
InfoEndpointAutoConfiguration.class, RefreshEndpointAutoConfiguration.class,
|
||||
ConfigurationPropertiesBindingPostProcessor.class,
|
||||
ConfigurationPropertiesRebinderAutoConfiguration.class, Fabric8BootstrapConfiguration.class,
|
||||
Fabric8RetryBootstrapConfiguration.class, KubernetesBootstrapConfiguration.class)
|
||||
.web(org.springframework.boot.WebApplicationType.NONE).properties(envArray).run();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void afterEach() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
this.context = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotContainRetryableConfigMapPropertySourceLocator() throws Exception {
|
||||
mockServer.expect().withPath(API).andReturn(500, "Internal Server Error").once();
|
||||
setup("debug=true", "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.test.enable-retry=true");
|
||||
assertThat(context.containsBean("retryableConfigMapPropertySourceLocator")).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.fabric8.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
|
||||
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
|
||||
import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration;
|
||||
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
|
||||
import org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.config.KubernetesBootstrapConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadAutoConfiguration;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.retry.annotation.RetryConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@EnableKubernetesMockClient
|
||||
public class SecretsEnableRetryWithoutFailFastTest {
|
||||
|
||||
private static final String API = "/api/v1/namespaces/default/configmaps/application";
|
||||
|
||||
static KubernetesMockServer mockServer;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
protected void setup(String... env) {
|
||||
List<String> envList = (env != null) ? new ArrayList<>(Arrays.asList(env)) : new ArrayList<>();
|
||||
envList.add("spring.cloud.kubernetes.client.namespace=default");
|
||||
String[] envArray = envList.toArray(new String[0]);
|
||||
|
||||
context = new SpringApplicationBuilder(RetryConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
ConfigReloadAutoConfiguration.class, RefreshAutoConfiguration.class, EndpointAutoConfiguration.class,
|
||||
InfoEndpointAutoConfiguration.class, RefreshEndpointAutoConfiguration.class,
|
||||
ConfigurationPropertiesBindingPostProcessor.class,
|
||||
ConfigurationPropertiesRebinderAutoConfiguration.class, Fabric8BootstrapConfiguration.class,
|
||||
Fabric8RetryBootstrapConfiguration.class, KubernetesBootstrapConfiguration.class)
|
||||
.web(org.springframework.boot.WebApplicationType.NONE).properties(envArray).run();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void afterEach() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
this.context = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotContainRetryableSecretsPropertySourceLocator() throws Exception {
|
||||
mockServer.expect().withPath(API).andReturn(500, "Internal Server Error").once();
|
||||
setup("debug=true", "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.test.enable-retry=true",
|
||||
"spring.cloud.kubernetes.secrets.name=my-secret", "spring.cloud.kubernetes.secrets.enable-api=true");
|
||||
assertThat(context.containsBean("retryableSecretsPropertySourceLocator")).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user