Skip to content

Commit

Permalink
fix fabric8io#4460 running spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Sep 30, 2022
1 parent f18aa2e commit cf01c37
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 41 deletions.
Expand Up @@ -26,9 +26,9 @@
import io.fabric8.kubernetes.api.model.RootPaths;
import io.fabric8.kubernetes.client.Client;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.KubernetesClientBuilder.ExecutorSupplier;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.VersionInfo;
import io.fabric8.kubernetes.client.KubernetesClientBuilder.ExecutorSupplier;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext;
Expand Down
Expand Up @@ -30,15 +30,16 @@ public class URLFromEnvVarsImpl implements ServiceToURLProvider {

@Override
public String getURL(Service service, String portName, String namespace, KubernetesClient client) {
String serviceHost = URLFromServiceUtil.resolveHostFromEnvVarOrSystemProperty(service.getMetadata().getName());
String servicePort = URLFromServiceUtil.resolvePortFromEnvVarOrSystemProperty(service.getMetadata().getName(), "");
String serviceProtocol = URLFromServiceUtil.resolveProtocolFromEnvVarOrSystemProperty(service.getSpec().getPorts().iterator().next().getProtocol(), "");
String serviceHost = URLFromServiceUtil.resolveHostFromEnvVarOrSystemProperty(service.getMetadata().getName());
String servicePort = URLFromServiceUtil.resolvePortFromEnvVarOrSystemProperty(service.getMetadata().getName(), "");
String serviceProtocol = URLFromServiceUtil
.resolveProtocolFromEnvVarOrSystemProperty(service.getSpec().getPorts().iterator().next().getProtocol(), "");

if(!serviceHost.isEmpty() && !servicePort.isEmpty() && !serviceProtocol.isEmpty()) {
if (!serviceHost.isEmpty() && !servicePort.isEmpty() && !serviceProtocol.isEmpty()) {
return serviceProtocol + "://" + serviceHost + ":" + servicePort;
} else {
String answer = URLFromServiceUtil.getOrCreateAnnotations(service).get(ANNOTATION_EXPOSE_URL);
if(answer != null && !answer.isEmpty()) {
if (answer != null && !answer.isEmpty()) {
return answer;
}
}
Expand Down
Expand Up @@ -29,12 +29,12 @@ public class URLFromIngressImpl implements ServiceToURLProvider {
public String getURL(Service service, String portName, String namespace, KubernetesClient client) {
ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName);
String serviceName = service.getMetadata().getName();
if(port == null) {
if (port == null) {
throw new RuntimeException("Couldn't find port: " + portName + " for service " + service.getMetadata().getName());
}

IngressList ingresses = client.extensions().ingresses().inNamespace(namespace).list();
if(ingresses != null && !ingresses.getItems().isEmpty()) {
if (ingresses != null && !ingresses.getItems().isEmpty()) {
return URLFromServiceUtil.getURLFromIngressList(ingresses.getItems(), namespace, serviceName, port);
}
return null;
Expand Down
Expand Up @@ -35,13 +35,13 @@ public String getURL(Service service, String portName, String namespace, Kuberne
String serviceProto = port.getProtocol();
NodePortUrlComponents urlComponents = null;
Integer nodePort = port.getNodePort();
if(nodePort != null) {
if (nodePort != null) {
try {
NodeList nodeList = client.nodes().list();
if(nodeList != null && nodeList.getItems() != null) {
for(Node item : nodeList.getItems()) {
if (nodeList != null && nodeList.getItems() != null) {
for (Node item : nodeList.getItems()) {
urlComponents = getUrlComponentsFromNodeList(item.getStatus(), nodePort);
if(urlComponents != null) {
if (urlComponents != null) {
break;
}
}
Expand All @@ -51,11 +51,13 @@ public String getURL(Service service, String portName, String namespace, Kuberne
}
}

return urlComponents != null ? (serviceProto + "://" + urlComponents.getClusterIP() + ":" + urlComponents.getPortNumber()).toLowerCase(Locale.ROOT) : null;
return urlComponents != null
? (serviceProto + "://" + urlComponents.getClusterIP() + ":" + urlComponents.getPortNumber()).toLowerCase(Locale.ROOT)
: null;
}

private NodePortUrlComponents getUrlComponentsFromNodeList(NodeStatus nodeStatus, Integer nodePort) {
if(nodeStatus != null) {
if (nodeStatus != null) {
List<NodeAddress> addresses = nodeStatus.getAddresses();
for (NodeAddress address : addresses) {
String ip = address.getAddress();
Expand Down
Expand Up @@ -24,7 +24,6 @@
import io.fabric8.kubernetes.client.RequestConfig;
import io.fabric8.kubernetes.client.dsl.internal.OperationSupport;
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.impl.BaseClient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down
Expand Up @@ -23,7 +23,6 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.http.BasicBuilder;
import io.fabric8.kubernetes.client.http.HttpHeaders;
import io.fabric8.kubernetes.client.impl.KubernetesClientImpl;
import io.fabric8.kubernetes.client.utils.HttpClientUtils;
import io.fabric8.kubernetes.client.utils.Serialization;
import io.fabric8.kubernetes.client.utils.Utils;
Expand Down
Expand Up @@ -26,7 +26,6 @@
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.http.HttpRequest;
import io.fabric8.kubernetes.client.http.HttpRequest.Builder;
import io.fabric8.kubernetes.client.impl.KubernetesClientImpl;
import io.fabric8.kubernetes.client.http.TestHttpResponse;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down
Expand Up @@ -26,7 +26,6 @@
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.http.HttpRequest;
import io.fabric8.kubernetes.client.http.HttpRequest.Builder;
import io.fabric8.kubernetes.client.impl.KubernetesClientImpl;
import io.fabric8.kubernetes.client.http.TestHttpRequest;
import io.fabric8.kubernetes.client.http.TestHttpResponse;
import org.junit.jupiter.api.BeforeEach;
Expand Down
Expand Up @@ -42,8 +42,8 @@
import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperation;
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.impl.BaseClient;
import io.fabric8.kubernetes.client.impl.KubernetesClientImpl;
import io.fabric8.kubernetes.client.impl.ExtensionsAPIGroupClient;
import io.fabric8.kubernetes.client.impl.KubernetesClientImpl;
import io.fabric8.kubernetes.client.utils.HttpClientUtils;
import io.fabric8.kubernetes.client.utils.Serialization;
import io.fabric8.kubernetes.client.utils.TokenRefreshInterceptor;
Expand Down
Expand Up @@ -37,7 +37,7 @@ public class URLFromOpenshiftRouteImpl implements ServiceToURLProvider {
public String getURL(Service service, String portName, String namespace, KubernetesClient client) {
String serviceName = service.getMetadata().getName();
ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName);
if(port != null && port.getName() != null && client.isAdaptable(OpenShiftClient.class)) {
if (port != null && port.getName() != null && client.isAdaptable(OpenShiftClient.class)) {
try {
String serviceProtocol = port.getProtocol();
OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class);
Expand All @@ -46,8 +46,8 @@ public String getURL(Service service, String portName, String namespace, Kuberne
return (serviceProtocol + "://" + route.getSpec().getHost()).toLowerCase(Locale.ROOT);
}
} catch (KubernetesClientException e) {
if(e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) {
logger.warn("Could not lookup route:{} in namespace:{}, due to:{} ",serviceName,namespace,e.getMessage());
if (e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) {
logger.warn("Could not lookup route:{} in namespace:{}, due to:{} ", serviceName, namespace, e.getMessage());
}
}
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ void testAdaptDisabledCheck() {
void testAdaptDSLs() {
// Given
OpenShiftClient client = new OpenShiftClientImpl(
new OpenShiftConfigBuilder().withDisableApiGroupCheck(true).build());
new OpenShiftConfigBuilder().withDisableApiGroupCheck(true).build());

assertNotNull(client.v1());
assertNotNull(client.apps());
Expand Down
Expand Up @@ -19,7 +19,6 @@
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.utils.Serialization;
import io.fabric8.openshift.client.OpenShiftConfig;
import io.fabric8.openshift.client.impl.OpenShiftClientImpl;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -35,8 +34,8 @@ class OpenShiftConfigTest {
@BeforeEach
void setup() {
this.kubernetesConfig = new ConfigBuilder()
.withMasterUrl("https://2.2.2.2")
.build();
.withMasterUrl("https://2.2.2.2")
.build();

this.version = "v1";
System.setProperty(OpenShiftConfig.KUBERNETES_OAPI_VERSION_SYSTEM_PROPERTY, this.version);
Expand All @@ -48,7 +47,6 @@ void tearDown() {
System.clearProperty(OpenShiftConfig.KUBERNETES_OAPI_VERSION_SYSTEM_PROPERTY);
}


@Test
void testOpenshiftURLAsRoot() {
System.setProperty(OpenShiftConfig.OPENSHIFT_URL_SYSTEM_PROPERTY, "https://1.1.1.1");
Expand Down
Expand Up @@ -18,7 +18,6 @@

import io.fabric8.openshift.client.OpenShiftConfig;
import io.fabric8.openshift.client.OpenShiftConfigBuilder;
import io.fabric8.openshift.client.impl.OpenShiftClientImpl;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

Expand Down
Expand Up @@ -18,26 +18,25 @@
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.openshift.api.model.User;
import io.fabric8.openshift.client.OpenShiftClient;
import io.fabric8.openshift.client.impl.OpenShiftClientImpl;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
*/
class ViewCurrentUser {
@Test
void testShowCurrentUser() throws Exception {
OpenShiftClient client = new OpenShiftClientImpl();
User user = client.currentUser();
@Test
void testShowCurrentUser() throws Exception {
OpenShiftClient client = new OpenShiftClientImpl();
User user = client.currentUser();

System.out.println("Current user is: " + user);
assertNotNull(user);
ObjectMeta metadata = user.getMetadata();
assertNotNull(metadata);
String name = metadata.getName();
System.out.println("User name is: " + name);
assertNotNull(name);
}
System.out.println("Current user is: " + user);
assertNotNull(user);
ObjectMeta metadata = user.getMetadata();
assertNotNull(metadata);
String name = metadata.getName();
System.out.println("User name is: " + name);
assertNotNull(name);
}

}

0 comments on commit cf01c37

Please sign in to comment.