-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from Heylosky/member-cluster-api
ADD pod resource & routes to get member-cluster namespace/deployment/pod
- Loading branch information
Showing
11 changed files
with
344 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package router | ||
|
||
import ( | ||
"context" | ||
"github.com/gin-gonic/gin" | ||
"github.com/karmada-io/dashboard/cmd/api/app/types/common" | ||
"github.com/karmada-io/dashboard/pkg/client" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"net/http" | ||
) | ||
|
||
func EnsureMemberClusterMiddleware() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
karmadaClient := client.InClusterKarmadaClient() | ||
_, err := karmadaClient.ClusterV1alpha1().Clusters().Get(context.TODO(), c.Param("clustername"), metav1.GetOptions{}) | ||
if err != nil { | ||
c.AbortWithStatusJSON(http.StatusOK, common.BaseResponse{ | ||
Code: 500, | ||
Msg: err.Error(), | ||
}) | ||
return | ||
} | ||
c.Next() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package deployment | ||
|
||
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/deployment" | ||
"github.com/karmada-io/dashboard/pkg/resource/event" | ||
) | ||
|
||
func handleGetMemberDeployments(c *gin.Context) { | ||
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) | ||
namespace := common.ParseNamespacePathParameter(c) | ||
dataSelect := common.ParseDataSelectPathParameter(c) | ||
result, err := deployment.GetDeploymentList(memberClient, namespace, dataSelect) | ||
if err != nil { | ||
common.Fail(c, err) | ||
return | ||
} | ||
common.Success(c, result) | ||
} | ||
|
||
func handleGetMemberDeploymentDetail(c *gin.Context) { | ||
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) | ||
namespace := c.Param("namespace") | ||
name := c.Param("deployment") | ||
result, err := deployment.GetDeploymentDetail(memberClient, namespace, name) | ||
if err != nil { | ||
common.Fail(c, err) | ||
return | ||
} | ||
common.Success(c, result) | ||
} | ||
|
||
func handleGetMemberDeploymentEvents(c *gin.Context) { | ||
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) | ||
namespace := c.Param("namespace") | ||
name := c.Param("deployment") | ||
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("/deployment", handleGetMemberDeployments) | ||
r.GET("/deployment/:namespace", handleGetMemberDeployments) | ||
r.GET("/deployment/:namespace/:deployment", handleGetMemberDeploymentDetail) | ||
r.GET("/deployment/:namespace/:deployment/event", handleGetMemberDeploymentEvents) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package member | ||
|
||
// Importing member route packages forces route registration | ||
import ( | ||
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member/deployment" | ||
_ "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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package namespace | ||
|
||
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" | ||
ns "github.com/karmada-io/dashboard/pkg/resource/namespace" | ||
) | ||
|
||
func handleGetMemberNamespace(c *gin.Context) { | ||
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) | ||
|
||
dataSelect := common.ParseDataSelectPathParameter(c) | ||
result, err := ns.GetNamespaceList(memberClient, dataSelect) | ||
if err != nil { | ||
common.Fail(c, err) | ||
return | ||
} | ||
common.Success(c, result) | ||
} | ||
|
||
func handleGetMemberNamespaceDetail(c *gin.Context) { | ||
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) | ||
|
||
name := c.Param("name") | ||
result, err := ns.GetNamespaceDetail(memberClient, name) | ||
if err != nil { | ||
common.Fail(c, err) | ||
return | ||
} | ||
common.Success(c, result) | ||
} | ||
|
||
func handleGetMemberNamespaceEvents(c *gin.Context) { | ||
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) | ||
|
||
name := c.Param("name") | ||
dataSelect := common.ParseDataSelectPathParameter(c) | ||
result, err := event.GetNamespaceEvents(memberClient, dataSelect, name) | ||
if err != nil { | ||
common.Fail(c, err) | ||
return | ||
} | ||
common.Success(c, result) | ||
} | ||
|
||
func init() { | ||
r := router.MemberV1() | ||
r.GET("/namespace", handleGetMemberNamespace) | ||
r.GET("/namespace/:name", handleGetMemberNamespaceDetail) | ||
r.GET("/namespace/:name/event", handleGetMemberNamespaceEvents) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package pod | ||
|
||
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/pod" | ||
) | ||
|
||
// return a pods list | ||
func handleGetMemberPod(c *gin.Context) { | ||
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) | ||
dataSelect := common.ParseDataSelectPathParameter(c) | ||
nsQuery := common.ParseNamespacePathParameter(c) | ||
result, err := pod.GetPodList(memberClient, nsQuery, dataSelect) | ||
if err != nil { | ||
common.Fail(c, err) | ||
return | ||
} | ||
common.Success(c, result) | ||
} | ||
|
||
// return a pod detail | ||
func handleGetMemberPodDetail(c *gin.Context) { | ||
memberClient := client.InClusterClientForMemberCluster(c.Param("clustername")) | ||
namespace := c.Param("namespace") | ||
name := c.Param("name") | ||
result, err := pod.GetPodDetail(memberClient, namespace, name) | ||
if err != nil { | ||
common.Fail(c, err) | ||
return | ||
} | ||
common.Success(c, result) | ||
} | ||
|
||
func init() { | ||
r := router.MemberV1() | ||
r.GET("/pod", handleGetMemberPod) | ||
r.GET("/pod/:namespace", handleGetMemberPod) | ||
r.GET("/pod/:namespace/:name", handleGetMemberPodDetail) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package pod | ||
|
||
import ( | ||
"github.com/karmada-io/dashboard/pkg/dataselect" | ||
api "k8s.io/api/core/v1" | ||
) | ||
|
||
type PodCell api.Pod | ||
|
||
func (self PodCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { | ||
switch name { | ||
case dataselect.NameProperty: | ||
return dataselect.StdComparableString(self.ObjectMeta.Name) | ||
case dataselect.CreationTimestampProperty: | ||
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time) | ||
case dataselect.NamespaceProperty: | ||
return dataselect.StdComparableString(self.ObjectMeta.Namespace) | ||
default: | ||
// if name is not supported then just return a constant dummy value, sort will have no effect. | ||
return nil | ||
} | ||
} | ||
|
||
func toCells(std []api.Pod) []dataselect.DataCell { | ||
cells := make([]dataselect.DataCell, len(std)) | ||
for i := range std { | ||
cells[i] = PodCell(std[i]) | ||
} | ||
return cells | ||
} | ||
|
||
func fromCells(cells []dataselect.DataCell) []api.Pod { | ||
std := make([]api.Pod, len(cells)) | ||
for i := range std { | ||
std[i] = api.Pod(cells[i].(PodCell)) | ||
} | ||
return std | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package pod | ||
|
||
import ( | ||
"context" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
type PodDeatil struct { | ||
ObjectMeta metaV1.ObjectMeta `json:"objectMeta"` | ||
TypeMeta metaV1.TypeMeta `json:"typeMeta"` | ||
Spec v1.PodSpec `json:"podSpec"` | ||
Status v1.PodStatus `json:"status"` | ||
} | ||
|
||
// GetPodDetail returns a Pod detail | ||
func GetPodDetail(client kubernetes.Interface, namespace, name string) (*v1.Pod, error) { | ||
podData, err := client.CoreV1().Pods(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return podData, nil | ||
} |
Oops, something went wrong.