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
package clusterprovider
import (
"fmt"
"github.com/johnandersen777/socialweb-computer-kcp/internal/portallocator"
"github.com/johnandersen777/socialweb-computer-kcp/internal/procgroup"
)
var componentPorts = map[procgroup.Component][]portallocator.Purpose{
procgroup.ComponentPostgres: {portallocator.PurposePostgres},
procgroup.ComponentOpenBao: {portallocator.PurposeOpenBao},
procgroup.ComponentApiserverFront: {portallocator.PurposeK3sSecure},
procgroup.ComponentKine: {portallocator.PurposeKine, portallocator.PurposeKineB},
procgroup.ComponentK3s: {
portallocator.PurposeK3sSlotA,
portallocator.PurposeK3sApiserverA,
portallocator.PurposeK3sControllerManager,
portallocator.PurposeK3sScheduler,
portallocator.PurposeK3sCloudControllerManager,
portallocator.PurposeK3sSlotB,
portallocator.PurposeK3sApiserverB,
portallocator.PurposeK3sControllerManagerB,
portallocator.PurposeK3sSchedulerB,
portallocator.PurposeK3sCloudControllerManagerB,
},
procgroup.ComponentCloudControllerManager: nil,
procgroup.ComponentExternalSecretsWebhook: {
portallocator.PurposeExternalSecretsWebhook,
portallocator.PurposeExternalSecretsWebhookHealth,
},
procgroup.ComponentExternalSecrets: {portallocator.PurposeExternalSecretsHealth},
}
var ErrNoPurposeForComponent = fmt.Errorf(
"clusterprovider: a component of this Stack has no leased port. A component with no lease " +
"either binds a host-fixed port -- and the first cluster takes it and every later one " +
"fails at bind -- or it binds nothing, which means it is in the Stack without being run")
func PurposesFor(stack Stack, postgresNeeded bool) ([]portallocator.Purpose, error) {
if len(stack) == 0 {
return nil, fmt.Errorf(
"clusterprovider: an empty Stack leases nothing, and a cluster with no leases is a " +
"cluster with no ports to hold it to; refusing rather than returning the default carve")
}
var out []portallocator.Purpose
seen := map[portallocator.Purpose]bool{}
add := func(p portallocator.Purpose) {
if seen[p] {
return
}
seen[p] = true
out = append(out, p)
}
if postgresNeeded {
add(portallocator.PurposePostgres)
}
for _, c := range stack {
purposes, ok := componentPorts[c]
if !ok {
return nil, fmt.Errorf("%w (component %q)", ErrNoPurposeForComponent, c)
}
for _, p := range purposes {
add(p)
}
}
return out, nil
}