From 611dc04cfbcab35d11e8c8e7122e3197134fb156 Mon Sep 17 00:00:00 2001 From: petar-cvit Date: Sat, 21 Sep 2024 18:05:10 +0200 Subject: [PATCH] kind to resource --- .../internal/controller/sse/resources.go | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/cyclops-ctrl/internal/controller/sse/resources.go b/cyclops-ctrl/internal/controller/sse/resources.go index e4c00d7e..913d9fda 100644 --- a/cyclops-ctrl/internal/controller/sse/resources.go +++ b/cyclops-ctrl/internal/controller/sse/resources.go @@ -5,6 +5,8 @@ import ( "net/http" "time" + "github.com/pkg/errors" + "github.com/gin-gonic/gin" "k8s.io/apimachinery/pkg/runtime/schema" @@ -24,13 +26,7 @@ func (s *Server) Resources(ctx *gin.Context) { continue } - resourceName, err := s.k8sClient.GVKtoAPIResourceName( - schema.GroupVersion{ - Group: resource.GetGroup(), - Version: resource.GetVersion(), - }, - resource.GetKind(), - ) + resourceName, err := kindToResource(resource.GetKind()) if err != nil { ctx.String(http.StatusInternalServerError, err.Error()) return @@ -151,3 +147,16 @@ func (s *Server) SingleResource(ctx *gin.Context) { } }) } + +func kindToResource(kind string) (string, error) { + switch kind { + case "Deployment": + return "deployments", nil + case "StatefulSet": + return "statefulsets", nil + case "DaemonSet": + return "daemonsets", nil + default: + return "", errors.Errorf("kind %v is not a workload", kind) + } +}