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

feat(dashboard): add csi-node/mountpods for pods details page #1121

Merged
merged 1 commit into from
Sep 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions dashboard-ui-v2/src/components/pods-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { getPodStatusBadge, podStatus } from '@/utils'
const PodsTable: React.FC<{
title: string
source: 'pod' | 'pv' | 'pvc'
type: 'mountpods' | 'apppods'
type: 'mountpods' | 'apppods' | 'csi-nodes'
name: string
namespace?: string
}> = ({ title, source, type, namespace, name }) => {
Expand All @@ -45,7 +45,7 @@ const PodsTable: React.FC<{
render: (_, pod) => {
return (
<Link
to={`/pods/${pod.metadata?.namespace}/${pod.metadata?.name}`}
to={`/${type === 'apppods' ? 'pods' : 'syspods'}/${pod.metadata?.namespace}/${pod.metadata?.name}`}
>
{pod.metadata?.namespace}/{pod.metadata?.name}
</Link>
Expand Down
1 change: 1 addition & 0 deletions dashboard-ui-v2/src/components/resource-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function ResourcesDetail() {
const { resources, namespace, name } = useParams<DetailParams>()

switch (resources) {
case 'syspods':
case 'pods':
return <PodDetail namespace={namespace} name={name} />
case 'storageclass':
Expand Down
2 changes: 1 addition & 1 deletion dashboard-ui-v2/src/hooks/use-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function usePods(
namespace?: string,
name?: string,
source: 'pod' | 'pv' | 'pvc' = 'pod',
type: 'mountpods' | 'apppods' = 'apppods',
type: 'mountpods' | 'apppods' | 'csi-nodes' = 'apppods',
) {
return useSWR<Pod[]>(
source === 'pv'
Expand Down
6 changes: 3 additions & 3 deletions dashboard-ui-v2/src/pages/app-pod-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const columns: ProColumns<Pod>[] = [
color={getPodStatusBadge(podStatus(mountPod) || '')}
text={
<Link
to={`/pods/${mountPod?.metadata?.namespace}/${mountPod?.metadata?.name}/`}
to={`/syspods/${mountPod?.metadata?.namespace}/${mountPod?.metadata?.name}/`}
>
{mountPod?.metadata?.name}
</Link>
Expand All @@ -130,7 +130,7 @@ const columns: ProColumns<Pod>[] = [
color={getPodStatusBadge(podStatus(mountPod) || '')}
text={
<Link
to={`/pods/${mountPod.metadata?.namespace}/${mountPod.metadata?.name}/`}
to={`/syspods/${mountPod.metadata?.namespace}/${mountPod.metadata?.name}/`}
>
{mountPod?.metadata?.name}
</Link>
Expand Down Expand Up @@ -173,7 +173,7 @@ const columns: ProColumns<Pod>[] = [
color={getPodStatusBadge(podStatus(pod.csiNode) || '')}
text={
<Link
to={`/pods/${pod.csiNode.metadata?.namespace}/${pod.csiNode.metadata?.name}/`}
to={`/syspods/${pod.csiNode.metadata?.namespace}/${pod.csiNode.metadata?.name}/`}
>
{pod.csiNode.metadata?.name}
</Link>
Expand Down
7 changes: 7 additions & 0 deletions dashboard-ui-v2/src/pages/pod-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ const PodDetail: React.FC<{
namespace={namespace!}
name={name!}
/>
<PodsTable
title="CSI Node Pod"
source="pod"
type="csi-nodes"
namespace={namespace!}
name={name!}
/>
<EventTable source="pod" name={name!} namespace={namespace!} />
</PageContainer>
)
Expand Down
8 changes: 6 additions & 2 deletions dashboard-ui-v2/src/pages/sys-pod-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ const columns: ProColumns<Pod>[] = [
const podFailReason = failedReasonOfMountPod(pod) || ''
if (podFailReason === '') {
return (
<Link to={`/pods/${pod.metadata?.namespace}/${pod.metadata?.name}`}>
<Link
to={`/syspods/${pod.metadata?.namespace}/${pod.metadata?.name}`}
>
{pod.metadata?.name}
</Link>
)
}
const failReason = <FormattedMessage id={podFailReason} />
return (
<div>
<Link to={`/pods/${pod.metadata?.namespace}/${pod.metadata?.name}`}>
<Link
to={`/syspods/${pod.metadata?.namespace}/${pod.metadata?.name}`}
>
{pod.metadata?.name}
</Link>
<Tooltip title={failReason}>
Expand Down
1 change: 1 addition & 0 deletions pkg/dashboard/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (api *API) Handle(group *gin.RouterGroup) {
podGroup.GET("/pvcs", api.listPodPVCsHandler())
podGroup.GET("/mountpods", api.listMountPodsOfAppPod())
podGroup.GET("/apppods", api.listAppPodsOfMountPod())
podGroup.GET("/csi-nodes", api.listCSINodePod())
podGroup.GET("/node", api.getPodNode())
podGroup.GET("/downloadDebugFile", api.downloadDebugFile())
pvGroup := group.Group("/pv/:name", api.getPVMiddileware())
Expand Down
8 changes: 8 additions & 0 deletions pkg/dashboard/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down Expand Up @@ -116,6 +117,13 @@ func (c *PodController) SetupWithManager(mgr manager.Manager) error {
return err
}

if err := mgr.GetFieldIndexer().IndexField(context.Background(), &corev1.Pod{}, "spec.nodeName", func(rawObj client.Object) []string {
pod := rawObj.(*corev1.Pod)
return []string{pod.Spec.NodeName}
}); err != nil {
return err
}

return ctr.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForObject{}, predicate.Funcs{
CreateFunc: func(event event.CreateEvent) bool {
return true
Expand Down
45 changes: 45 additions & 0 deletions pkg/dashboard/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ func (api *API) listMountPod() gin.HandlerFunc {

func (api *API) listCSINodePod() gin.HandlerFunc {
return func(c *gin.Context) {
var targetPod *corev1.Pod
if v, ok := c.Get("pod"); ok {
targetPod = v.(*corev1.Pod)
}
if targetPod.Labels["app.kubernetes.io/name"] == "juicefs-csi-driver" {
return
}
var pods corev1.PodList
s, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: map[string]string{
Expand All @@ -291,8 +298,15 @@ func (api *API) listCSINodePod() gin.HandlerFunc {
c.String(500, "parse label selector error %v", err)
return
}
var fieldSelector fields.Selector
if targetPod != nil {
fieldSelector = fields.SelectorFromSet(fields.Set{
"spec.nodeName": targetPod.Spec.NodeName,
})
}
err = api.cachedReader.List(c, &pods, &client.ListOptions{
LabelSelector: s,
FieldSelector: fieldSelector,
})
if err != nil {
c.String(500, "list pods error %v", err)
Expand Down Expand Up @@ -523,6 +537,28 @@ func (api *API) listMountPodOf(ctx context.Context, pod *corev1.Pod) ([]*corev1.
return mountPods, nil
}

func (api *API) listMountPodOfCSINode(ctx context.Context, csiNode *corev1.Pod) ([]corev1.Pod, error) {
var mountPods corev1.PodList
s, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: map[string]string{
"app.kubernetes.io/name": "juicefs-mount",
},
})
if err != nil {
return nil, err
}
err = api.cachedReader.List(ctx, &mountPods, &client.ListOptions{
FieldSelector: fields.SelectorFromSet(fields.Set{
"spec.nodeName": csiNode.Spec.NodeName,
}),
LabelSelector: s,
})
if err != nil {
return nil, err
}
return mountPods.Items, nil
}

func (api *API) listMountPodsOfAppPod() gin.HandlerFunc {
return func(c *gin.Context) {
obj, ok := c.Get("pod")
Expand All @@ -531,6 +567,15 @@ func (api *API) listMountPodsOfAppPod() gin.HandlerFunc {
return
}
pod := obj.(*corev1.Pod)
if isCsiNode(pod) {
mountPods, err := api.listMountPodOfCSINode(c, pod)
if err != nil {
c.String(500, "list mount pods error %v", err)
return
}
c.IndentedJSON(200, mountPods)
return
}
pods, err := api.listMountPodOf(c, pod)
if err != nil {
c.String(500, "list mount pods error %v", err)
Expand Down
Loading