forked from kubernetes/kops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (62 loc) · 1.72 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
package main
import (
"flag"
"fmt"
"github.com/golang/glog"
"k8s.io/kops/upup/models"
"k8s.io/kops/upup/pkg/fi/nodeup"
"os"
"time"
)
var (
// value overwritten during build. This can be used to resolve issues.
BuildVersion = "0.1"
)
const retryInterval = 30 * time.Second
func main() {
fmt.Printf("nodeup version %s\n", BuildVersion)
var flagConf string
flag.StringVar(&flagConf, "conf", "node.yaml", "configuration location")
var flagCacheDir string
flag.StringVar(&flagCacheDir, "cache", "/var/cache/nodeup", "the location for the local asset cache")
var flagRootFS string
flag.StringVar(&flagRootFS, "rootfs", "/", "the location of the machine root (for running in a container)")
var flagRetries int
flag.IntVar(&flagRetries, "retries", -1, "maximum number of retries on failure: -1 means retry forever")
dryrun := false
flag.BoolVar(&dryrun, "dryrun", false, "Don't create cloud resources; just show what would be done")
target := "direct"
flag.StringVar(&target, "target", target, "Target - direct, cloudinit")
if dryrun {
target = "dryrun"
}
flag.Set("logtostderr", "true")
flag.Parse()
if flagConf == "" {
glog.Exitf("--conf is required")
}
retries := flagRetries
for {
cmd := &nodeup.NodeUpCommand{
ConfigLocation: flagConf,
Target: target,
CacheDir: flagCacheDir,
FSRoot: flagRootFS,
ModelDir: models.NewAssetPath("nodeup"),
}
err := cmd.Run(os.Stdout)
if err == nil {
fmt.Printf("success")
os.Exit(0)
}
if retries == 0 {
glog.Exitf("error running nodeup: %v", err)
os.Exit(1)
}
if retries > 0 {
retries--
}
glog.Warningf("got error running nodeup (will retry in %s): %v", retryInterval, err)
time.Sleep(retryInterval)
}
}