-
Notifications
You must be signed in to change notification settings - Fork 92
/
flags.go
96 lines (86 loc) · 3.39 KB
/
flags.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
package preflight
import (
flag "github.com/spf13/pflag"
utilpointer "k8s.io/utils/ptr"
)
const (
flagInteractive = "interactive"
flagFormat = "format"
flagCollectorImage = "collector-image"
flagCollectorPullPolicy = "collector-pullpolicy"
flagCollectWithoutPermissions = "collect-without-permissions"
flagSelector = "selector"
flagSinceTime = "since-time"
flagSince = "since"
flagOutput = "output"
flagDebug = "debug"
)
type PreflightFlags struct {
Interactive *bool
Format *string
CollectorImage *string
CollectorPullPolicy *string
CollectWithoutPermissions *bool
Selector *string
SinceTime *string
Since *string
Output *string
Debug *bool
}
var preflightFlags *PreflightFlags
func NewPreflightFlags() *PreflightFlags {
return &PreflightFlags{
Interactive: utilpointer.To(true),
Format: utilpointer.To("human"),
CollectorImage: utilpointer.To(""),
CollectorPullPolicy: utilpointer.To(""),
CollectWithoutPermissions: utilpointer.To(true),
Selector: utilpointer.To(""),
SinceTime: utilpointer.To(""),
Since: utilpointer.To(""),
Output: utilpointer.To("o"),
Debug: utilpointer.To(false),
}
}
func AddFlags(flags *flag.FlagSet) {
if preflightFlags == nil {
preflightFlags = NewPreflightFlags()
}
preflightFlags.addFlags(flags)
}
// AddFlags binds client configuration flags to a given flagset
func (f *PreflightFlags) addFlags(flags *flag.FlagSet) {
if preflightFlags == nil {
preflightFlags = NewPreflightFlags()
}
if f.Interactive != nil {
flags.BoolVar(f.Interactive, flagInteractive, *f.Interactive, "interactive preflights")
}
if f.Format != nil {
flags.StringVar(f.Format, flagFormat, *f.Format, "output format, one of human, json, yaml. only used when interactive is set to false")
}
if f.CollectorImage != nil {
flags.StringVar(f.CollectorImage, flagCollectorImage, *f.CollectorImage, "the full name of the collector image to use")
}
if f.CollectorPullPolicy != nil {
flags.StringVar(f.CollectorPullPolicy, flagCollectorPullPolicy, *f.CollectorPullPolicy, "the pull policy of the collector image")
}
if f.CollectWithoutPermissions != nil {
flags.BoolVar(f.CollectWithoutPermissions, flagCollectWithoutPermissions, *f.CollectWithoutPermissions, "always run preflight checks even if some require permissions that preflight does not have")
}
if f.Selector != nil {
flags.StringVar(f.Selector, flagSelector, *f.Selector, "selector (label query) to filter remote collection nodes on.")
}
if f.SinceTime != nil {
flags.StringVar(f.SinceTime, flagSinceTime, *f.SinceTime, "force pod logs collectors to return logs after a specific date (RFC3339)")
}
if f.Since != nil {
flags.StringVar(f.Since, flagSince, *f.Since, "force pod logs collectors to return logs newer than a relative duration like 5s, 2m, or 3h.")
}
if f.Output != nil {
flags.StringVarP(f.Output, flagOutput, *f.Output, "", "specify the output file path for the preflight checks")
}
if f.Debug != nil {
flags.BoolVar(f.Debug, flagDebug, *f.Debug, "enable debug logging")
}
}