Skip to content

Commit

Permalink
kind to resource
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-cvit committed Sep 21, 2024
1 parent 183f818 commit 611dc04
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cyclops-ctrl/internal/controller/sse/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"net/http"
"time"

"github.com/pkg/errors"

"github.com/gin-gonic/gin"
"k8s.io/apimachinery/pkg/runtime/schema"

Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 611dc04

Please sign in to comment.