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 Fabric8ActuatorConfiguration {
final class Fabric8ActuatorConfiguration {

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@
@Configuration(proxyBeanMethods = false)
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
@AutoConfigureAfter(KubernetesCommonsAutoConfiguration.class)
public class Fabric8AutoConfiguration {

private static <D> D or(D left, D right) {
return left != null ? left : right;
}

private static Integer orDurationInt(Duration left, Integer right) {
return left != null ? (int) left.toMillis() : right;
}
public final class Fabric8AutoConfiguration {

@Bean
@ConditionalOnMissingBean(Config.class)
Expand Down Expand Up @@ -109,8 +101,16 @@ public KubernetesClient kubernetesClient(Config config) {

@Bean
@ConditionalOnMissingBean
public Fabric8PodUtils kubernetesPodUtils(KubernetesClient client) {
Fabric8PodUtils kubernetesPodUtils(KubernetesClient client) {
return new Fabric8PodUtils(client);
}

private static <D> D or(D left, D right) {
return left != null ? left : right;
}

private static Integer orDurationInt(Duration left, Integer right) {
return left != null ? (int) left.toMillis() : right;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
* @author Ioannis Canellos
* @author Eddú Meléndez
*/
public class Fabric8HealthIndicator extends AbstractKubernetesHealthIndicator {
final class Fabric8HealthIndicator extends AbstractKubernetesHealthIndicator {

private final PodUtils<Pod> utils;

public Fabric8HealthIndicator(PodUtils<Pod> utils) {
Fabric8HealthIndicator(PodUtils<Pod> utils) {
this.utils = utils;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
*
* @author Mark Anderson
*/
public class Fabric8InfoContributor extends AbstractKubernetesInfoContributor {
final class Fabric8InfoContributor extends AbstractKubernetesInfoContributor {

private final PodUtils<Pod> utils;

public Fabric8InfoContributor(PodUtils<Pod> utils) {
Fabric8InfoContributor(PodUtils<Pod> utils) {
this.utils = utils;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,7 @@
*
* @author Ioannis Canellos
*/
public class Fabric8PodUtils implements PodUtils<Pod> {

/**
* 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 Fabric8PodUtils implements PodUtils<Pod> {

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

Expand All @@ -57,14 +47,14 @@ public class Fabric8PodUtils implements PodUtils<Pod> {

private final Supplier<Pod> current;

public Fabric8PodUtils(KubernetesClient client) {
Fabric8PodUtils(KubernetesClient client) {
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);
}

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

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

import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;

import org.springframework.cloud.kubernetes.commons.profile.AbstractKubernetesProfileEnvironmentPostProcessor;
import org.springframework.cloud.kubernetes.fabric8.Fabric8PodUtils;
import org.springframework.core.env.Environment;

public class Fabric8ProfileEnvironmentPostProcessor extends AbstractKubernetesProfileEnvironmentPostProcessor {
final class Fabric8ProfileEnvironmentPostProcessor extends AbstractKubernetesProfileEnvironmentPostProcessor {

@Override
protected boolean isInsideKubernetes(Environment environment) {

try (KubernetesClient client = new KubernetesClientBuilder().build()) {
Fabric8PodUtils podUtils = new Fabric8PodUtils(client);
return environment.containsProperty(Fabric8PodUtils.KUBERNETES_SERVICE_HOST)
|| podUtils.isInsideKubernetes();
return environment.containsProperty("KUBERNETES_SERVICE_HOST") || podUtils.isInsideKubernetes();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
*/
public final class Fabric8Utils {

private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8Utils.class));

private Fabric8Utils() {

}
Expand All @@ -48,8 +50,6 @@ public static ServiceMetadata serviceMetadata(Service service) {
metadata.getLabels(), metadata.getAnnotations());
}

private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8Utils.class));

/**
* this method does the namespace resolution. Namespace is being searched according to
* the order below.
Expand All @@ -76,7 +76,7 @@ public static String getApplicationNamespace(KubernetesClient client, @Nullable
String configurationTarget, KubernetesNamespaceProvider provider) {

if (StringUtils.hasText(namespace)) {
LOG.debug(configurationTarget + " namespace : " + namespace);
LOG.debug(() -> configurationTarget + " namespace : " + namespace);
return namespace;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
org.springframework.boot.EnvironmentPostProcessor=\
org.springframework.cloud.kubernetes.fabric8.profile.Fabric8ProfileEnvironmentPostProcessor
org.springframework.cloud.kubernetes.fabric8.Fabric8ProfileEnvironmentPostProcessor
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.cloud.kubernetes;
package org.springframework.cloud.kubernetes.fabric8;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.KubernetesClient;
Expand All @@ -26,15 +26,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
import org.springframework.cloud.kubernetes.example.App;
import org.springframework.cloud.kubernetes.fabric8.Fabric8HealthIndicator;
import org.springframework.cloud.kubernetes.fabric8.Fabric8InfoContributor;
import org.springframework.cloud.kubernetes.fabric8.Fabric8PodUtils;
import org.springframework.context.ConfigurableApplicationContext;

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

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestApp.class,
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.password=mypassword",
"spring.cloud.kubernetes.client.proxy-password=myproxypassword" })
@EnableKubernetesMockClient(crud = true, https = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

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

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -34,7 +33,7 @@
*
* test "User-Agent" functionality via system properties
*/
@SpringBootTest(classes = App.class, properties = "spring.main.cloud-platform=KUBERNETES")
@SpringBootTest(classes = TestApp.class, properties = "spring.main.cloud-platform=KUBERNETES")
@DirtiesContext
class Fabric8ClientUserAgentEnvPropertyTests {

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

package org.springframework.cloud.kubernetes;
package org.springframework.cloud.kubernetes.fabric8;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.KubernetesClient;
Expand All @@ -25,11 +25,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.test.LocalManagementPort;
import org.springframework.cloud.kubernetes.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=false" })
@EnableKubernetesMockClient(crud = true, https = false)
class Fabric8HealthIndicatorDisabledTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.cloud.kubernetes;
package org.springframework.cloud.kubernetes.fabric8;

import java.util.Collections;

Expand All @@ -29,8 +29,6 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.test.LocalManagementPort;
import org.springframework.cloud.kubernetes.commons.PodUtils;
import org.springframework.cloud.kubernetes.example.App;
import org.springframework.cloud.kubernetes.fabric8.Fabric8HealthIndicator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -44,7 +42,7 @@
* test to see if proper fields are set in health when it is running inside the container
*/
@Import(Fabric8InsideHealthIndicatorTest.KubernetesActuatorTestConfiguration.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestApp.class,
properties = { "management.endpoint.health.show-details=always" })
class Fabric8InsideHealthIndicatorTest {

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

package org.springframework.cloud.kubernetes;
package org.springframework.cloud.kubernetes.fabric8;

import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodBuilder;
Expand All @@ -26,8 +26,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.test.LocalManagementPort;
import org.springframework.cloud.kubernetes.example.App;
import org.springframework.cloud.kubernetes.fabric8.Fabric8PodUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -40,7 +38,7 @@
* test proper fields being set in /actuator/info
*/
@Import(Fabric8InsideInfoContributorTest.InfoContributorTestConfig.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestApp.class,
properties = { "spring.main.cloud-platform=KUBERNETES", "management.endpoints.web.exposure.include=info",
"management.endpoint.info.show-details=always", "management.info.kubernetes.enabled=true" })
class Fabric8InsideInfoContributorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.cloud.kubernetes;
package org.springframework.cloud.kubernetes.fabric8;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.KubernetesClient;
Expand All @@ -26,11 +26,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.test.LocalManagementPort;
import org.springframework.cloud.kubernetes.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 = { "spring.main.cloud-platform=KUBERNETES", "management.endpoint.health.show-details=always" })
@EnableKubernetesMockClient(crud = true, https = false)
class Fabric8NotInsideHealthIndicatorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.cloud.kubernetes;
package org.springframework.cloud.kubernetes.fabric8;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
Expand All @@ -23,11 +23,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.test.LocalManagementPort;
import org.springframework.cloud.kubernetes.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 = { "spring.main.cloud-platform=KUBERNETES", "management.endpoints.web.exposure.include=info",
"management.endpoint.info.show-details=always", "management.info.kubernetes.enabled=true" })
@EnableKubernetesMockClient(crud = true, https = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.cloud.kubernetes;
package org.springframework.cloud.kubernetes.fabric8;

import java.io.File;
import java.nio.file.Path;
Expand All @@ -35,15 +35,10 @@
import org.mockito.Mockito;

import org.springframework.cloud.kubernetes.commons.EnvReader;
import org.springframework.cloud.kubernetes.fabric8.Fabric8PodUtils;

@SuppressWarnings("unchecked")
class Fabric8PodUtilsTest {

private static final String KUBERNETES_SERVICE_HOST = Fabric8PodUtils.KUBERNETES_SERVICE_HOST;

private static final String HOSTNAME = Fabric8PodUtils.HOSTNAME;

private static final String SERVICE_ACCOUNT_TOKEN_PATH = Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH;

private static final String SERVICE_ACCOUNT_CERT_PATH = Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH;
Expand Down Expand Up @@ -147,11 +142,11 @@ void allPresent() {
}

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
Loading
Loading