forked from target/impeller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (67 loc) · 1.67 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
package main
import (
"fmt"
"log"
"os"
"github.com/target/impeller/utils"
"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",
},
cli.StringSliceFlag{
Name: "value-files",
Usage: "Helm value override files",
EnvVar: "VALUE_FILES,PLUGIN_VALUE_FILES",
},
cli.StringFlag{
Name: "kube-config",
Usage: "Kubernetes configuration file",
EnvVar: "KUBE_CONFIG,PLUGIN_KUBE_CONFIG",
},
cli.StringFlag{
Name: "kube-context",
Usage: "Kubernetes configuration context to use",
EnvVar: "KUBE_CONTEXT,PLUGIN_KUBE_CONTEXT",
},
cli.BoolFlag{
Name: "dry-run",
Usage: "Enables a dry_run deployment",
EnvVar: "DRY_RUN,PLUGIN_DRY_RUN",
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func run(ctx *cli.Context) error {
if ctx.String("cluster-config-path") == "" {
return fmt.Errorf("Cluster config path not set.")
}
if ctx.String("kube-config") == "" {
return fmt.Errorf("Kube config not set.")
}
if ctx.String("kube-context") == "" {
return fmt.Errorf("Kube context not set.")
}
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,
ValueFiles: ctx.StringSlice("value-files"),
KubeConfig: ctx.String("kube-config"),
KubeContext: ctx.String("kube-context"),
Dryrun: ctx.Bool("dry-run"),
}
return plugin.Exec()
}