forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
89 lines (81 loc) · 2.4 KB
/
get.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
package cron
import (
"encoding/json"
"fmt"
"log"
"os"
"strings"
"github.com/argoproj/pkg/humanize"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
)
func NewGetCommand() *cobra.Command {
var (
output string
)
var command = &cobra.Command{
Use: "get CRON_WORKFLOW",
Short: "display details about a cron workflow",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}
cronWfClient := InitCronWorkflowClient()
for _, arg := range args {
wftmpl, err := cronWfClient.Get(arg, metav1.GetOptions{})
if err != nil {
log.Fatal(err)
}
printCronWorkflow(wftmpl, output)
}
},
}
command.Flags().StringVarP(&output, "output", "o", "", "Output format. One of: json|yaml|wide")
return command
}
func printCronWorkflow(wf *wfv1.CronWorkflow, outFmt string) {
switch outFmt {
case "name":
fmt.Println(wf.ObjectMeta.Name)
case "json":
outBytes, _ := json.MarshalIndent(wf, "", " ")
fmt.Println(string(outBytes))
case "yaml":
outBytes, _ := yaml.Marshal(wf)
fmt.Print(string(outBytes))
case "wide", "":
printCronWorkflowTemplate(wf, outFmt)
default:
log.Fatalf("Unknown output format: %s", outFmt)
}
}
func printCronWorkflowTemplate(wf *wfv1.CronWorkflow, outFmt string) {
const fmtStr = "%-30s %v\n"
fmt.Printf(fmtStr, "Name:", wf.ObjectMeta.Name)
fmt.Printf(fmtStr, "Namespace:", wf.ObjectMeta.Namespace)
fmt.Printf(fmtStr, "Created:", humanize.Timestamp(wf.ObjectMeta.CreationTimestamp.Time))
fmt.Printf(fmtStr, "Schedule:", wf.Spec.Schedule)
fmt.Printf(fmtStr, "Suspended:", wf.Spec.Suspend)
if wf.Spec.Timezone != "" {
fmt.Printf(fmtStr, "Timezone:", wf.Spec.Timezone)
}
if wf.Spec.StartingDeadlineSeconds != nil {
fmt.Printf(fmtStr, "StartingDeadlineSeconds:", *wf.Spec.StartingDeadlineSeconds)
}
if wf.Spec.ConcurrencyPolicy != "" {
fmt.Printf(fmtStr, "ConcurrencyPolicy:", wf.Spec.ConcurrencyPolicy)
}
if wf.Status.LastScheduledTime != nil {
fmt.Printf(fmtStr, "LastScheduledTime:", humanize.Timestamp(wf.Status.LastScheduledTime.Time))
}
if len(wf.Status.Active) > 0 {
var activeWfNames []string
for _, activeWf := range wf.Status.Active {
activeWfNames = append(activeWfNames, activeWf.Name)
}
fmt.Printf(fmtStr, "Active Workflows:", strings.Join(activeWfNames, ", "))
}
}