Skip to content

Commit d4e30ac

Browse files
authored
K8s native clean up part 1 (#1273)
1 parent 07d60b3 commit d4e30ac

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import static org.springframework.cloud.kubernetes.client.discovery.KubernetesDiscoveryClientUtils.matchesServiceLabels;
5050
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.HTTP;
5151
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.HTTPS;
52+
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.PRIMARY_PORT_NAME_LABEL_KEY;
53+
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.SECURED;
5254
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.UNSET_PORT_NAME;
5355

5456
/**
@@ -60,10 +62,6 @@ public class KubernetesInformerDiscoveryClient implements DiscoveryClient {
6062

6163
private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(KubernetesInformerDiscoveryClient.class));
6264

63-
private static final String PRIMARY_PORT_NAME_LABEL_KEY = "primary-port-name";
64-
65-
private static final String SECURED_KEY = "secured";
66-
6765
private final SharedInformerFactory sharedInformerFactory;
6866

6967
private final Lister<V1Service> serviceLister;
@@ -184,10 +182,10 @@ private Stream<ServiceInstance> getServiceInstanceDetails(V1Service service, Str
184182
private static boolean isSecured(V1Service service) {
185183
Optional<String> securedOpt = Optional.empty();
186184
if (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) {
187-
securedOpt = Optional.ofNullable(service.getMetadata().getAnnotations().get(SECURED_KEY));
185+
securedOpt = Optional.ofNullable(service.getMetadata().getAnnotations().get(SECURED));
188186
}
189187
if (!securedOpt.isPresent() && service.getMetadata() != null && service.getMetadata().getLabels() != null) {
190-
securedOpt = Optional.ofNullable(service.getMetadata().getLabels().get(SECURED_KEY));
188+
securedOpt = Optional.ofNullable(service.getMetadata().getLabels().get(SECURED));
191189
}
192190
return Boolean.parseBoolean(securedOpt.orElse("false"));
193191
}

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ private KubernetesDiscoveryConstants() {
7777
*/
7878
public static final String SERVICE_TYPE = "type";
7979

80+
/**
81+
* value of the 'secure' label or annotation.
82+
*/
83+
public static final String SECURED = "secured";
84+
8085
}

spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
2626
import org.springframework.core.log.LogAccessor;
2727

28+
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.SECURED;
29+
2830
class ServicePortSecureResolver {
2931

3032
private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(ServicePortSecureResolver.class));
@@ -53,13 +55,13 @@ boolean resolve(Input input) {
5355
String serviceName = input.serviceName();
5456
Fabric8ServicePortData portData = input.portData();
5557

56-
Optional<String> securedLabelValue = Optional.ofNullable(input.serviceLabels().get("secured"));
58+
Optional<String> securedLabelValue = Optional.ofNullable(input.serviceLabels().get(SECURED));
5759
if (securedLabelValue.isPresent() && TRUTHY_STRINGS.contains(securedLabelValue.get())) {
5860
logEntry(serviceName, portData.portNumber(), "the service contains a true value for the 'secured' label");
5961
return true;
6062
}
6163

62-
Optional<String> securedAnnotationValue = Optional.ofNullable(input.serviceAnnotations().get("secured"));
64+
Optional<String> securedAnnotationValue = Optional.ofNullable(input.serviceAnnotations().get(SECURED));
6365
if (securedAnnotationValue.isPresent() && TRUTHY_STRINGS.contains(securedAnnotationValue.get())) {
6466
logEntry(serviceName, portData.portNumber(),
6567
"the service contains a true value for the 'secured' annotation");

0 commit comments

Comments
 (0)