-
Notifications
You must be signed in to change notification settings - Fork 286
/
tinkerbell.go
112 lines (94 loc) · 3.23 KB
/
tinkerbell.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
104
105
106
107
108
109
110
111
112
package cluster
import (
"context"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
)
// tinkerbellEntry is unimplemented. Its boiler plate to mute warnings that could confuse the customer until we
// get round to implementing it.
func tinkerbellEntry() *ConfigManagerEntry {
return &ConfigManagerEntry{
APIObjectMapping: map[string]APIObjectGenerator{
anywherev1.TinkerbellDatacenterKind: func() APIObject {
return &anywherev1.TinkerbellDatacenterConfig{}
},
anywherev1.TinkerbellMachineConfigKind: func() APIObject {
return &anywherev1.TinkerbellMachineConfig{}
},
anywherev1.TinkerbellTemplateConfigKind: func() APIObject {
return &anywherev1.TinkerbellTemplateConfig{}
},
},
Processors: []ParsedProcessor{
processTinkerbellDatacenter,
machineConfigsProcessor(processTinkerbellMachineConfig),
processTinkerbellTemplateConfigs,
},
}
}
func processTinkerbellDatacenter(c *Config, objects ObjectLookup) {
if c.Cluster.Spec.DatacenterRef.Kind == anywherev1.TinkerbellDatacenterKind {
datacenter := objects.GetFromRef(c.Cluster.APIVersion, c.Cluster.Spec.DatacenterRef)
if datacenter != nil {
c.TinkerbellDatacenter = datacenter.(*anywherev1.TinkerbellDatacenterConfig)
}
}
}
func processTinkerbellTemplateConfigs(c *Config, objects ObjectLookup) {
if c.TinkerbellTemplateConfigs == nil {
c.TinkerbellTemplateConfigs = map[string]*anywherev1.TinkerbellTemplateConfig{}
}
if c.Cluster.Spec.DatacenterRef.Kind == anywherev1.TinkerbellDatacenterKind {
for _, o := range objects {
mt, ok := o.(*anywherev1.TinkerbellTemplateConfig)
if ok {
c.TinkerbellTemplateConfigs[mt.Name] = mt
}
}
}
}
func processTinkerbellMachineConfig(c *Config, objects ObjectLookup, machineRef *anywherev1.Ref) {
if machineRef == nil {
return
}
if machineRef.Kind != anywherev1.TinkerbellMachineConfigKind {
return
}
if c.TinkerbellMachineConfigs == nil {
c.TinkerbellMachineConfigs = map[string]*anywherev1.TinkerbellMachineConfig{}
}
m := objects.GetFromRef(c.Cluster.APIVersion, *machineRef)
if m == nil {
return
}
c.TinkerbellMachineConfigs[m.GetName()] = m.(*anywherev1.TinkerbellMachineConfig)
}
func getTinkerbellDatacenter(ctx context.Context, client Client, c *Config) error {
if c.Cluster.Spec.DatacenterRef.Kind != anywherev1.TinkerbellDatacenterKind {
return nil
}
datacenter := &anywherev1.TinkerbellDatacenterConfig{}
if err := client.Get(ctx, c.Cluster.Spec.DatacenterRef.Name, c.Cluster.Namespace, datacenter); err != nil {
return err
}
c.TinkerbellDatacenter = datacenter
return nil
}
func getTinkerbellMachineConfigs(ctx context.Context, client Client, c *Config) error {
if c.Cluster.Spec.DatacenterRef.Kind != anywherev1.TinkerbellDatacenterKind {
return nil
}
if c.TinkerbellMachineConfigs == nil {
c.TinkerbellMachineConfigs = map[string]*anywherev1.TinkerbellMachineConfig{}
}
for _, machineRef := range c.Cluster.MachineConfigRefs() {
if machineRef.Kind != anywherev1.TinkerbellMachineConfigKind {
continue
}
machineConfig := &anywherev1.TinkerbellMachineConfig{}
if err := client.Get(ctx, machineRef.Name, c.Cluster.Namespace, machineConfig); err != nil {
return err
}
c.TinkerbellMachineConfigs[machineConfig.Name] = machineConfig
}
return nil
}