Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnKubernetesHealthIndicatorEnabled
public class KubernetesClientActuatorConfiguration {
final class KubernetesClientActuatorConfiguration {

@Bean
@ConditionalOnEnabledHealthIndicator("kubernetes")
public KubernetesClientHealthIndicator kubernetesHealthIndicator(PodUtils<V1Pod> podUtils) {
KubernetesClientHealthIndicator kubernetesHealthIndicator(PodUtils<V1Pod> podUtils) {
return new KubernetesClientHealthIndicator(podUtils);
}

@Bean
@ConditionalOnEnabledInfoContributor("kubernetes")
public KubernetesClientInfoContributor kubernetesInfoContributor(PodUtils<V1Pod> podUtils) {
KubernetesClientInfoContributor kubernetesInfoContributor(PodUtils<V1Pod> podUtils) {
return new KubernetesClientInfoContributor(podUtils);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@
@Configuration(proxyBeanMethods = false)
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
@AutoConfigureAfter(KubernetesCommonsAutoConfiguration.class)
public class KubernetesClientAutoConfiguration {
public final class KubernetesClientAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public CoreV1Api coreApi(ApiClient apiClient) {
CoreV1Api coreApi(ApiClient apiClient) {
return new CoreV1Api(apiClient);
}

@Bean
@ConditionalOnMissingBean
public ApiClient apiClient(KubernetesClientProperties clientProperties) {
ApiClient apiClient(KubernetesClientProperties clientProperties) {
ApiClient apiClient = kubernetesApiClient();
apiClient.setUserAgent(clientProperties.userAgent());
return apiClient;
Expand All @@ -62,7 +62,7 @@ public KubernetesNamespaceProvider kubernetesNamespaceProvider(Environment envir

@Bean
@ConditionalOnMissingBean
public KubernetesClientPodUtils kubernetesPodUtils(CoreV1Api client,
KubernetesClientPodUtils kubernetesPodUtils(CoreV1Api client,
KubernetesNamespaceProvider kubernetesNamespaceProvider) {
return new KubernetesClientPodUtils(client, kubernetesNamespaceProvider.getNamespace(), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
/**
* @author Ryan Baxter
*/
public class KubernetesClientHealthIndicator extends AbstractKubernetesHealthIndicator {
final class KubernetesClientHealthIndicator extends AbstractKubernetesHealthIndicator {

private final PodUtils<V1Pod> utils;

public KubernetesClientHealthIndicator(PodUtils<V1Pod> utils) {
KubernetesClientHealthIndicator(PodUtils<V1Pod> utils) {
this.utils = utils;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
/**
* @author Ryan Baxter
*/
public class KubernetesClientInfoContributor extends AbstractKubernetesInfoContributor {
final class KubernetesClientInfoContributor extends AbstractKubernetesInfoContributor {

private final PodUtils<V1Pod> utils;

public KubernetesClientInfoContributor(PodUtils<V1Pod> utils) {
KubernetesClientInfoContributor(PodUtils<V1Pod> utils) {
this.utils = utils;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,7 @@
/**
* @author Ryan Baxter
*/
public class KubernetesClientPodUtils implements PodUtils<V1Pod> {

/**
* Hostname environment variable name.
*/
public static final String HOSTNAME = "HOSTNAME";

/**
* KUBERNETES_SERVICE_HOST environment variable name.
*/
public static final String KUBERNETES_SERVICE_HOST = "KUBERNETES_SERVICE_HOST";
final class KubernetesClientPodUtils implements PodUtils<V1Pod> {

private static final Log LOG = LogFactory.getLog(KubernetesClientPodUtils.class);

Expand All @@ -62,14 +52,14 @@ public class KubernetesClientPodUtils implements PodUtils<V1Pod> {

// mainly needed for the health and info contributors, so that they report DOWN
// correctly
public KubernetesClientPodUtils(CoreV1Api client, String namespace, boolean failFast) {
KubernetesClientPodUtils(CoreV1Api client, String namespace, boolean failFast) {
if (client == null) {
throw new IllegalArgumentException("Must provide an instance of KubernetesClient");
}

this.client = client;
this.hostName = EnvReader.getEnv(HOSTNAME);
this.serviceHost = EnvReader.getEnv(KUBERNETES_SERVICE_HOST);
this.hostName = EnvReader.getEnv("HOSTNAME");
this.serviceHost = EnvReader.getEnv("KUBERNETES_SERVICE_HOST");
this.current = LazilyInstantiate.using(this::internalGetPod);
this.namespace = namespace;
this.failFast = failFast;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

package org.springframework.cloud.kubernetes.client.profile;
package org.springframework.cloud.kubernetes.client;

import io.kubernetes.client.openapi.apis.CoreV1Api;

import org.springframework.cloud.kubernetes.client.KubernetesClientPodUtils;
import org.springframework.cloud.kubernetes.commons.profile.AbstractKubernetesProfileEnvironmentPostProcessor;
import org.springframework.core.env.Environment;

Expand All @@ -28,7 +27,7 @@
* @author Ryan Baxter
* @author Thomas Vitale
*/
public class KubernetesClientProfileEnvironmentPostProcessor extends AbstractKubernetesProfileEnvironmentPostProcessor {
final class KubernetesClientProfileEnvironmentPostProcessor extends AbstractKubernetesProfileEnvironmentPostProcessor {

@Override
protected boolean isInsideKubernetes(Environment environment) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
org.springframework.boot.EnvironmentPostProcessor=\
org.springframework.cloud.kubernetes.client.profile.KubernetesClientProfileEnvironmentPostProcessor
org.springframework.cloud.kubernetes.client.KubernetesClientProfileEnvironmentPostProcessor
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
import org.springframework.boot.health.registry.ReactiveHealthContributorRegistry;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.test.LocalManagementPort;
import org.springframework.cloud.kubernetes.client.example.App;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;

/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestApp.class,
properties = { "management.health.kubernetes.enabled=false", "management.endpoint.health.show-details=always",
"management.endpoint.health.show-components=always", "spring.main.cloud-platform=KUBERNETES",
"management.endpoints.web.exposure.include=health" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@
import org.springframework.boot.health.contributor.Status;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.cloud.kubernetes.client.example.App;
import org.springframework.cloud.kubernetes.commons.EnvReader;
import org.springframework.context.annotation.Bean;

/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = { App.class, ActuatorEnabledFailFastExceptionTest.ActuatorConfig.class },
classes = { TestApp.class, ActuatorEnabledFailFastExceptionTest.ActuatorConfig.class },
properties = { "management.endpoint.health.show-details=always",
"management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health",
"spring.main.cloud-platform=KUBERNETES" })
Expand Down Expand Up @@ -76,9 +75,8 @@ private static void mocks() {
envReaderMockedStatic = Mockito.mockStatic(EnvReader.class);
pathsMockedStatic = Mockito.mockStatic(Paths.class, Mockito.CALLS_REAL_METHODS);

envReaderMockedStatic.when(() -> EnvReader.getEnv(KubernetesClientPodUtils.KUBERNETES_SERVICE_HOST))
.thenReturn("k8s-host");
envReaderMockedStatic.when(() -> EnvReader.getEnv(KubernetesClientPodUtils.HOSTNAME)).thenReturn("host");
envReaderMockedStatic.when(() -> EnvReader.getEnv("KUBERNETES_SERVICE_HOST")).thenReturn("k8s-host");
envReaderMockedStatic.when(() -> EnvReader.getEnv("HOSTNAME")).thenReturn("host");

Path serviceAccountTokenPath = Mockito.mock(Path.class);
File serviceAccountTokenFile = Mockito.mock(File.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import org.springframework.boot.health.registry.HealthContributorRegistry;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.test.LocalManagementPort;
import org.springframework.cloud.kubernetes.client.example.App;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestApp.class,
properties = { "management.health.kubernetes.enabled=true", "management.endpoint.health.show-details=always",
"management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health",
"spring.main.cloud-platform=KUBERNETES" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@
import org.springframework.boot.health.contributor.Status;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.cloud.kubernetes.client.example.App;
import org.springframework.cloud.kubernetes.commons.EnvReader;
import org.springframework.context.annotation.Bean;

/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = { App.class, ActuatorEnabledNoFailFastExceptionTest.ActuatorConfig.class },
classes = { TestApp.class, ActuatorEnabledNoFailFastExceptionTest.ActuatorConfig.class },
properties = { "management.endpoint.health.show-details=always",
"management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health",
"spring.main.cloud-platform=KUBERNETES" })
Expand Down Expand Up @@ -79,9 +78,8 @@ private static void mocks() {
envReaderMockedStatic = Mockito.mockStatic(EnvReader.class);
pathsMockedStatic = Mockito.mockStatic(Paths.class, Mockito.CALLS_REAL_METHODS);

envReaderMockedStatic.when(() -> EnvReader.getEnv(KubernetesClientPodUtils.KUBERNETES_SERVICE_HOST))
.thenReturn("k8s-host");
envReaderMockedStatic.when(() -> EnvReader.getEnv(KubernetesClientPodUtils.HOSTNAME)).thenReturn("host");
envReaderMockedStatic.when(() -> EnvReader.getEnv("KUBERNETES_SERVICE_HOST")).thenReturn("k8s-host");
envReaderMockedStatic.when(() -> EnvReader.getEnv("HOSTNAME")).thenReturn("host");

Path serviceAccountTokenPath = Mockito.mock(Path.class);
File serviceAccountTokenFile = Mockito.mock(File.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.client.example.App;
import org.springframework.context.ApplicationContext;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestApp.class,
properties = "spring.main.cloud-platform=KUBERNETES")
public class KubernetesClientHealthIndicatorInsideTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.client.example.App;
import org.springframework.context.ApplicationContext;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestApp.class,
properties = { "management.health.kubernetes.enabled=false" })
public class KubernetesClientHealthIndicatorNotInsideTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.client.example.App;
import org.springframework.context.ApplicationContext;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestApp.class,
properties = "spring.main.cloud-platform=KUBERNETES")
public class KubernetesClientInfoContributorInsideTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.client.example.App;
import org.springframework.context.ApplicationContext;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestApp.class,
properties = { "management.info.kubernetes.enabled=false" })
public class KubernetesClientInfoContributorNotInsideTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
*/
class KubernetesClientPodUtilsTests {

private static final String KUBERNETES_SERVICE_HOST = KubernetesClientPodUtils.KUBERNETES_SERVICE_HOST;

private static final String HOSTNAME = KubernetesClientPodUtils.HOSTNAME;

private static final String SERVICE_ACCOUNT_TOKEN_PATH = Config.SERVICEACCOUNT_TOKEN_PATH;

private static final String SERVICE_ACCOUNT_CERT_PATH = Config.SERVICEACCOUNT_CA_PATH;
Expand Down Expand Up @@ -150,11 +146,11 @@ private void assertSupplierAndClient(Supplier<V1Pod> sup, KubernetesClientPodUti
}

private void mockHost(String host) {
envReader.when(() -> EnvReader.getEnv(KUBERNETES_SERVICE_HOST)).thenReturn(host);
envReader.when(() -> EnvReader.getEnv("KUBERNETES_SERVICE_HOST")).thenReturn(host);
}

private void mockHostname(String name) {
envReader.when(() -> EnvReader.getEnv(HOSTNAME)).thenReturn(name);
envReader.when(() -> EnvReader.getEnv("HOSTNAME")).thenReturn(name);
}

private void mockTokenPath(boolean result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* limitations under the License.
*/

package org.springframework.cloud.kubernetes.client.profile;
package org.springframework.cloud.kubernetes.client;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.client.example.App;
import org.springframework.core.env.Environment;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -29,7 +28,7 @@
/**
* @author Ryan Baxter
*/
@SpringBootTest(classes = { App.class })
@SpringBootTest(classes = { TestApp.class })
class KubernetesClientProfileEnvironmentPostProcessorNoProfileTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* limitations under the License.
*/

package org.springframework.cloud.kubernetes.client.profile;
package org.springframework.cloud.kubernetes.client;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.client.example.App;
import org.springframework.core.env.Environment;

import static io.kubernetes.client.util.Config.ENV_SERVICE_HOST;
Expand All @@ -32,7 +31,7 @@
* @author Thomas Vitale
*/
@SpringBootTest(properties = { ENV_SERVICE_HOST + "=10.0.0.1", ENV_SERVICE_PORT + "=80",
"spring.main.cloud-platform=KUBERNETES" }, classes = { App.class })
"spring.main.cloud-platform=KUBERNETES" }, classes = { TestApp.class })
class KubernetesClientProfileEnvironmentPostProcessorTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
* limitations under the License.
*/

package org.springframework.cloud.kubernetes.client.default_api;
package org.springframework.cloud.kubernetes.client;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
class App {
public class TestApp {

public static void main(String[] args) {
SpringApplication.run(TestApp.class, args);
}

}
Loading
Loading