From 51095e74b72cb39e16d9066158444f0336464704 Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Mon, 5 Jun 2023 21:23:30 +0200 Subject: [PATCH] display routes for openshift clusters (#610) Signed-off-by: Andre Dietisheim --- .../model/resource/OperatorFactory.kt | 2 ++ .../resource/openshift/RoutesOperator.kt | 32 +++++++++++++++++++ .../kubernetes/tree/OpenShiftDescriptors.kt | 4 ++- .../kubernetes/tree/OpenShiftStructure.kt | 29 ++++++++++++++++- 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/resource/openshift/RoutesOperator.kt diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/resource/OperatorFactory.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/resource/OperatorFactory.kt index becbfbd7e..d7ff3492d 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/resource/OperatorFactory.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/resource/OperatorFactory.kt @@ -35,6 +35,7 @@ import com.redhat.devtools.intellij.kubernetes.model.resource.openshift.Deployme import com.redhat.devtools.intellij.kubernetes.model.resource.openshift.ImageStreamsOperator import com.redhat.devtools.intellij.kubernetes.model.resource.openshift.ProjectsOperator import com.redhat.devtools.intellij.kubernetes.model.resource.openshift.ReplicationControllersOperator +import com.redhat.devtools.intellij.kubernetes.model.resource.openshift.RoutesOperator import io.fabric8.kubernetes.api.model.HasMetadata import io.fabric8.kubernetes.client.KubernetesClient import io.fabric8.openshift.client.OpenShiftClient @@ -58,6 +59,7 @@ object OperatorFactory { BuildsOperator.KIND to ::BuildsOperator, BuildConfigsOperator.KIND to ::BuildConfigsOperator, ReplicationControllersOperator.KIND to ::ReplicationControllersOperator, + RoutesOperator.KIND to ::RoutesOperator, ServicesOperator.KIND to ::ServicesOperator, EndpointsOperator.KIND to ::EndpointsOperator, PersistentVolumesOperator.KIND to ::PersistentVolumesOperator, diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/resource/openshift/RoutesOperator.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/resource/openshift/RoutesOperator.kt new file mode 100644 index 000000000..844c5f25e --- /dev/null +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/resource/openshift/RoutesOperator.kt @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package com.redhat.devtools.intellij.kubernetes.model.resource.openshift + +import com.redhat.devtools.intellij.kubernetes.model.client.ClientAdapter +import com.redhat.devtools.intellij.kubernetes.model.resource.NamespacedOperation +import com.redhat.devtools.intellij.kubernetes.model.resource.NamespacedResourceOperator +import com.redhat.devtools.intellij.kubernetes.model.resource.ResourceKind +import io.fabric8.openshift.api.model.Route +import io.fabric8.openshift.client.OpenShiftClient + +class RoutesOperator(client: ClientAdapter) + : NamespacedResourceOperator(client.get()) { + + companion object { + val KIND = ResourceKind.create(Route::class.java) + } + + override val kind = KIND + + override fun getOperation(): NamespacedOperation { + return client.routes() + } +} diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/OpenShiftDescriptors.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/OpenShiftDescriptors.kt index e0c627b61..46d1acd94 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/OpenShiftDescriptors.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/OpenShiftDescriptors.kt @@ -27,6 +27,7 @@ import io.fabric8.openshift.api.model.Build import io.fabric8.openshift.api.model.BuildConfig import io.fabric8.openshift.api.model.DeploymentConfig import io.fabric8.openshift.api.model.ImageStream +import io.fabric8.openshift.api.model.Route import javax.swing.Icon object OpenShiftDescriptors { @@ -48,7 +49,8 @@ object OpenShiftDescriptors { is DeploymentConfig, is ReplicationController, is BuildConfig, - is Build -> ResourceDescriptor(element as HasMetadata, childrenKind, parent, model, project) + is Build, + is Route -> ResourceDescriptor(element as HasMetadata, childrenKind, parent, model, project) else -> null } } diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/OpenShiftStructure.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/OpenShiftStructure.kt index 53efbaec2..78a740d44 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/OpenShiftStructure.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/OpenShiftStructure.kt @@ -22,7 +22,9 @@ import com.redhat.devtools.intellij.kubernetes.model.resource.openshift.Deployme import com.redhat.devtools.intellij.kubernetes.model.resource.openshift.ImageStreamsOperator import com.redhat.devtools.intellij.kubernetes.model.resource.openshift.ProjectsOperator import com.redhat.devtools.intellij.kubernetes.model.resource.openshift.ReplicationControllersOperator +import com.redhat.devtools.intellij.kubernetes.model.resource.openshift.RoutesOperator import com.redhat.devtools.intellij.kubernetes.model.resourceName +import com.redhat.devtools.intellij.kubernetes.tree.KubernetesStructure.Folders.NETWORK import com.redhat.devtools.intellij.kubernetes.tree.KubernetesStructure.Folders.WORKLOADS import com.redhat.devtools.intellij.kubernetes.tree.TreeStructure.Folder import io.fabric8.kubernetes.api.model.HasMetadata @@ -37,11 +39,13 @@ class OpenShiftStructure(model: IResourceModel): AbstractTreeStructureContributi val IMAGESTREAMS = Folder("ImageStreams", kind = ImageStreamsOperator.KIND) val DEPLOYMENTCONFIGS = Folder("DeploymentConfigs", kind = DeploymentConfigsOperator.KIND) val BUILDCONFIGS = Folder("BuildConfigs", kind = BuildConfigsOperator.KIND) + val ROUTES = Folder("Routes", kind = RoutesOperator.KIND) } override val elementsTree: List> = listOf( *createProjectsElements(), - *createWorkloadElements() + *createWorkloadElements(), + *createNetworkElements() ) private fun createProjectsElements(): Array> { @@ -134,6 +138,29 @@ class OpenShiftStructure(model: IResourceModel): AbstractTreeStructureContributi ) } + private fun createNetworkElements(): Array> { + return arrayOf( + element { + applicableIf { it == NETWORK } + children { + listOf( + ROUTES + ) + } + }, + element { + applicableIf { it == ROUTES } + childrenKind { RoutesOperator.KIND } + children { + model.resources(RoutesOperator.KIND) + .inCurrentNamespace() + .list() + .sortedBy(resourceName) + } + } + ) + } + override fun descriptorFactory(): (Any, ResourceKind?, NodeDescriptor<*>?, IResourceModel, com.intellij.openapi.project.Project) -> NodeDescriptor<*>? { return OpenShiftDescriptors::createDescriptor }