Move secure port resolver to commons (#1396)
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
package org.springframework.cloud.kubernetes.commons.discovery;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -22,13 +22,11 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortNameAndNumber;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
|
||||
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.SECURED;
|
||||
|
||||
class ServicePortSecureResolver {
|
||||
public final class ServicePortSecureResolver {
|
||||
|
||||
private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(ServicePortSecureResolver.class));
|
||||
|
||||
@@ -36,7 +34,7 @@ class ServicePortSecureResolver {
|
||||
|
||||
private final KubernetesDiscoveryProperties properties;
|
||||
|
||||
ServicePortSecureResolver(KubernetesDiscoveryProperties properties) {
|
||||
public ServicePortSecureResolver(KubernetesDiscoveryProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@@ -51,7 +49,7 @@ class ServicePortSecureResolver {
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
boolean resolve(Input input) {
|
||||
public boolean resolve(Input input) {
|
||||
|
||||
String serviceName = input.serviceName();
|
||||
ServicePortNameAndNumber portData = input.portData();
|
||||
@@ -90,10 +88,10 @@ class ServicePortSecureResolver {
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
record Input(ServicePortNameAndNumber portData, String serviceName, Map<String, String> serviceLabels,
|
||||
public record Input(ServicePortNameAndNumber portData, String serviceName, Map<String, String> serviceLabels,
|
||||
Map<String, String> serviceAnnotations) {
|
||||
|
||||
Input(ServicePortNameAndNumber portData, String serviceName, Map<String, String> serviceLabels,
|
||||
public Input(ServicePortNameAndNumber portData, String serviceName, Map<String, String> serviceLabels,
|
||||
Map<String, String> serviceAnnotations) {
|
||||
this.portData = portData;
|
||||
this.serviceName = serviceName;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
package org.springframework.cloud.kubernetes.commons.discovery;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@@ -25,11 +25,9 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortNameAndNumber;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.kubernetes.fabric8.discovery.ServicePortSecureResolver.Input;
|
||||
import static org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver.Input;
|
||||
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class ServicePortSecureResolverTest {
|
||||
@@ -33,6 +33,7 @@ import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
|
||||
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.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
|
||||
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortNameAndNumber;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
|
||||
import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -57,7 +58,6 @@ import org.springframework.util.StringUtils;
|
||||
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.EXTERNAL_NAME;
|
||||
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.PRIMARY_PORT_NAME_LABEL_KEY;
|
||||
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.SERVICE_TYPE;
|
||||
import static org.springframework.cloud.kubernetes.fabric8.discovery.ServicePortSecureResolver.Input;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
@@ -208,8 +208,9 @@ final class Fabric8KubernetesDiscoveryClientUtils {
|
||||
secured = false;
|
||||
}
|
||||
else {
|
||||
secured = servicePortSecureResolver.resolve(new Input(portData, service.getMetadata().getName(),
|
||||
service.getMetadata().getLabels(), service.getMetadata().getAnnotations()));
|
||||
secured = servicePortSecureResolver
|
||||
.resolve(new ServicePortSecureResolver.Input(portData, service.getMetadata().getName(),
|
||||
service.getMetadata().getLabels(), service.getMetadata().getAnnotations()));
|
||||
}
|
||||
|
||||
String host = Optional.ofNullable(endpointAddress).map(EndpointAddress::getIp)
|
||||
@@ -294,8 +295,7 @@ final class Fabric8KubernetesDiscoveryClientUtils {
|
||||
|
||||
// this is most probably not a needed if statement, but it preserves the
|
||||
// previous logic before I refactored the code. In particular, this takes care of
|
||||
// the fact
|
||||
// that an EndpointsPort name could be missing.
|
||||
// the fact that an EndpointsPort name could be missing.
|
||||
if (endpointPorts.size() == 1) {
|
||||
result.put(endpointPorts.get(0).getName(), endpointPorts.get(0).getPort());
|
||||
return result;
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.DiscoveryClientUtils;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortNameAndNumber;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKuber
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryClientHealthIndicatorInitializer;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
|
||||
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties.Metadata;
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortNameAndNumber;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
|
||||
Reference in New Issue
Block a user