-
Notifications
You must be signed in to change notification settings - Fork 1
/
system.go
86 lines (66 loc) · 1.95 KB
/
system.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
package system
import (
"fmt"
"github.com/spigell/pulumi-hcloud-kube-hetzner/internal/hetzner"
"github.com/spigell/pulumi-hcloud-kube-hetzner/internal/program"
"github.com/spigell/pulumi-hcloud-kube-hetzner/internal/system/info"
"github.com/spigell/pulumi-hcloud-kube-hetzner/internal/system/os"
"github.com/spigell/pulumi-hcloud-kube-hetzner/internal/system/os/microos"
"github.com/spigell/pulumi-hcloud-kube-hetzner/internal/system/variables"
"github.com/spigell/pulumi-hcloud-kube-hetzner/internal/utils/ssh/keypair"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
type System struct {
ctx *program.Context
info *info.Info
// kubeDependecies hidden storage for keeping dependencies between modules in k8s stage.
// For instance, wait leader to be ready before joining nodes.
kubeDependecies map[string][]pulumi.Resource
ID string
KeyPair *keypair.ECDSAKeyPair
OS os.OperatingSystem
}
type SysProvisioned struct {
OS os.Provisioned
}
func New(ctx *program.Context, id string) *System {
return &System{
ID: id,
ctx: ctx,
// KeyPair: pair,
info: info.New(),
}
}
func (s *System) MicroOS() *microos.MicroOS {
os := microos.New(s.ID)
return os
}
func (s *System) WithOS(os os.OperatingSystem) *System {
s.OS = os
return s
}
func (s *System) WithCommunicationMethod(method variables.CommunicationMethod) *System {
s.info = s.info.WithCommunicationMethod(method)
return s
}
func (s *System) CommunicationMethod() variables.CommunicationMethod {
return s.info.CommunicationMethod()
}
func (s *System) WithK8SEndpointType(t string) *System {
s.info = s.info.WithK8SEndpointType(t)
return s
}
func (s *System) MarkAsLeader() *System {
s.info = s.info.MarkAsLeader()
return s
}
func (s *System) Up(server *hetzner.Server) (*SysProvisioned, error) {
os, err := s.OS.Up(s.ctx, server, s.kubeDependecies)
if err != nil {
err = fmt.Errorf("error while preparing: %w", err)
return nil, err
}
return &SysProvisioned{
OS: os,
}, nil
}