Skip to content

Commit

Permalink
fix: bump kubernetes-client to 7.0.0 (#921)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Jan 10, 2025
1 parent dc979a2 commit 157ad6a
Show file tree
Hide file tree
Showing 20 changed files with 419 additions and 308 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
# libraries
junit = "4.13.2"
openshift-client = "6.12.0"
openshift-client = "7.0.0"
devtools-common = "1.9.7-SNAPSHOT"
keycloak = "24.0.5"
jsonwebtoken = "0.12.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@
******************************************************************************/
package org.jboss.tools.intellij.openshift.utils;

import org.jboss.tools.intellij.openshift.utils.oc.Oc;

import java.io.IOException;
import org.jboss.tools.intellij.openshift.utils.oc.Oc;

public class OdoCluster {

public static final OdoCluster INSTANCE = new OdoCluster();

private static final String CLUSTER_URL = System.getenv("CLUSTER_URL");
public static final String CLUSTER_URL = System.getenv("CLUSTER_URL");

private static final String CLUSTER_USER = System.getenv("CLUSTER_USER");
public static final String CLUSTER_USER = System.getenv("CLUSTER_USER");

private static final String CLUSTER_PASSWORD = System.getenv("CLUSTER_PASSWORD");
public static final String CLUSTER_PASSWORD = System.getenv("CLUSTER_PASSWORD");

public void login(Oc oc) throws IOException {
if (CLUSTER_URL != null && !oc.getMasterUrl().toString().startsWith(CLUSTER_URL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,38 @@
package org.jboss.tools.intellij.openshift.utils;

import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import io.fabric8.kubernetes.client.KubernetesClient;
import java.util.concurrent.ExecutionException;
import org.jboss.tools.intellij.openshift.utils.ToolFactory.Tool;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jboss.tools.intellij.openshift.utils.oc.Oc;
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
import org.jboss.tools.intellij.openshift.utils.odo.OdoDelegate;

import java.util.concurrent.ExecutionException;

public class ToolFactoryTest extends BasePlatformTestCase {

private KubernetesClient client;

@Override
protected void setUp() throws Exception {
super.setUp();
this.client = new KubernetesClientFactory().create();
}

public void testGetOdo() throws ExecutionException, InterruptedException {
Tool<OdoDelegate> tool = ToolFactory.getInstance().createOdo(getProject()).get();
Tool<OdoDelegate> tool = ToolFactory.getInstance().createOdo(client, getProject()).get();
Odo odo = tool.get();
assertNotNull(odo);
}

public void testGetHelm() throws ExecutionException, InterruptedException {
Tool<Helm> tool = ToolFactory.getInstance().createHelm(getProject()).get();
Tool<Helm> tool = ToolFactory.getInstance().createHelm().get();
Helm helm = tool.get();
assertNotNull(helm);
}

public void testGetOc() throws ExecutionException, InterruptedException {
Tool<Oc> tool = ToolFactory.getInstance().createOc(getProject()).get();
Tool<Oc> tool = ToolFactory.getInstance().createOc(client).get();
Oc oc = tool.get();
assertNotNull(oc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

public class HelmCliSearchTest extends HelmCliTest {

public void testSearch_should_list_all_charts() throws IOException {
// given openshift a repo was added to helm
// when
List<Chart> charts = helm.search();
// then
assertFalse(charts.isEmpty());
}
public void testSearch_should_list_all_charts() throws IOException {
// given openshift a repo was added to helm
// when
List<Chart> charts = helm.search();
// then
assertFalse(charts.isEmpty());
}

public void testSearch_should_list_kuberos() throws IOException {
// given openshift repo was added to helm
String id = Charts.CHART_KUBEROS;
// when
List<Chart> charts = helm.search(id);
// then
boolean found = charts.stream().anyMatch((Chart chart) -> chart.getName().contains(id));
assertTrue(found);
}
public void testSearch_should_list_kuberos() throws IOException {
// given openshift repo was added to helm
String id = Charts.CHART_KUBEROS;
// when
List<Chart> charts = helm.search(id);
// then
boolean found = charts.stream().anyMatch((Chart chart) -> chart.getName().contains(id));
assertTrue(found);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,39 @@
package org.jboss.tools.intellij.openshift.utils.helm;

import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import io.fabric8.kubernetes.client.KubernetesClient;
import java.util.Random;
import org.jboss.tools.intellij.openshift.utils.KubernetesClientFactory;
import org.jboss.tools.intellij.openshift.utils.OdoCluster;
import org.jboss.tools.intellij.openshift.utils.ToolFactory;
import org.jboss.tools.intellij.openshift.utils.ToolFactory.Tool;
import org.jboss.tools.intellij.openshift.utils.oc.Oc;
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
import org.jboss.tools.intellij.openshift.utils.odo.OdoDelegate;

import java.util.Random;

public abstract class HelmCliTest extends BasePlatformTestCase {

protected Helm helm;

private KubernetesClient client;
private final String projectName = "prj-" + new Random().nextInt();

@Override
protected void setUp() throws Exception {
super.setUp();
Tool<OdoDelegate> odoTool = ToolFactory.getInstance().createOdo(getProject()).get();
Tool<Oc> ocTool = ToolFactory.getInstance().createOc(getProject()).get();
this.client = new KubernetesClientFactory().create();
Tool<OdoDelegate> odoTool = ToolFactory.getInstance().createOdo(client, getProject()).get();
Tool<Oc> ocTool = ToolFactory.getInstance().createOc(client).get();
Odo odo = odoTool.get();
OdoCluster.INSTANCE.login(ocTool.get());
odo.createProject(projectName);
Tool<Helm> helmTool = ToolFactory.getInstance().createHelm(getProject()).get();
Tool<Helm> helmTool = ToolFactory.getInstance().createHelm().get();
this.helm = helmTool.get();
Charts.addRepository(Charts.REPOSITORY_STABLE, helm);
}

@Override
protected void tearDown() throws Exception {
Tool<OdoDelegate> tool = ToolFactory.getInstance().createOdo(getProject()).getNow(null);
Tool<OdoDelegate> tool = ToolFactory.getInstance().createOdo(client, getProject()).getNow(null);
if (tool != null) {
tool.get().deleteProject(projectName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import com.redhat.devtools.intellij.common.utils.MessagesHelper;
import io.fabric8.kubernetes.client.KubernetesClient;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationRootNodeOdo;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
import org.jboss.tools.intellij.openshift.utils.KubernetesClientFactory;
import org.jboss.tools.intellij.openshift.utils.OdoCluster;
import org.jboss.tools.intellij.openshift.utils.ToolFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.with;
import static org.jboss.tools.intellij.openshift.Constants.PLUGIN_FOLDER;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -64,34 +65,40 @@ public abstract class OdoCliTest extends BasePlatformTestCase {
protected static final String REGISTRY_PREFIX = "reg";

private TestDialog previousTestDialog;
private KubernetesClient client;

@Before
public void init() throws Exception {
previousTestDialog = MessagesHelper.setTestDialog(TestDialog.OK);
ToolFactory.getInstance().createOc(getProject()).whenComplete((ocTool, throwable) -> {
try {
OdoCluster.INSTANCE.login(ocTool.get());
} catch (IOException e) {
throw new RuntimeException(e);
}
});
odo = getOdo().get();
this.previousTestDialog = MessagesHelper.setTestDialog(TestDialog.OK);
this.client = new KubernetesClientFactory().create();
loginCluster();
this.odo = createOdo(client).get();
}

@After
public void cleanup() {
MessagesHelper.setTestDialog(previousTestDialog);
}

private CompletableFuture<OdoFacade> getOdo() {
private void loginCluster() {
ToolFactory.getInstance().createOc(client).whenComplete((ocTool, throwable) -> {
try {
OdoCluster.INSTANCE.login(ocTool.get());
} catch (IOException e) {
throw new RuntimeException("Could not log into " + OdoCluster.CLUSTER_URL + " as user " + OdoCluster.CLUSTER_USER, e);
}
});
}

private CompletableFuture<OdoFacade> createOdo(KubernetesClient client) {
return ToolFactory.getInstance()
.createOdo(getProject())
.createOdo(client, getProject())
.thenApply(tool -> new ApplicationRootNodeOdo(tool.get(), false, rootNode, processHelper));
}

protected void createProject(String project) throws IOException, ExecutionException, InterruptedException {
odo.createProject(project);
odo = getOdo().get();
odo = createOdo(client).get();
}

protected void createComponent(String project, String component, String starter, String projectPath) throws IOException, ExecutionException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
import io.fabric8.openshift.api.model.ProjectList;
import io.fabric8.openshift.client.OpenShiftClient;
import io.fabric8.openshift.client.dsl.ProjectOperation;
import org.jboss.tools.intellij.openshift.utils.Cli;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
Expand All @@ -40,7 +36,9 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jboss.tools.intellij.openshift.utils.Cli;
import org.junit.Before;
import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
Expand Down Expand Up @@ -256,11 +254,10 @@ private OdoCli createOdo(KubernetesClient kubernetesClient, OpenShiftClient open
MessageBus bus = mock(MessageBus.class);
doReturn(connection)
.when(bus).connect();
Supplier<KubernetesClient> kubernetesClientFactory = () -> kubernetesClient;
Function<KubernetesClient, OpenShiftClient> openShiftClientFactory = client -> openShiftClient;
Function<String, Map<String, String>> envVarFactory = url -> new HashMap<>();
Cli.TelemetryReport telemetryReport = mock(Cli.TelemetryReport.class);
return new OdoCli(project, command, bus, kubernetesClientFactory, openShiftClientFactory, envVarFactory, telemetryReport);
return new OdoCli(command, project, kubernetesClient, bus, openShiftClientFactory, envVarFactory, telemetryReport);
}

private static <R extends HasMetadata> R mockResource(String name, Class<R> clazz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void actionPerformed(AnActionEvent anActionEvent, TreePath[] path, Object

protected Helm getHelm(AnActionEvent anActionEvent) {
try {
return ActionUtils.getApplicationRootNode(anActionEvent).getHelm(true);
return ActionUtils.getApplicationRootNode(anActionEvent).getHelm();
} catch (Exception e) {
LOGGER.warn("Could not get helm: {}", e.getMessage(), e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ protected OcAction(Class... filters) {
@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected) {
setTelemetrySender(new TelemetrySender(PREFIX_ACTION + getTelemetryActionName()));
ActionUtils.getApplicationRootNode(anActionEvent).getOcTool().whenComplete(
(ocTool, throwable) -> {
if (ocTool != null) {
Oc oc = ocTool.get();
if (oc != null) {
this.actionPerformedOnSelectedObject(anActionEvent, getElement(selected), oc);
ActionUtils.getApplicationRootNode(anActionEvent).getOcTool()
.whenComplete(
(ocTool, throwable) -> {
if (ocTool != null) {
Oc oc = ocTool.get();
if (oc != null) {
this.actionPerformedOnSelectedObject(anActionEvent, getElement(selected), oc);
}
}
}
}
);
);
}

public abstract void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Oc oc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.intellij.openshift.actions.project;

import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
Expand Down Expand Up @@ -189,4 +190,9 @@ public void run() {
);
}
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
}
Loading

0 comments on commit 157ad6a

Please sign in to comment.