Skip to content

Commit

Permalink
Align fabric8 k8s discovery clients part 5 (#1506)
Browse files Browse the repository at this point in the history
wind57 authored Nov 15, 2023
1 parent 81fd64b commit 13787ee
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -46,7 +46,6 @@
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.util.ClassUtils;

import static org.springframework.cloud.kubernetes.client.KubernetesClientUtils.kubernetesApiClient;

@@ -57,7 +56,7 @@ class KubernetesClientConfigServerBootstrapper extends KubernetesConfigServerBoo

@Override
public void initialize(BootstrapRegistry registry) {
if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerInstanceProvider", null)) {
if (hasConfigServerInstanceProvider()) {
return;
}
// We need to pass a lambda here rather than create a new instance of
@@ -96,7 +95,7 @@ public List<ServiceInstance> apply(String serviceId, Binder binder, BindHandler
.getInstances(serviceId);
}

protected KubernetesConfigServerInstanceProvider getInstanceProvider(
private KubernetesConfigServerInstanceProvider getInstanceProvider(
KubernetesDiscoveryProperties discoveryProperties, KubernetesClientProperties clientProperties,
BootstrapContext context, Binder binder, BindHandler bindHandler, Log log) {
if (context.isRegistered(KubernetesInformerDiscoveryClient.class)) {
@@ -116,12 +115,12 @@ protected KubernetesConfigServerInstanceProvider getInstanceProvider(

String namespace = getInformerNamespace(kubernetesNamespaceProvider, discoveryProperties);
SharedInformerFactory sharedInformerFactory = new SharedInformerFactory(apiClient);
final GenericKubernetesApi<V1Service, V1ServiceList> servicesApi = new GenericKubernetesApi<>(
V1Service.class, V1ServiceList.class, "", "v1", "services", apiClient);
GenericKubernetesApi<V1Service, V1ServiceList> servicesApi = new GenericKubernetesApi<>(V1Service.class,
V1ServiceList.class, "", "v1", "services", apiClient);
SharedIndexInformer<V1Service> serviceSharedIndexInformer = sharedInformerFactory
.sharedIndexInformerFor(servicesApi, V1Service.class, 0L, namespace);
Lister<V1Service> serviceLister = new Lister<>(serviceSharedIndexInformer.getIndexer());
final GenericKubernetesApi<V1Endpoints, V1EndpointsList> endpointsApi = new GenericKubernetesApi<>(
GenericKubernetesApi<V1Endpoints, V1EndpointsList> endpointsApi = new GenericKubernetesApi<>(
V1Endpoints.class, V1EndpointsList.class, "", "v1", "endpoints", apiClient);
SharedIndexInformer<V1Endpoints> endpointsSharedIndexInformer = sharedInformerFactory
.sharedIndexInformerFor(endpointsApi, V1Endpoints.class, 0L, namespace);
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public static boolean hasConfigServerInstanceProvider() {

public static KubernetesDiscoveryProperties createKubernetesDiscoveryProperties(Binder binder,
BindHandler bindHandler) {
return binder.bind("spring.cloud.kubernetes.discovery", Bindable.of(KubernetesDiscoveryProperties.class),
return binder.bind(KubernetesDiscoveryProperties.PREFIX, Bindable.of(KubernetesDiscoveryProperties.class),
bindHandler).orElseGet(() -> KubernetesDiscoveryProperties.DEFAULT);
}

Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@
* have "type: ExternalName" in their spec.
*/
// @formatter:off
@ConfigurationProperties("spring.cloud.kubernetes.discovery")
@ConfigurationProperties(KubernetesDiscoveryProperties.PREFIX)
public record KubernetesDiscoveryProperties(
@DefaultValue("true") boolean enabled, boolean allNamespaces,
@DefaultValue Set<String> namespaces,
@@ -63,6 +63,11 @@ public record KubernetesDiscoveryProperties(
boolean includeExternalNameServices) {
// @formatter:on

/**
* Prefix of the properties.
*/
public static final String PREFIX = "spring.cloud.kubernetes.discovery";

@ConstructorBinding
public KubernetesDiscoveryProperties {

Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@
import org.springframework.cloud.kubernetes.commons.config.KubernetesConfigServerBootstrapper;
import org.springframework.cloud.kubernetes.commons.config.KubernetesConfigServerInstanceProvider;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
import org.springframework.util.ClassUtils;

/**
* @author Ryan Baxter
@@ -42,7 +41,7 @@ class ConfigServerBootstrapper extends KubernetesConfigServerBootstrapper {

@Override
public void initialize(BootstrapRegistry registry) {
if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerInstanceProvider", null)) {
if (hasConfigServerInstanceProvider()) {
return;
}
// We need to pass a lambda here rather than create a new instance of
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;
import org.springframework.util.ClassUtils;

/**
* @author Ryan Baxter
@@ -44,7 +43,7 @@ class Fabric8ConfigServerBootstrapper extends KubernetesConfigServerBootstrapper

@Override
public void initialize(BootstrapRegistry registry) {
if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerInstanceProvider", null)) {
if (hasConfigServerInstanceProvider()) {
return;
}
// We need to pass a lambda here rather than create a new instance of

0 comments on commit 13787ee

Please sign in to comment.