-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (57 loc) · 1.82 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
package main
import (
"flag"
"io/ioutil"
zippo "github.com/jan0ski/zippo/pkg"
log "github.com/sirupsen/logrus"
"golang.org/x/mod/semver"
)
var (
listenAddr string
listenPort int
sshUser string
sshPubkey string
k8sVersion string
cniVersion string
templatePath string
configPath string
)
func init() {
flag.StringVar(&listenAddr, "address", "0.0.0.0", "listen address of the server")
flag.IntVar(&listenPort, "port", 8080, "listen port of the server")
flag.StringVar(&sshUser, "ssh-user", "core", "initial user available via ssh")
flag.StringVar(&sshPubkey, "ssh-pubkey", "", "key to add to `authorized_hosts` for ssh access")
flag.StringVar(&k8sVersion, "k8s-version", "v1.23.0", "Kubernetes version to install")
flag.StringVar(&cniVersion, "cni-version", "v1.0.0", "CNI version to install")
flag.StringVar(&templatePath, "template", "/etc/zippo/templates/config.tmpl", "path to Butane template to render")
flag.StringVar(&configPath, "config", "/etc/zippo/config.yaml", "path to place rendered config")
flag.Parse()
}
// Define your own args to pass into the template
type args struct {
Hostname string
SSHUser string
SSHPubkey string
CNIVersion string
CRICtlVersion string
K8sVersion string
}
func main() {
// Don't set `Hostname`, it's populated from the host header
args := args{
Hostname: "{{ .Hostname }}",
SSHUser: sshUser,
SSHPubkey: sshPubkey,
K8sVersion: k8sVersion,
// CRICTL only has major/minor releases
CRICtlVersion: semver.MajorMinor(k8sVersion) + ".0",
CNIVersion: cniVersion,
}
// populate config file with rendered template
template, err := zippo.Render(templatePath, args)
if err != nil {
log.Fatalf(err.Error())
}
ioutil.WriteFile(configPath, template.Bytes(), 0600)
zippo.NewServer(listenAddr, listenPort, configPath, args).Run()
}