-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
122 lines (113 loc) · 3.25 KB
/
main.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
115
116
117
118
119
120
121
122
package main
import (
"fmt"
"log"
"os"
"github.com/target/impeller/types"
"github.com/target/impeller/utils"
"github.com/target/impeller/utils/report"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "addon-manager"
app.Action = run
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "cluster-config-path",
Usage: "Path to the cluster config",
EnvVar: "CLUSTER_CONFIG,PLUGIN_CLUSTER_CONFIG,PARAMETER_CLUSTER_CONFIG",
},
cli.StringSliceFlag{
Name: "value-files",
Usage: "Helm value override files",
EnvVar: "VALUE_FILES,PLUGIN_VALUE_FILES,PARAMETER_VALUE_FILES",
},
cli.StringFlag{
Name: "kube-config",
Usage: "Kubernetes configuration file",
EnvVar: "KUBE_CONFIG,PLUGIN_KUBE_CONFIG,PARAMETER_KUBE_CONFIG",
},
cli.BoolFlag{
Name: "kube-config-base64",
Usage: "Flag true/false, base64 encoded kubeconfig",
EnvVar: "KUBE_CONFIG_BASE64,PLUGIN_KUBE_CONFIG_BASE64,PARAMETER_KUBE_CONFIG_BASE64",
},
cli.StringFlag{
Name: "kube-context",
Usage: "Kubernetes configuration context to use",
EnvVar: "KUBE_CONTEXT,PLUGIN_KUBE_CONTEXT,PARAMETER_KUBE_CONTEXT",
},
cli.BoolFlag{
Name: "dry-run",
Usage: "Enables a dry_run deployment",
EnvVar: "DRY_RUN,PLUGIN_DRY_RUN,PARAMETER_DRY_RUN",
},
cli.BoolFlag{
Name: "diff-run",
Usage: "compares upgrade changes deployment",
EnvVar: "DIFF_RUN,PLUGIN_DIFF_RUN,PARAMETER_DIFF_RUN",
},
cli.BoolFlag{
Name: "audit",
Usage: "create audit report",
EnvVar: "AUDIT_RUN,PLUGIN_AUDIT_RUN,PARAMETER_AUDIT_RUN",
},
cli.StringFlag{
Name: "audit-file",
Usage: "audit report file name",
EnvVar: "AUDIT_FILE_NAME,PLUGIN_AUDIT_FILE_NAME,PARAMETER_AUDIT_FILE_NAME",
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func run(ctx *cli.Context) error {
var clusterConfig types.ClusterConfig
var clist report.Clusters
var auditReportFileName string
var err error
if ctx.String("cluster-config-path") == "" {
return fmt.Errorf("Cluster config path not set.")
}
if os.Getenv("DRONE") == "true" {
if ctx.String("kube-config") == "" {
return fmt.Errorf("Kube config not set.")
}
if ctx.String("kube-context") == "" {
return fmt.Errorf("Kube context not set.")
}
}
if ctx.Bool("audit") {
if ctx.String("audit-file") == "" {
auditReportFileName = "./auditreport.csv"
} else {
auditReportFileName = ctx.String("audit-file")
}
clist, err = utils.ListClusters(ctx.String("cluster-config-path"))
if err != nil {
return fmt.Errorf("Error reading cluster config: %v", err)
}
} else {
clusterConfig, err = utils.ReadClusterConfig(ctx.String("cluster-config-path"))
if err != nil {
return fmt.Errorf("Error reading cluster config: %v", err)
}
}
plugin := Plugin{
ClusterConfig: clusterConfig,
ClusterConfigPath: ctx.String("cluster-config-path"),
ClustersList: clist,
ValueFiles: ctx.StringSlice("value-files"),
KubeConfig: ctx.String("kube-config"),
KubeConfigBase64: ctx.Bool("kube-config-base64"),
KubeContext: ctx.String("kube-context"),
Dryrun: ctx.Bool("dry-run"),
Diffrun: ctx.Bool("diff-run"),
Audit: ctx.Bool("audit"),
AuditFile: auditReportFileName,
}
return plugin.Exec()
}