intellij-openshift-connector icon indicating copy to clipboard operation
intellij-openshift-connector copied to clipboard

Refreshing the tree is too slow, should not validate current namespace

Open adietish opened this issue 2 years ago • 0 comments

follows up on #595 related to #616

Currently the tree would validate the current namespace before displaying it: The current namespace/project in the client is taken and checked if it exists in the list of all namespaces/projects on the cluster.

https://github.com/redhat-developer/intellij-openshift-connector/blob/main/src/main/java/org/jboss/tools/intellij/openshift/utils/odo/OdoCli.java#L213

    protected String validateNamespace(String ns) {
        if (Strings.isNullOrEmpty(ns)) {
            ns = "default";
        }
        try {
            if (isOpenShift()) {
                client.adapt(OpenShiftClient.class).projects().withName(ns).get();
            } else {
                client.namespaces().withName(ns).get();
            }
        } catch (KubernetesClientException e) {
            ns = "";
            if (isOpenShift()) {
                List<Project> projects = client.adapt(OpenShiftClient.class).projects().list().getItems();
                if (!projects.isEmpty()) {
                    ns = projects.get(0).getMetadata().getName();
                }
            } else {
                List<Namespace> namespaces = client.namespaces().list().getItems();
                if (!namespaces.isEmpty()) {
                    ns = namespaces.get(0).getMetadata().getName();
                }
            }
        }
        return ns;
    }

This was impl'd in order to avoid using an invalid/missing namespace (ex. when you delete the current namespace/project in the tooling). This slows displaying the tree considerably though, since it is causing 3+ requests to the cluster:

  • determine if the cluster is an OpenShift cluster (done by requesting the API-Groups in the kubernetes-client)
  • retrieve all namespaces/projects

We could eliminate this validation and make sure that we set a valid new current namespace/project if we delete it. If the namespace/project was deleted using the cli we could simply display the error retrieving the resources for the (invalid) current namespace/project. A menu item to switch the current namespace would then allow the user to choose a valid namespace/project.

adietish avatar Nov 14 '23 11:11 adietish