-
Notifications
You must be signed in to change notification settings - Fork 110
/
inspect_view.go
101 lines (84 loc) · 2.4 KB
/
inspect_view.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2024 The Carvel Authors.
// SPDX-License-Identifier: Apache-2.0
package tools
import (
"fmt"
"github.com/cppforlife/go-cli-ui/ui"
uitable "github.com/cppforlife/go-cli-ui/ui/table"
ctlcap "github.com/vmware-tanzu/carvel-kapp/pkg/kapp/clusterapply"
cmdcore "github.com/vmware-tanzu/carvel-kapp/pkg/kapp/cmd/core"
ctlres "github.com/vmware-tanzu/carvel-kapp/pkg/kapp/resources"
)
type InspectView struct {
Source string
Resources []ctlres.Resource
Sort bool
}
func (v InspectView) Print(ui ui.UI) {
versionHeader := uitable.NewHeader("Version")
versionHeader.Hidden = true
reconcileStateHeader := uitable.NewHeader("Reconcile state")
reconcileStateHeader.Title = "Rs"
reconcileInfoHeader := uitable.NewHeader("Reconcile info")
reconcileInfoHeader.Title = "Ri"
table := uitable.Table{
Title: fmt.Sprintf("Resources in %s", v.Source),
Content: "resources",
Header: []uitable.Header{
uitable.NewHeader("Namespace"),
uitable.NewHeader("Name"),
uitable.NewHeader("Kind"),
versionHeader,
uitable.NewHeader("Owner"),
reconcileStateHeader,
reconcileInfoHeader,
uitable.NewHeader("Age"),
},
Notes: []string{"Rs: Reconcile state", "Ri: Reconcile information"},
}
if v.Sort {
table.SortBy = []uitable.ColumnSort{
{Column: 0, Asc: true},
{Column: 1, Asc: true},
{Column: 2, Asc: true},
{Column: 3, Asc: true},
}
} else {
// Otherwise it might look very awkward
table.FillFirstColumn = true
}
for _, resource := range v.Resources {
row := []uitable.Value{
cmdcore.NewValueNamespace(resource.Namespace()),
uitable.NewValueString(resource.Name()),
uitable.NewValueString(resource.Kind()),
uitable.NewValueString(resource.APIVersion()),
NewValueResourceOwner(resource),
}
if resource.IsProvisioned() {
syncVal := ctlcap.NewValueResourceConverged(resource)
row = append(row,
syncVal.StateVal,
syncVal.ReasonVal,
cmdcore.NewValueAge(resource.CreatedAt()),
)
} else {
row = append(row,
uitable.NewValueString(""),
uitable.NewValueString(""),
uitable.NewValueString(""),
)
}
table.Rows = append(table.Rows, row)
}
ui.PrintTable(table)
}
func NewValueResourceOwner(resource ctlres.Resource) uitable.ValueString {
if resource.IsProvisioned() {
if resource.Transient() {
return uitable.NewValueString("cluster")
}
return uitable.NewValueString("kapp")
}
return uitable.NewValueString("")
}