Skip to content

Commit 87059e5

Browse files
authored
Merge pull request #1475 from prembhaskal/kctrl-list-new-msg-column
adding new column message in kctrl pkg installed list command
2 parents 3c008c1 + e99b02f commit 87059e5

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

cli/pkg/kctrl/cmd/package/installed/list.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/spf13/cobra"
1313
cmdcore "github.com/vmware-tanzu/carvel-kapp-controller/cli/pkg/kctrl/cmd/core"
1414
"github.com/vmware-tanzu/carvel-kapp-controller/cli/pkg/kctrl/logger"
15+
kcpkgv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/packaging/v1alpha1"
1516
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1617
)
1718

@@ -22,6 +23,7 @@ type ListOptions struct {
2223

2324
NamespaceFlags cmdcore.NamespaceFlags
2425
AllNamespaces bool
26+
Wide bool
2527

2628
pkgCmdTreeOpts cmdcore.PackageCommandTreeOpts
2729
}
@@ -49,6 +51,8 @@ func NewListCmd(o *ListOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comman
4951
}
5052
o.NamespaceFlags.SetWithPackageCommandTreeOpts(cmd, flagsFactory, o.pkgCmdTreeOpts)
5153
cmd.Flags().BoolVarP(&o.AllNamespaces, "all-namespaces", "A", false, "List installed packages in all namespaces")
54+
55+
cmd.Flags().BoolVar(&o.Wide, "wide", false, "show additional info")
5256
return cmd
5357
}
5458

@@ -74,6 +78,9 @@ func (o *ListOptions) Run() error {
7478
return err
7579
}
7680

81+
messageHeader := uitable.NewHeader("Message")
82+
messageHeader.Hidden = !o.Wide
83+
7784
table := uitable.Table{
7885
Title: tableTitle,
7986

@@ -83,6 +90,7 @@ func (o *ListOptions) Run() error {
8390
uitable.NewHeader("Package Name"),
8491
uitable.NewHeader("Package Version"),
8592
uitable.NewHeader("Status"),
93+
messageHeader,
8694
},
8795

8896
SortBy: []uitable.ColumnSort{
@@ -99,10 +107,20 @@ func (o *ListOptions) Run() error {
99107
uitable.NewValueString(pkgi.Spec.PackageRef.RefName),
100108
uitable.NewValueString(pkgi.Status.Version),
101109
uitable.ValueFmt{V: uitable.NewValueString(status), Error: isFailing},
110+
cmdcore.NewValueTruncated(uitable.NewValueString(o.getPkgiStatusMessage(&pkgi)), 50),
102111
})
103112
}
104113

105114
o.ui.PrintTable(table)
106115

107116
return nil
108117
}
118+
119+
func (o *ListOptions) getPkgiStatusMessage(pkgi *kcpkgv1alpha1.PackageInstall) string {
120+
conditionsLen := len(pkgi.Status.Conditions)
121+
if conditionsLen == 0 {
122+
return ""
123+
}
124+
lastCondition := pkgi.Status.Conditions[conditionsLen-1]
125+
return lastCondition.Message
126+
}

cli/test/e2e/package_install_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ key2: value2
138138
require.Exactly(t, expectedOutputRows, output.Tables[0].Rows)
139139
})
140140

141+
logger.Section("package installed list with one package installed with wide option", func() {
142+
out, err := kappCtrl.RunWithOpts([]string{"package", "installed", "list", "--wide", "--json"}, RunOpts{})
143+
require.NoError(t, err)
144+
145+
output := uitest.JSONUIFromBytes(t, []byte(out))
146+
147+
expectedOutputRows := []map[string]string{{
148+
"message": "",
149+
"name": "testpkgi",
150+
"package_name": "test-pkg.carvel.dev",
151+
"package_version": "1.0.0",
152+
"status": "Reconcile succeeded",
153+
}}
154+
require.Exactly(t, expectedOutputRows, output.Tables[0].Rows)
155+
})
156+
141157
logger.Section("package installed get", func() {
142158

143159
out, err := kappCtrl.RunWithOpts([]string{"package", "installed", "get", "--package-install", pkgiName, "--json"}, RunOpts{})
@@ -260,6 +276,36 @@ key2: value2
260276
require.Contains(t, err.Error(), "not found")
261277
})
262278

279+
logger.Section("Listing with error in package install", func() {
280+
incorrectValuesFile := `
281+
key1: value1:
282+
`
283+
_, err := kappCtrl.RunWithOpts([]string{"package", "installed", "create", "--package-install", pkgiName,
284+
"-p", packageMetadataName, "--version", packageVersion1,
285+
"--values-file", "-"}, RunOpts{
286+
StdinReader: strings.NewReader(incorrectValuesFile),
287+
AllowError: true,
288+
})
289+
require.Error(t, err)
290+
291+
out, err := kappCtrl.RunWithOpts([]string{"package", "installed", "list", "--wide", "--json"}, RunOpts{})
292+
require.NoError(t, err)
293+
294+
output := uitest.JSONUIFromBytes(t, []byte(out))
295+
296+
expectedOutputRows := []map[string]string{{
297+
"message": "Error (see .status.usefulErrorMessage for details)",
298+
"name": "testpkgi",
299+
"package_name": "test-pkg.carvel.dev",
300+
"package_version": "1.0.0",
301+
"status": "Reconcile failed",
302+
}}
303+
require.Exactly(t, expectedOutputRows, output.Tables[0].Rows)
304+
305+
_, err = kappCtrl.RunWithOpts([]string{"package", "installed", "delete", "--package-install", pkgiName}, RunOpts{})
306+
require.NoError(t, err)
307+
})
308+
263309
logger.Section("package installed update with missing old version", func() {
264310
kappCtrl.RunWithOpts([]string{"package", "installed", "create", "--package-install", pkgiName,
265311
"-p", packageMetadataName, "--version", packageVersion1,

0 commit comments

Comments
 (0)