forked from k3s-io/k3s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (58 loc) · 1.14 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
package main
import (
"context"
"net"
"os"
"github.com/sirupsen/logrus"
"k8s.io/kubernetes/pkg/wrapper/agent"
"k8s.io/kubernetes/pkg/wrapper/server"
)
func runAgent() {
_, ipNet, err := net.ParseCIDR("10.43.0.0/16")
if err != nil {
panic(err)
}
err = agent.Agent(&agent.AgentConfig{
KubeConfig: "./data/cred/kubeconfig-node.yaml",
RuntimeSocket: "unix:///run/containerd/containerd.sock",
ClusterCIDR: *ipNet,
})
if err != nil {
logrus.Fatal(err)
}
select {}
}
func runServer() {
hostname, err := os.Hostname()
if err != nil {
panic(err)
}
_, cidr, err := net.ParseCIDR("10.43.0.0/16")
if err != nil {
panic(err)
}
_, clusterCidr, err := net.ParseCIDR("10.42.0.0/16")
if err != nil {
panic(err)
}
cfg := server.ServerConfig{
DataDir: "./data",
ListenAddr: net.ParseIP("0.0.0.0"),
ListenPort: 6443,
ClusterIPRange: *clusterCidr,
ServiceIPRange: *cidr,
PublicHostname: hostname,
}
ctx := context.Background()
err = server.Server(ctx, &cfg)
if err != nil {
panic(err)
}
<-ctx.Done()
}
func main() {
if len(os.Args) > 1 && os.Args[1] == "agent" {
runAgent()
}
runServer()
}