-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflags.go
51 lines (42 loc) · 1.64 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
package main
import (
"errors"
"flag"
)
// flags represents the flags to parse from the command line
type flags struct {
crictlConfig string
kubeConfig string
masterURL string
metricsAddress string
nodeName string
runtimeEndpoint string
}
// parseFlags parses flags from the command line
func parseFlags() (*flags, error) {
var config flags
flag.StringVar(&config.crictlConfig, "crictl-config", "/etc/crictl.yaml", "The location of the crictl.yaml file, usually /etc/crictl.yaml. Not used if --runtime-endpoint is set.")
flag.StringVar(&config.kubeConfig, "kube-config", "", "Path to a kubeconfig.")
flag.StringVar(&config.masterURL, "master-url", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig.")
flag.StringVar(&config.metricsAddress, "metrics-listen-address", ":9091", "Metrics server listen address, either address:port or :port.")
flag.StringVar(&config.nodeName, "node-name", "", "The node the daemon is running on.")
flag.StringVar(&config.runtimeEndpoint, "runtime-endpoint", "", "The runtime endpoint to use, e.g. unix:///run/containerd/containerd.sock.")
flag.Parse()
err := validateFlags(config)
if err != nil {
return nil, err
}
return &config, nil
}
// validateFlags performs basic error checking on parsed flags
func validateFlags(config flags) error {
// Make sure current node is supplied
if config.nodeName == "" {
return errors.New("--node-name must be supplied")
}
// Make sure runtime endpoint is supplied
if config.crictlConfig == "" && config.runtimeEndpoint == "" {
return errors.New("--crictl-config or --runtime-endpoint must be supplied")
}
return nil
}