-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
74 lines (64 loc) · 2.07 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
package main
import (
"flag"
"fmt"
"os"
"github.com/mmontes11/k8s-bootstrap/pkg/config"
)
var (
configPath string
apiServerEndpoint string
token string
caCertHash string
labelKey string
labelValue string
taint string
)
func main() {
flag.StringVar(&configPath, "config-path", "",
"Path where the join configuration will be written. For example: config/kubeadm-join.yaml."+
"If not provided, stdout is used.")
flag.StringVar(&apiServerEndpoint, "api-server-endpoint", "",
"API server endpoint used to bootstrap the Node. For example: 10.0.0.20:6443.")
flag.StringVar(&token, "token", "", "Token used to bootstrap the Node.")
flag.StringVar(&caCertHash, "ca-cert-hash", "", "CA certificate hash used to bootstrap the Node.")
flag.StringVar(&labelKey, "label-key", "", "Label key to be added to the Node.")
flag.StringVar(&labelValue, "label-value", "", "Label value to be added to the Node.")
flag.StringVar(&taint, "taint", "", "Taint to be added to the Node.")
flag.Parse()
if apiServerEndpoint == "" || token == "" || caCertHash == "" {
fmt.Println("api-server-endpoint, token and ca-cert-hash flags are mandatory.")
os.Exit(1)
}
opts := []config.Option{
config.WithAPIServerEndpoint(apiServerEndpoint),
config.WithToken(token),
config.WithCACertHash(caCertHash),
}
if labelKey != "" && labelValue != "" {
opts = append(opts, config.WithLabel(labelKey, labelValue))
}
if taint != "" {
opts = append(opts, config.WithTaint(taint))
}
joinConfig, err := config.NewJoinConfig(opts...)
if err != nil {
fmt.Printf("Error getting join configuration: %v\n", err)
os.Exit(1)
}
writer := os.Stdout
if configPath != "" {
fmt.Printf("Generating join configuration file: %v\n", configPath)
file, err := os.Create(configPath)
if err != nil {
fmt.Printf("Error opening \"%s\" file: %v\n", configPath, err)
os.Exit(1)
}
defer file.Close()
writer = file
}
if _, err := writer.Write([]byte(joinConfig)); err != nil {
fmt.Printf("Error writing join configuration: %v\n", err)
os.Exit(1)
}
}