Skip to content

Commit e139d89

Browse files
committed
fix: corrected check for OpenShift cluster (#216)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent c487d8f commit e139d89

File tree

2 files changed

+5
-37
lines changed

2 files changed

+5
-37
lines changed

src/main/java/com/redhat/devtools/intellij/common/kubernetes/ClusterHelper.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ private ClusterHelper() {
2525
}
2626

2727
public static boolean isOpenShift(KubernetesClient client) {
28-
OpenShiftClient osClient = client.adapt(OpenShiftClient.class);
29-
try {
30-
return osClient.isSupported();
31-
} catch (KubernetesClientException e) {
32-
return e.getCode() == HttpURLConnection.HTTP_UNAUTHORIZED;
33-
}
28+
return client.hasApiGroup(OpenShiftClient.BASE_API_GROUP, false);
3429
}
3530

3631
public static ClusterInfo getClusterInfo(KubernetesClient client) {

src/test/java/com/redhat/devtools/intellij/common/kubernetes/ClusterHelperTest.java

+4-31
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,14 @@
1111
package com.redhat.devtools.intellij.common.kubernetes;
1212

1313
import io.fabric8.kubernetes.client.KubernetesClient;
14-
import io.fabric8.kubernetes.client.KubernetesClientException;
1514
import io.fabric8.kubernetes.client.VersionInfo;
1615
import io.fabric8.openshift.client.OpenShiftClient;
1716
import org.junit.Test;
1817

19-
import java.net.HttpURLConnection;
20-
2118
import static org.assertj.core.api.Assertions.assertThat;
2219
import static org.junit.Assert.assertEquals;
2320
import static org.junit.Assert.assertFalse;
2421
import static org.junit.Assert.assertTrue;
25-
import static org.mockito.Mockito.doReturn;
26-
import static org.mockito.Mockito.doThrow;
2722
import static org.mockito.Mockito.mock;
2823
import static org.mockito.Mockito.when;
2924

@@ -77,46 +72,24 @@ public void testOCP3OrOCP4AdminUserCluster() {
7772
}
7873

7974
@Test
80-
public void isOpenShift_should_return_true_if_isSupported() {
75+
public void isOpenShift_should_return_true_if_has_api_group() {
8176
// given
82-
OpenShiftClient oclient = mock(OpenShiftClient.class);
83-
doReturn(true)
84-
.when(oclient).isSupported();
8577
KubernetesClient client = mock(KubernetesClient.class);
86-
when(client.adapt(OpenShiftClient.class)).thenReturn(oclient);
78+
when(client.hasApiGroup(OpenShiftClient.BASE_API_GROUP, false)).thenReturn(true);
8779
// when
8880
boolean isOpenShift = ClusterHelper.isOpenShift(client);
8981
// then
9082
assertThat(isOpenShift).isTrue();
9183
}
9284

9385
@Test
94-
public void isOpenShift_should_return_false_if_isSupported_throws() {
86+
public void isOpenShift_should_return_false_if_has_not_api_group() {
9587
// given
96-
OpenShiftClient oclient = mock(OpenShiftClient.class);
97-
doThrow(KubernetesClientException.class)
98-
.when(oclient).isSupported();
9988
KubernetesClient client = mock(KubernetesClient.class);
100-
when(client.adapt(OpenShiftClient.class)).thenReturn(oclient);
89+
when(client.hasApiGroup(OpenShiftClient.BASE_API_GROUP, false)).thenReturn(false);
10190
// when
10291
boolean isOpenShift = ClusterHelper.isOpenShift(client);
10392
// then
10493
assertThat(isOpenShift).isFalse();
10594
}
106-
107-
@Test
108-
public void isOpenShift_should_return_true_if_isSupported_throws_unauthorized() {
109-
// given
110-
OpenShiftClient oclient = mock(OpenShiftClient.class);
111-
KubernetesClientException e = new KubernetesClientException("ouch", HttpURLConnection.HTTP_UNAUTHORIZED, null);
112-
doThrow(e)
113-
.when(oclient).isSupported();
114-
KubernetesClient client = mock(KubernetesClient.class);
115-
when(client.adapt(OpenShiftClient.class)).thenReturn(oclient);
116-
// when
117-
boolean isOpenShift = ClusterHelper.isOpenShift(client);
118-
// then
119-
assertThat(isOpenShift).isTrue();
120-
}
121-
12295
}

0 commit comments

Comments
 (0)