Skip to content

Commit

Permalink
dashboard: fix app pod should be list
Browse files Browse the repository at this point in the history
Signed-off-by: zwwhdls <[email protected]>
  • Loading branch information
zwwhdls committed Jul 16, 2024
1 parent 8000ecb commit 45dc114
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/dashboard/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *PodController) Reconcile(ctx context.Context, req reconcile.Request) (r
klog.Errorf("get pod %s failed: %v", req.NamespacedName, err)
return reconcile.Result{}, nil
}
if !isSysPod(pod) && !isAppPod(pod) && !c.isAppPodPending(pod) {
if !isSysPod(pod) && !isAppPod(pod) && !c.isAppPodShouldList(ctx, pod) {
// skip
return reconcile.Result{}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dashboard/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (api *API) listAppPod() gin.HandlerFunc {
if err := api.cachedReader.Get(c, name, &pod); err == nil &&
(nameFilter == "" || strings.Contains(pod.Name, nameFilter)) &&
(namespaceFilter == "" || strings.Contains(pod.Namespace, namespaceFilter)) &&
(isAppPod(&pod) || api.isAppPodPending(&pod)) {
(isAppPod(&pod) || api.isAppPodShouldList(c, &pod)) {
pods = append(pods, &PodExtra{Pod: &pod})
}
}
Expand Down Expand Up @@ -354,7 +354,7 @@ func (api *API) getPodMiddileware() gin.HandlerFunc {
} else if err != nil {
c.String(500, "get pod error %v", err)
return
} else if !isAppPod(&pod) && !isSysPod(&pod) && !api.isAppPodPending(&pod) {
} else if !isAppPod(&pod) && !isSysPod(&pod) && !api.isAppPodShouldList(c, &pod) {
c.String(404, "not found")
return
}
Expand Down
25 changes: 21 additions & 4 deletions pkg/dashboard/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package dashboard

import (
"context"
"sort"

"github.com/juicedata/juicefs-csi-driver/pkg/config"
Expand Down Expand Up @@ -45,14 +46,30 @@ func isAppPod(pod *corev1.Pod) bool {
return false
}

func (api *API) isAppPodPending(pod *corev1.Pod) bool {
usingPVC := false
func (api *API) isAppPodShouldList(ctx context.Context, pod *corev1.Pod) bool {
for _, volume := range pod.Spec.Volumes {
if volume.PersistentVolumeClaim != nil {
usingPVC = true
var pvc corev1.PersistentVolumeClaim
if err := api.cachedReader.Get(ctx, types.NamespacedName{Name: volume.PersistentVolumeClaim.ClaimName, Namespace: pod.Namespace}, &pvc); err != nil {
return false
}

if pvc.Spec.VolumeName == "" {
// pvc not bound
// Can't tell whether it is juicefs pvc, so list it as well.
return true
}

var pv corev1.PersistentVolume
if err := api.cachedReader.Get(ctx, types.NamespacedName{Name: pvc.Spec.VolumeName}, &pv); err != nil {
return false
}
if pv.Spec.CSI != nil && pv.Spec.CSI.Driver == config.DriverName {
return true
}
}
}
return usingPVC && pod.Status.Phase == corev1.PodPending
return false
}

func isSysPod(pod *corev1.Pod) bool {
Expand Down

0 comments on commit 45dc114

Please sign in to comment.