Skip to content

Commit

Permalink
Add a json output to velero backup describe
Browse files Browse the repository at this point in the history
Signed-off-by: allenxu404 <qix2@vmware.com>
  • Loading branch information
allenxu404 committed Feb 16, 2023
1 parent 5db9437 commit e569d11
Show file tree
Hide file tree
Showing 4 changed files with 538 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/5865-allenxu404
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a json output to cmd velero backup describe
22 changes: 18 additions & 4 deletions pkg/cmd/cli/backup/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
listOptions metav1.ListOptions
details bool
insecureSkipTLSVerify bool
outputFormat string
)

config, err := client.LoadConfig()
Expand All @@ -59,6 +60,10 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
kbClient, err := f.KubebuilderClient()
cmd.CheckError(err)

if outputFormat != "" && outputFormat != "json" {
cmd.CheckError(fmt.Errorf("Invalid argument '%s' for '--o'. Valid formats is 'json'", outputFormat))
}

var backups *velerov1api.BackupList
if len(args) > 0 {
backups = new(velerov1api.BackupList)
Expand Down Expand Up @@ -102,13 +107,21 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
}
}

s := output.DescribeBackup(context.Background(), kbClient, &backups.Items[i], deleteRequestList.Items, podVolumeBackupList.Items, vscList.Items, details, veleroClient, insecureSkipTLSVerify, caCertFile)
if first {
first = false
// `output` flag only applies to a single backup in case of OOM
// To describe the list of backups in structured format, users could iterate over the list and describe backup one after another.
if len(backups.Items) == 1 && outputFormat != "" {
s := output.DescribeBackupInSF(context.Background(), kbClient, &backups.Items[i], deleteRequestList.Items, podVolumeBackupList.Items, vscList.Items, details, veleroClient, insecureSkipTLSVerify, caCertFile, outputFormat)
fmt.Print(s)
} else {
fmt.Printf("\n\n%s", s)
s := output.DescribeBackup(context.Background(), kbClient, &backups.Items[i], deleteRequestList.Items, podVolumeBackupList.Items, vscList.Items, details, veleroClient, insecureSkipTLSVerify, caCertFile)
if first {
first = false
fmt.Print(s)
} else {
fmt.Printf("\n\n%s", s)
}
}

}
cmd.CheckError(err)
},
Expand All @@ -118,5 +131,6 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
c.Flags().BoolVar(&details, "details", details, "Display additional detail in the command output.")
c.Flags().BoolVar(&insecureSkipTLSVerify, "insecure-skip-tls-verify", insecureSkipTLSVerify, "If true, the object store's TLS certificate will not be checked for validity. This is insecure and susceptible to man-in-the-middle attacks. Not recommended for production.")
c.Flags().StringVar(&caCertFile, "cacert", caCertFile, "Path to a certificate bundle to use when verifying TLS connections.")
c.Flags().StringVar(&outputFormat, "o", outputFormat, "Output display format. Valid formats are 'json'. This flag only applies to a single backup")
return c
}
Loading

0 comments on commit e569d11

Please sign in to comment.