-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.go
72 lines (58 loc) · 2.05 KB
/
cluster.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
package model
import (
"fmt"
"github.com/duncanpierce/hetzanetes/env"
"log"
)
func (c *Cluster) Repair(actions Actions) error {
if c.Status == nil {
log.Printf("No status found - bootstrapping\n")
err := c.Bootstrap(actions)
if err != nil {
return err
}
}
c.CreateNodeSetStatusesIfNecessary()
c.Status.UpdateVersionRanges()
for _, nodeSetStatus := range c.Status.NodeSetStatuses {
nodeSetStatus.Repair(c)
}
c.Status.Find().MakeProgress(c, actions)
c.Status.UpdateVersionRanges()
return actions.SaveStatus(c.Metadata.Name, c.Status)
}
func (c *Cluster) CreateNodeSetStatusesIfNecessary() {
for _, nodeSetSpec := range c.Spec.NodeSets {
(&c.Status.NodeSetStatuses).CreateIfNecessary(nodeSetSpec)
}
}
func (c *Cluster) Bootstrap(actions Actions) error {
log.Printf("Initializing status field\n")
c.Status = &ClusterStatus{
Versions: &VersionStatus{},
ClusterNetwork: ClusterNetworkStatus{
CloudId: env.HCloudNetworkId(),
IpRange: env.HCloudNetworkIpRange(),
},
NodeSetStatuses: NodeSetStatuses{},
}
log.Printf("Downloading release channels and setting target Kubernetes version for cluster\n")
if err := c.Status.Versions.UpdateReleaseChannels(c.Spec.Versions.GetKubernetes(), actions); err != nil {
return err
}
log.Printf("Creating nodeSet statuses\n")
c.CreateNodeSetStatusesIfNecessary()
bootstrapApiNodeSetName := c.Spec.NodeSets.FirstApiServerNodeSet().Name
nodeSetStatus := c.Status.NodeSetStatuses.Named(bootstrapApiNodeSetName)
nodeSetStatus.Generation = 1
bootstrapNodeName := fmt.Sprintf("%s-%s-%d", c.Metadata.Name, bootstrapApiNodeSetName, 1)
log.Printf("Looking for bootstrap API server %s\n", bootstrapNodeName)
k8sVersion := c.Status.Versions.Target // TODO would be safer to read it from the Node resource in K8s (avoids race condition)
nodeStatus, err := actions.GetBootstrapServer(bootstrapNodeName, true, k8sVersion)
if err != nil {
return err
}
log.Printf("Adding bootstrap node %#v to node status\n", nodeStatus)
nodeSetStatus.NodeStatuses = append(nodeSetStatus.NodeStatuses, nodeStatus)
return nil
}