-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ns.go
46 lines (37 loc) · 1.1 KB
/
ns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package xray
import (
"context"
"fmt"
"github.com/derailed/k9s/internal/client"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)
// Namespace represents an xray renderer.
type Namespace struct{}
// Render renders an xray node.
func (n *Namespace) Render(ctx context.Context, ns string, o interface{}) error {
raw, ok := o.(*unstructured.Unstructured)
if !ok {
return fmt.Errorf("Expected NamespaceWithMetrics, but got %T", o)
}
var nss v1.Namespace
err := runtime.DefaultUnstructuredConverter.FromUnstructured(raw.Object, &nss)
if err != nil {
return err
}
root := NewTreeNode("v1/namespaces", client.FQN(client.ClusterScope, nss.Name))
parent, ok := ctx.Value(KeyParent).(*TreeNode)
if !ok {
return fmt.Errorf("Expecting a TreeNode but got %T", ctx.Value(KeyParent))
}
parent.Add(root)
return n.validate(root, nss)
}
func (*Namespace) validate(root *TreeNode, ns v1.Namespace) error {
root.Extras[StatusKey] = OkStatus
if ns.Status.Phase == v1.NamespaceTerminating {
root.Extras[StatusKey] = ToastStatus
}
return nil
}