Skip to content

Commit ed21654

Browse files
committed
Add --show-source flag to flux get kustomization
Closes #2692 Signed-off-by: Rafael Peroco <rafaelperoco@gmail.com>
1 parent befe53a commit ed21654

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

cmd/flux/get_kustomization.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,22 @@ import (
3030
"github.com/fluxcd/flux2/v2/internal/utils"
3131
)
3232

33+
type getKustomizationFlags struct {
34+
showSource bool
35+
}
36+
37+
var getKsArgs getKustomizationFlags
38+
3339
var getKsCmd = &cobra.Command{
3440
Use: "kustomizations",
3541
Aliases: []string{"ks", "kustomization"},
3642
Short: "Get Kustomization statuses",
3743
Long: `The get kustomizations command prints the statuses of the resources.`,
3844
Example: ` # List all kustomizations and their status
39-
flux get kustomizations`,
45+
flux get kustomizations
46+
47+
# List all kustomizations with source information
48+
flux get kustomizations --show-source`,
4049
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
4150
RunE: func(cmd *cobra.Command, args []string) error {
4251
get := getCommand{
@@ -74,6 +83,7 @@ var getKsCmd = &cobra.Command{
7483
}
7584

7685
func init() {
86+
getKsCmd.Flags().BoolVar(&getKsArgs.showSource, "show-source", false, "show the source reference for each kustomization")
7787
getCmd.AddCommand(getKsCmd)
7888
}
7989

@@ -83,12 +93,27 @@ func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool, in
8393
status, msg := statusAndMessage(item.Status.Conditions)
8494
revision = utils.TruncateHex(revision)
8595
msg = utils.TruncateHex(msg)
86-
return append(nameColumns(&item, includeNamespace, includeKind),
96+
row := nameColumns(&item, includeNamespace, includeKind)
97+
if getKsArgs.showSource {
98+
sourceNs := item.Spec.SourceRef.Namespace
99+
if sourceNs == "" {
100+
sourceNs = item.GetNamespace()
101+
}
102+
row = append(row, fmt.Sprintf("%s/%s/%s",
103+
item.Spec.SourceRef.Kind,
104+
sourceNs,
105+
item.Spec.SourceRef.Name))
106+
}
107+
return append(row,
87108
revision, cases.Title(language.English).String(strconv.FormatBool(item.Spec.Suspend)), status, msg)
88109
}
89110

90111
func (a kustomizationListAdapter) headers(includeNamespace bool) []string {
91-
headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
112+
headers := []string{"Name"}
113+
if getKsArgs.showSource {
114+
headers = append(headers, "Source")
115+
}
116+
headers = append(headers, "Revision", "Suspended", "Ready", "Message")
92117
if includeNamespace {
93118
headers = append([]string{"Namespace"}, headers...)
94119
}

0 commit comments

Comments
 (0)