Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish the handler of the member cluster resources #155

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions cmd/api/app/routes/member/configmap/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package configmap

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/configmap"
)

func handleGetConfigMap(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
dataSelect := common.ParseDataSelectPathParameter(c)
nsQuery := common.ParseNamespacePathParameter(c)
result, err := configmap.GetConfigMapList(memberClient, nsQuery, dataSelect)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetConfigMapDetail(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := c.Param("namespace")
name := c.Param("name")
result, err := configmap.GetConfigMapDetail(memberClient, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func init() {
r := router.MemberV1()
r.GET("/configmap", handleGetConfigMap)
r.GET("/configmap/:namespace", handleGetConfigMap)
r.GET("/configmap/:namespace/:name", handleGetConfigMapDetail)
}
55 changes: 55 additions & 0 deletions cmd/api/app/routes/member/cronjob/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cronjob

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/cronjob"
"github.com/karmada-io/dashboard/pkg/resource/event"
)

func handleGetCronJob(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := common.ParseNamespacePathParameter(c)
dataSelect := common.ParseDataSelectPathParameter(c)
result, err := cronjob.GetCronJobList(memberClient, namespace, dataSelect)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetCronJobDetail(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := c.Param("namespace")
name := c.Param("cronjob")
result, err := cronjob.GetCronJobDetail(memberClient, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetCronJobEvents(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := c.Param("namespace")
name := c.Param("cronjob")
dataSelect := common.ParseDataSelectPathParameter(c)
result, err := event.GetResourceEvents(memberClient, dataSelect, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func init() {
r := router.MemberV1()
r.GET("/cronjob", handleGetCronJob)
r.GET("/cronjob/:namespace", handleGetCronJob)
r.GET("/cronjob/:namespace/:cronjob", handleGetCronJobDetail)
r.GET("/cronjob/:namespace/:cronjob/event", handleGetCronJobEvents)
}
55 changes: 55 additions & 0 deletions cmd/api/app/routes/member/daemonset/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package daemonset

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/daemonset"
"github.com/karmada-io/dashboard/pkg/resource/event"
)

func handleGetDaemonset(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := common.ParseNamespacePathParameter(c)
dataSelect := common.ParseDataSelectPathParameter(c)
result, err := daemonset.GetDaemonSetList(memberClient, namespace, dataSelect)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetDaemonsetDetail(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := c.Param("namespace")
name := c.Param("daemonset")
result, err := daemonset.GetDaemonSetDetail(memberClient, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetDaemonsetEvents(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := c.Param("namespace")
name := c.Param("daemonset")
dataSelect := common.ParseDataSelectPathParameter(c)
result, err := event.GetResourceEvents(memberClient, dataSelect, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func init() {
r := router.MemberV1()
r.GET("/daemonset", handleGetDaemonset)
r.GET("/daemonset/:namespace", handleGetDaemonset)
r.GET("/daemonset/:namespace/:daemonset", handleGetDaemonsetDetail)
r.GET("/daemonset/:namespace/:daemonset/event", handleGetDaemonsetEvents)
}
40 changes: 40 additions & 0 deletions cmd/api/app/routes/member/ingress/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ingress

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/ingress"
)

func handleGetIngress(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
dataSelect := common.ParseDataSelectPathParameter(c)
nsQuery := common.ParseNamespacePathParameter(c)
result, err := ingress.GetIngressList(memberClient, nsQuery, dataSelect)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetIngressDetail(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := c.Param("namespace")
name := c.Param("ingress")
result, err := ingress.GetIngressDetail(memberClient, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func init() {
r := router.MemberV1()
r.GET("/ingress", handleGetIngress)
r.GET("/ingress/:namespace", handleGetIngress)
r.GET("/ingress/:namespace/:ingress", handleGetIngressDetail)
}
55 changes: 55 additions & 0 deletions cmd/api/app/routes/member/job/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package job

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/event"
"github.com/karmada-io/dashboard/pkg/resource/job"
)

func handleGetJob(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := common.ParseNamespacePathParameter(c)
dataSelect := common.ParseDataSelectPathParameter(c)
result, err := job.GetJobList(memberClient, namespace, dataSelect)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetJobDetail(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := c.Param("namespace")
name := c.Param("job")
result, err := job.GetJobDetail(memberClient, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetJobEvents(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := c.Param("namespace")
name := c.Param("job")
dataSelect := common.ParseDataSelectPathParameter(c)
result, err := event.GetResourceEvents(memberClient, dataSelect, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func init() {
r := router.MemberV1()
r.GET("/job", handleGetJob)
r.GET("/job/:namespace", handleGetJob)
r.GET("/job/:namespace/:job", handleGetJobDetail)
r.GET("/job/:namespace/:job/event", handleGetJobEvents)
}
8 changes: 8 additions & 0 deletions cmd/api/app/routes/member/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ package member

// Importing member route packages forces route registration
import (
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/configmap"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/cronjob"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/daemonset"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/deployment"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/ingress"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/job"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/namespace"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/node"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/pod"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/secret"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/service"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/statefulset"
)
40 changes: 40 additions & 0 deletions cmd/api/app/routes/member/secret/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package secret

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/secret"
)

func handleGetSecrets(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
dataSelect := common.ParseDataSelectPathParameter(c)
nsQuery := common.ParseNamespacePathParameter(c)
result, err := secret.GetSecretList(memberClient, nsQuery, dataSelect)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func handleGetSecretDetail(c *gin.Context) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
namespace := c.Param("namespace")
name := c.Param("secret")
result, err := secret.GetSecretDetail(memberClient, namespace, name)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

func init() {
r := router.MemberV1()
r.GET("/secret", handleGetSecrets)
r.GET("/secret/:namespace", handleGetSecrets)
r.GET("/secret/:namespace/:secret", handleGetSecretDetail)
}
54 changes: 54 additions & 0 deletions cmd/api/app/routes/member/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) {
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername"))
dataSelect := common.ParseDataSelectPathParameter(c)
nsQuery := common.ParseNamespacePathParameter(c)
result, err := service.GetServiceList(memberClient, nsQuery, dataSelect)
if err != nil {
common.Fail(c, err)
return
}
common.Success(c, result)
}

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

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

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