/
main.go
91 lines (66 loc) · 1.84 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
package main
import (
"context"
"github.com/oats87/rancher-agent/pkg/applyinator"
"github.com/oats87/rancher-agent/pkg/config"
"github.com/oats87/rancher-agent/pkg/localplan"
"github.com/oats87/rancher-agent/pkg/remoteplan"
"github.com/rancher/wrangler/pkg/signals"
"os"
"strings"
"github.com/mattn/go-colorable"
"github.com/sirupsen/logrus"
)
var (
Version = "v0.0.0-dev"
GitCommit = "HEAD"
)
func main() {
logrus.SetOutput(colorable.NewColorableStdout())
rawLevel := os.Getenv("CATTLE_LOGLEVEL")
if rawLevel != "" {
if lvl, err := logrus.ParseLevel(os.Getenv("CATTLE_LOGLEVEL")); err != nil {
logrus.Fatal(err)
} else {
logrus.SetLevel(lvl)
}
}
err := run()
if err != nil {
logrus.Fatal(err)
}
}
func isTrue(input string) bool {
if strings.ToLower(input) == "true" || input == "1" {
return true
}
return false
}
func run() error {
topContext := signals.SetupSignalHandler(context.Background())
logrus.Infof("Rancher System Agent version %s is starting", Version)
configFile := os.Getenv("CATTLE_AGENT_CONFIG")
if configFile == "" {
configFile = "/etc/rancher/agent/config.yaml"
}
var cf config.AgentConfig
err := config.Parse(configFile, &cf)
if err != nil {
logrus.Fatalf("Unable to parse config file %v", err)
}
logrus.Infof("Using directory %s for work", cf.WorkDir)
applyinator := applyinator.NewApplyinator(cf.WorkDir, "")
if cf.RemoteEnabled {
logrus.Infof("Starting remote watch of plans")
var connInfo config.ConnectionInfo
err = config.Parse(cf.ConnectionInfoFile, &connInfo)
if err != nil {
logrus.Fatalf("Unable to parse connection info file %v", err)
}
remoteplan.Watch(topContext, *applyinator, connInfo)
}
logrus.Infof("Starting local watch of plans in %s", cf.LocalPlanDir)
localplan.WatchFiles(topContext, *applyinator, cf.LocalPlanDir)
<-topContext.Done()
return nil
}