diff --git a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClient.java b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClient.java index cb5b0458ac..6ad440341d 100644 --- a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClient.java +++ b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClient.java @@ -49,6 +49,8 @@ import static org.springframework.cloud.kubernetes.client.discovery.KubernetesDiscoveryClientUtils.matchesServiceLabels; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.HTTP; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.HTTPS; +import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.PRIMARY_PORT_NAME_LABEL_KEY; +import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.SECURED; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.UNSET_PORT_NAME; /** @@ -60,10 +62,6 @@ public class KubernetesInformerDiscoveryClient implements DiscoveryClient { private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(KubernetesInformerDiscoveryClient.class)); - private static final String PRIMARY_PORT_NAME_LABEL_KEY = "primary-port-name"; - - private static final String SECURED_KEY = "secured"; - private final SharedInformerFactory sharedInformerFactory; private final Lister serviceLister; @@ -184,10 +182,10 @@ private Stream getServiceInstanceDetails(V1Service service, Str private static boolean isSecured(V1Service service) { Optional securedOpt = Optional.empty(); if (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) { - securedOpt = Optional.ofNullable(service.getMetadata().getAnnotations().get(SECURED_KEY)); + securedOpt = Optional.ofNullable(service.getMetadata().getAnnotations().get(SECURED)); } if (!securedOpt.isPresent() && service.getMetadata() != null && service.getMetadata().getLabels() != null) { - securedOpt = Optional.ofNullable(service.getMetadata().getLabels().get(SECURED_KEY)); + securedOpt = Optional.ofNullable(service.getMetadata().getLabels().get(SECURED)); } return Boolean.parseBoolean(securedOpt.orElse("false")); } diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryConstants.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryConstants.java index a6565d079c..6865d52a30 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryConstants.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryConstants.java @@ -77,4 +77,9 @@ private KubernetesDiscoveryConstants() { */ public static final String SERVICE_TYPE = "type"; + /** + * value of the 'secure' label or annotation. + */ + public static final String SECURED = "secured"; + } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java index 941fcf61da..e8c70e9e9c 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java @@ -25,6 +25,8 @@ import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.core.log.LogAccessor; +import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.SECURED; + class ServicePortSecureResolver { private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(ServicePortSecureResolver.class)); @@ -53,13 +55,13 @@ boolean resolve(Input input) { String serviceName = input.serviceName(); Fabric8ServicePortData portData = input.portData(); - Optional securedLabelValue = Optional.ofNullable(input.serviceLabels().get("secured")); + Optional securedLabelValue = Optional.ofNullable(input.serviceLabels().get(SECURED)); if (securedLabelValue.isPresent() && TRUTHY_STRINGS.contains(securedLabelValue.get())) { logEntry(serviceName, portData.portNumber(), "the service contains a true value for the 'secured' label"); return true; } - Optional securedAnnotationValue = Optional.ofNullable(input.serviceAnnotations().get("secured")); + Optional securedAnnotationValue = Optional.ofNullable(input.serviceAnnotations().get(SECURED)); if (securedAnnotationValue.isPresent() && TRUTHY_STRINGS.contains(securedAnnotationValue.get())) { logEntry(serviceName, portData.portNumber(), "the service contains a true value for the 'secured' annotation");