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
/
query.go
103 lines (92 loc) · 2.85 KB
/
query.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package kubernetes
import (
"github.com/caos/orbos/internal/api"
"github.com/pkg/errors"
"github.com/caos/orbos/internal/operator/common"
"github.com/caos/orbos/internal/operator/orbiter"
"github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/core/infra"
"github.com/caos/orbos/mntr"
)
func query(
monitor mntr.Monitor,
clusterID string,
desired *DesiredV0,
current *CurrentCluster,
providerCurrents map[string]interface{},
nodeAgentsCurrent *common.CurrentNodeAgents,
nodeAgentsDesired *common.DesiredNodeAgents,
k8sClient *Client,
oneoff bool) (orbiter.EnsureFunc, error) {
cloudPools, kubeAPIAddress, err := GetProviderInfos(desired, providerCurrents)
if err != nil {
panic(err)
}
if err := poolIsConfigured(&desired.Spec.ControlPlane, cloudPools); err != nil {
return nil, err
}
for _, w := range desired.Spec.Workers {
if err := poolIsConfigured(w, cloudPools); err != nil {
return nil, err
}
}
controlplane, controlplaneMachines, workers, workerMachines, initializeMachine, uninitializeMachine, err := initialize(
monitor,
current,
*desired,
nodeAgentsCurrent,
nodeAgentsDesired,
cloudPools,
k8sClient,
func(machine *initializedMachine) {
firewallFunc(monitor, *desired)(machine)
})
return func(psf api.SecretFunc) *orbiter.EnsureResult {
return orbiter.ToEnsureResult(ensure(
monitor,
clusterID,
desired,
kubeAPIAddress,
psf,
k8sClient,
oneoff,
controlplane,
controlplaneMachines,
workers,
workerMachines,
initializeMachine,
uninitializeMachine))
}, err
}
func poolIsConfigured(poolSpec *Pool, infra map[string]map[string]infra.Pool) error {
prov, ok := infra[poolSpec.Provider]
if !ok {
return errors.Errorf("provider %s not configured", poolSpec.Provider)
}
if _, ok := prov[poolSpec.Pool]; !ok {
return errors.Errorf("pool %s not configured on provider %s", poolSpec.Provider, poolSpec.Pool)
}
return nil
}
func GetProviderInfos(desired *DesiredV0, providerCurrents map[string]interface{}) (map[string]map[string]infra.Pool, *infra.Address, error) {
cloudPools := make(map[string]map[string]infra.Pool)
var kubeAPIAddress *infra.Address
for providerName, provider := range providerCurrents {
if cloudPools[providerName] == nil {
cloudPools[providerName] = make(map[string]infra.Pool)
}
prov := provider.(infra.ProviderCurrent)
providerPools := prov.Pools()
providerIngresses := prov.Ingresses()
for providerPoolName, providerPool := range providerPools {
cloudPools[providerName][providerPoolName] = providerPool
if desired.Spec.ControlPlane.Provider == providerName && desired.Spec.ControlPlane.Pool == providerPoolName {
var ok bool
kubeAPIAddress, ok = providerIngresses["kubeapi"]
if !ok {
return nil, nil, errors.New("no externally reachable address named kubeapi found")
}
}
}
}
return cloudPools, kubeAPIAddress, nil
}