Skip to content

Commit

Permalink
feat: add api for service management
Browse files Browse the repository at this point in the history
Signed-off-by: warjiang <1096409085@qq.com>
  • Loading branch information
warjiang committed Sep 9, 2024
1 parent f4cca3d commit 166891c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/api/app/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/overview"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/propagationpolicy"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/secret"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/service"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/statefulset"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/unstructured"
)
Expand Down
54 changes: 54 additions & 0 deletions cmd/api/app/routes/service/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package service

import (
"github.com/gin-gonic/gin"
"github.com/karmada-io/dashboard/cmd/api/app/router"
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"github.com/karmada-io/dashboard/pkg/client"
"github.com/karmada-io/dashboard/pkg/resource/service"
)

func handleGetServices(c *gin.Context) {
k8sClient := client.InClusterClientForKarmadaApiServer()
dataSelect := common.ParseDataSelectPathParameter(c)
nsQuery := common.ParseNamespacePathParameter(c)
result, err := service.GetServiceList(k8sClient, nsQuery, dataSelect)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetServiceDetail(c *gin.Context) {
k8sClient := client.InClusterClientForKarmadaApiServer()
namespace := c.Param("namespace")
name := c.Param("service")
result, err := service.GetServiceDetail(k8sClient, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetServiceEvents(c *gin.Context) {
k8sClient := client.InClusterClientForKarmadaApiServer()
namespace := c.Param("namespace")
name := c.Param("service")
dataSelect := common.ParseDataSelectPathParameter(c)
result, err := service.GetServiceEvents(k8sClient, dataSelect, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func init() {
r := router.V1()
r.GET("/service", handleGetServices)
r.GET("/service/:namespace", handleGetServices)
r.GET("/service/:namespace/:service", handleGetServiceDetail)
r.GET("/service/:namespace/:service/event", handleGetServiceEvents)
}

0 comments on commit 166891c

Please sign in to comment.