This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ensure.go
79 lines (70 loc) · 1.8 KB
/
ensure.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
77
78
79
package kubernetes
import (
"github.com/caos/orbos/internal/api"
"github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/core/infra"
"github.com/caos/orbos/mntr"
)
func ensure(
monitor mntr.Monitor,
clusterID string,
desired *DesiredV0,
kubeAPIAddress *infra.Address,
psf api.SecretFunc,
k8sClient *Client,
oneoff bool,
controlplane initializedPool,
controlplaneMachines []*initializedMachine,
workers []initializedPool,
workerMachines []*initializedMachine,
initializeMachine initializeMachineFunc,
uninitializeMachine uninitializeMachineFunc,
) (done bool, err error) {
initialized := true
for _, machine := range append(controlplaneMachines, workerMachines...) {
if err := machine.reconcile(); err != nil {
return false, err
}
machineMonitor := monitor.WithField("machine", machine.infra.ID())
if !machine.currentMachine.FirewallIsReady {
initialized = false
machineMonitor.Info("Firewall is not ready yet")
}
}
if !initialized {
return false, nil
}
targetVersion := ParseString(desired.Spec.Versions.Kubernetes)
upgradingDone, err := ensureSoftware(
monitor,
targetVersion,
k8sClient,
controlplaneMachines,
workerMachines)
if err != nil || !upgradingDone {
monitor.Info("Upgrading is not done yet")
return upgradingDone, err
}
var scalingDone bool
scalingDone, err = ensureScale(
monitor,
clusterID,
desired,
psf,
controlplane,
workers,
kubeAPIAddress,
targetVersion,
k8sClient,
oneoff,
func(created infra.Machine, pool initializedPool) initializedMachine {
machine := initializeMachine(created, pool)
target := targetVersion.DefineSoftware()
machine.desiredNodeagent.Software = &target
return *machine
},
uninitializeMachine)
if !scalingDone {
monitor.Info("Scaling is not done yet")
}
return scalingDone, err
}