From dc64b07db7a458ee25e1fe4d143f4253d2e95fbb Mon Sep 17 00:00:00 2001 From: Heylosky <2547226479@qq.com> Date: Wed, 11 Dec 2024 17:12:10 +0800 Subject: [PATCH] add more resources for member cluster Signed-off-by: Heylosky <2547226479@qq.com> --- .../app/routes/member/configmap/handler.go | 40 ++++++++++++++ cmd/api/app/routes/member/cronjob/handler.go | 55 +++++++++++++++++++ .../app/routes/member/daemonset/handler.go | 55 +++++++++++++++++++ cmd/api/app/routes/member/ingress/handler.go | 40 ++++++++++++++ cmd/api/app/routes/member/job/handler.go | 55 +++++++++++++++++++ cmd/api/app/routes/member/member.go | 8 +++ cmd/api/app/routes/member/secret/handler.go | 40 ++++++++++++++ cmd/api/app/routes/member/service/handler.go | 54 ++++++++++++++++++ .../app/routes/member/statefulset/handler.go | 55 +++++++++++++++++++ 9 files changed, 402 insertions(+) create mode 100644 cmd/api/app/routes/member/configmap/handler.go create mode 100644 cmd/api/app/routes/member/cronjob/handler.go create mode 100644 cmd/api/app/routes/member/daemonset/handler.go create mode 100644 cmd/api/app/routes/member/ingress/handler.go create mode 100644 cmd/api/app/routes/member/job/handler.go create mode 100644 cmd/api/app/routes/member/secret/handler.go create mode 100644 cmd/api/app/routes/member/service/handler.go create mode 100644 cmd/api/app/routes/member/statefulset/handler.go diff --git a/cmd/api/app/routes/member/configmap/handler.go b/cmd/api/app/routes/member/configmap/handler.go new file mode 100644 index 00000000..a3705779 --- /dev/null +++ b/cmd/api/app/routes/member/configmap/handler.go @@ -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) +} diff --git a/cmd/api/app/routes/member/cronjob/handler.go b/cmd/api/app/routes/member/cronjob/handler.go new file mode 100644 index 00000000..1d6d79c1 --- /dev/null +++ b/cmd/api/app/routes/member/cronjob/handler.go @@ -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) +} diff --git a/cmd/api/app/routes/member/daemonset/handler.go b/cmd/api/app/routes/member/daemonset/handler.go new file mode 100644 index 00000000..210c7bc3 --- /dev/null +++ b/cmd/api/app/routes/member/daemonset/handler.go @@ -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) +} diff --git a/cmd/api/app/routes/member/ingress/handler.go b/cmd/api/app/routes/member/ingress/handler.go new file mode 100644 index 00000000..51684f6e --- /dev/null +++ b/cmd/api/app/routes/member/ingress/handler.go @@ -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) +} diff --git a/cmd/api/app/routes/member/job/handler.go b/cmd/api/app/routes/member/job/handler.go new file mode 100644 index 00000000..d21c02af --- /dev/null +++ b/cmd/api/app/routes/member/job/handler.go @@ -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) +} diff --git a/cmd/api/app/routes/member/member.go b/cmd/api/app/routes/member/member.go index 96fa644d..453ff0fe 100644 --- a/cmd/api/app/routes/member/member.go +++ b/cmd/api/app/routes/member/member.go @@ -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" ) diff --git a/cmd/api/app/routes/member/secret/handler.go b/cmd/api/app/routes/member/secret/handler.go new file mode 100644 index 00000000..02c4b334 --- /dev/null +++ b/cmd/api/app/routes/member/secret/handler.go @@ -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) +} diff --git a/cmd/api/app/routes/member/service/handler.go b/cmd/api/app/routes/member/service/handler.go new file mode 100644 index 00000000..6a9c7dd8 --- /dev/null +++ b/cmd/api/app/routes/member/service/handler.go @@ -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) +} diff --git a/cmd/api/app/routes/member/statefulset/handler.go b/cmd/api/app/routes/member/statefulset/handler.go new file mode 100644 index 00000000..01bdf48f --- /dev/null +++ b/cmd/api/app/routes/member/statefulset/handler.go @@ -0,0 +1,55 @@ +package statefulset + +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/statefulset" +) + +func handleGetStatefulsets(c *gin.Context) { + memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) + namespace := common.ParseNamespacePathParameter(c) + dataSelect := common.ParseDataSelectPathParameter(c) + result, err := statefulset.GetStatefulSetList(memberClient, namespace, dataSelect) + if err != nil { + common.Fail(c, err) + return + } + common.Success(c, result) +} + +func handleGetStatefulsetDetail(c *gin.Context) { + memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) + namespace := c.Param("namespace") + name := c.Param("statefulset") + result, err := statefulset.GetStatefulSetDetail(memberClient, namespace, name) + if err != nil { + common.Fail(c, err) + return + } + common.Success(c, result) +} + +func handleGetStatefulsetEvents(c *gin.Context) { + memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) + namespace := c.Param("namespace") + name := c.Param("statefulset") + 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("/statefulset", handleGetStatefulsets) + r.GET("/statefulset/:namespace", handleGetStatefulsets) + r.GET("/statefulset/:namespace/:statefulset", handleGetStatefulsetDetail) + r.GET("/statefulset/:namespace/:statefulset/event", handleGetStatefulsetEvents) +}