-
Notifications
You must be signed in to change notification settings - Fork 24
/
agent.go
114 lines (105 loc) · 2.77 KB
/
agent.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package cmd
import (
"fmt"
"io/ioutil"
"log"
"time"
"github.com/jetstack/preflight/pkg/agent"
"github.com/jetstack/preflight/pkg/permissions"
"github.com/spf13/cobra"
)
var agentCmd = &cobra.Command{
Use: "agent",
Short: "start the preflight agent",
Long: `The agent will periodically gather data for the configured data
gatherers and send it to a remote backend for evaluation`,
Run: agent.Run,
}
var agentInfoCmd = &cobra.Command{
Use: "info",
Short: "print several internal parameters of the agent",
Long: `Print several internal parameters of the agent, as the built-in OAuth2 client ID.`,
Run: func(cmd *cobra.Command, args []string) {
printVersion(true)
fmt.Println()
printOAuth2Config()
},
}
var agentRBACCmd = &cobra.Command{
Use: "rbac",
Short: "print the agent's minimal RBAC manifest",
Long: `Print RBAC string by reading GVRs`,
Run: func(cmd *cobra.Command, args []string) {
b, err := ioutil.ReadFile(agent.ConfigFilePath)
if err != nil {
log.Fatalf("Failed to read config file: %s", err)
}
config, err := agent.ParseConfig(b)
if err != nil {
log.Fatalf("Failed to parse config file: %s", err)
}
out := permissions.GenerateFullManifest(config.DataGatherers)
fmt.Print(out)
},
}
func init() {
rootCmd.AddCommand(agentCmd)
agentCmd.AddCommand(agentInfoCmd)
agentCmd.AddCommand(agentRBACCmd)
agentCmd.PersistentFlags().StringVarP(
&agent.ConfigFilePath,
"agent-config-file",
"c",
"./agent.yaml",
"Config file location, default is `agent.yaml` in the current working directory.",
)
agentCmd.PersistentFlags().DurationVarP(
&agent.Period,
"period",
"p",
0,
"Override time between scans in the configuration file (given as XhYmZs).",
)
agentCmd.PersistentFlags().StringVarP(
&agent.CredentialsPath,
"credentials-file",
"k",
"",
"Location of the credentials file. For OAuth2 based authentication.",
)
agentCmd.PersistentFlags().BoolVarP(
&agent.OneShot,
"one-shot",
"",
false,
"Runs agent a single time if true, or continously if false",
)
agentCmd.PersistentFlags().StringVarP(
&agent.OutputPath,
"output-path",
"",
"",
"Output file path, if used, it will write data to a local file instead of uploading to the preflight server",
)
agentCmd.PersistentFlags().StringVarP(
&agent.InputPath,
"input-path",
"",
"",
"Input file path, if used, it will read data from a local file instead of gathering data from clusters",
)
agentCmd.PersistentFlags().DurationVarP(
&agent.BackoffMaxTime,
"backoff-max-time",
"",
10*time.Minute,
"Max time for retrying failed data gatherers (given as XhYmZs).",
)
agentCmd.PersistentFlags().BoolVarP(
&agent.StrictMode,
"strict",
"",
false,
"Runs agent in strict mode. No retry attempts will be made for a missing data gatherer's data.",
)
}