mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
fix resource filter for generic printers on get
This commit is contained in:
parent
d94bc9ef85
commit
799a0bf410
@ -18,7 +18,9 @@ package kubectl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
)
|
)
|
||||||
@ -50,6 +52,27 @@ func filterPods(obj runtime.Object, options printers.PrintOptions) bool {
|
|||||||
return p.Status.Phase == v1.PodSucceeded || p.Status.Phase == v1.PodFailed
|
return p.Status.Phase == v1.PodSucceeded || p.Status.Phase == v1.PodFailed
|
||||||
case *api.Pod:
|
case *api.Pod:
|
||||||
return p.Status.Phase == api.PodSucceeded || p.Status.Phase == api.PodFailed
|
return p.Status.Phase == api.PodSucceeded || p.Status.Phase == api.PodFailed
|
||||||
|
case *unstructured.Unstructured:
|
||||||
|
if (p.GroupVersionKind().GroupKind() != schema.GroupKind{Kind: "Pod"}) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
status, ok := p.Object["status"]
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
statusMap, ok := status.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
phase, ok := statusMap["phase"]
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
phaseString, ok := phase.(string)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return phaseString == string(api.PodSucceeded) || phaseString == string(api.PodFailed)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user