-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
machinepools.go
246 lines (201 loc) · 7.3 KB
/
machinepools.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package gcp
// FeatureSwitch indicates whether the feature is enabled or disabled.
type FeatureSwitch string
// OnHostMaintenanceType indicates the setting for the OnHostMaintenance feature, but this is only
// applicable when ConfidentialCompute is Enabled.
type OnHostMaintenanceType string
const (
// EnabledFeature indicates that the feature is configured as enabled.
EnabledFeature FeatureSwitch = "Enabled"
// DisabledFeature indicates that the feature is configured as disabled.
DisabledFeature FeatureSwitch = "Disabled"
// OnHostMaintenanceMigrate is the default, and it indicates that the OnHostMaintenance feature is set to Migrate.
OnHostMaintenanceMigrate OnHostMaintenanceType = "Migrate"
// OnHostMaintenanceTerminate indicates that the OnHostMaintenance feature is set to Terminate.
OnHostMaintenanceTerminate OnHostMaintenanceType = "Terminate"
)
// MachinePool stores the configuration for a machine pool installed on GCP.
type MachinePool struct {
// Zones is list of availability zones that can be used.
//
// +optional
Zones []string `json:"zones,omitempty"`
// InstanceType defines the GCP instance type.
// eg. n1-standard-4
//
// +optional
InstanceType string `json:"type"`
// OSDisk defines the storage for instance.
//
// +optional
OSDisk `json:"osDisk"`
// OSImage defines a custom image for instance.
//
// +optional
OSImage *OSImage `json:"osImage,omitempty"`
// Tags defines a set of network tags which will be added to instances in the machineset
//
// +optional
Tags []string `json:"tags,omitempty"`
// SecureBoot Defines whether the instance should have secure boot enabled.
// secure boot Verify the digital signature of all boot components, and halt the boot process if signature verification fails.
// If omitted, the platform chooses a default, which is subject to change over time, currently that default is false.
// +kubebuilder:validation:Enum=Enabled;Disabled
// +optional
SecureBoot string `json:"secureBoot,omitempty"`
// OnHostMaintenance determines the behavior when a maintenance event occurs that might cause the instance to reboot.
// Allowed values are "Migrate" and "Terminate".
// If omitted, the platform chooses a default, which is subject to change over time, currently that default is "Migrate".
// +kubebuilder:default="Migrate"
// +default="Migrate"
// +kubebuilder:validation:Enum=Migrate;Terminate;
// +optional
OnHostMaintenance string `json:"onHostMaintenance,omitempty"`
// ConfidentialCompute Defines whether the instance should have confidential compute enabled.
// If enabled OnHostMaintenance is required to be set to "Terminate".
// If omitted, the platform chooses a default, which is subject to change over time, currently that default is false.
// +kubebuilder:default="Disabled"
// +default="Disabled"
// +kubebuilder:validation:Enum=Enabled;Disabled
// +optional
ConfidentialCompute string `json:"confidentialCompute,omitempty"`
// ServiceAccount is the email of a gcp service account to be used for shared
// vpc installations. The provided service account will be attached to control-plane nodes
// in order to provide the permissions required by the cloud provider in the host project.
// This field is only supported in the control-plane machinepool.
//
// +optional
ServiceAccount string `json:"serviceAccount,omitempty"`
}
// OSDisk defines the disk for machines on GCP.
type OSDisk struct {
// DiskType defines the type of disk.
// For control plane nodes, the valid value is pd-ssd.
// +optional
// +kubebuilder:validation:Enum=pd-balanced;pd-ssd;pd-standard
DiskType string `json:"diskType"`
// DiskSizeGB defines the size of disk in GB.
//
// +kubebuilder:validation:Minimum=16
// +kubebuilder:validation:Maximum=65536
DiskSizeGB int64 `json:"DiskSizeGB"`
// EncryptionKey defines the KMS key to be used to encrypt the disk.
//
// +optional
EncryptionKey *EncryptionKeyReference `json:"encryptionKey,omitempty"`
}
// OSImage defines the image to use for the OS.
type OSImage struct {
// Name defines the name of the image.
//
// +required
Name string `json:"name"`
// Project defines the name of the project containing the image.
//
// +required
Project string `json:"project"`
}
// Set sets the values from `required` to `a`.
func (a *MachinePool) Set(required *MachinePool) {
if required == nil || a == nil {
return
}
if len(required.Zones) > 0 {
a.Zones = required.Zones
}
if required.InstanceType != "" {
a.InstanceType = required.InstanceType
}
if required.Tags != nil {
a.Tags = required.Tags
}
if required.OSDisk.DiskSizeGB > 0 {
a.OSDisk.DiskSizeGB = required.OSDisk.DiskSizeGB
}
if required.OSDisk.DiskType != "" {
a.OSDisk.DiskType = required.OSDisk.DiskType
}
if required.OSImage != nil {
a.OSImage = required.OSImage
}
if required.EncryptionKey != nil {
if a.EncryptionKey == nil {
a.EncryptionKey = &EncryptionKeyReference{}
}
a.EncryptionKey.Set(required.EncryptionKey)
}
if required.SecureBoot != "" {
a.SecureBoot = required.SecureBoot
}
if required.OnHostMaintenance != "" {
a.OnHostMaintenance = required.OnHostMaintenance
}
if required.ConfidentialCompute != "" {
a.ConfidentialCompute = required.ConfidentialCompute
}
if required.ServiceAccount != "" {
a.ServiceAccount = required.ServiceAccount
}
}
// EncryptionKeyReference describes the encryptionKey to use for a disk's encryption.
type EncryptionKeyReference struct {
// KMSKey is a reference to a KMS Key to use for the encryption.
//
// +optional
KMSKey *KMSKeyReference `json:"kmsKey,omitempty"`
// KMSKeyServiceAccount is the service account being used for the
// encryption request for the given KMS key. If absent, the Compute
// Engine default service account is used.
// See https://cloud.google.com/compute/docs/access/service-accounts#compute_engine_service_account
// for details on the default service account.
//
// +optional
KMSKeyServiceAccount string `json:"kmsKeyServiceAccount,omitempty"`
}
// Set sets the values from `required` to `e`.
func (e *EncryptionKeyReference) Set(required *EncryptionKeyReference) {
if required == nil || e == nil {
return
}
if required.KMSKeyServiceAccount != "" {
e.KMSKeyServiceAccount = required.KMSKeyServiceAccount
}
if required.KMSKey != nil {
if e.KMSKey == nil {
e.KMSKey = &KMSKeyReference{}
}
e.KMSKey.Set(required.KMSKey)
}
}
// KMSKeyReference gathers required fields for looking up a GCP KMS Key
type KMSKeyReference struct {
// Name is the name of the customer managed encryption key to be used for the disk encryption.
Name string `json:"name"`
// KeyRing is the name of the KMS Key Ring which the KMS Key belongs to.
KeyRing string `json:"keyRing"`
// ProjectID is the ID of the Project in which the KMS Key Ring exists.
// Defaults to the VM ProjectID if not set.
//
// +optional
ProjectID string `json:"projectID,omitempty"`
// Location is the GCP location in which the Key Ring exists.
Location string `json:"location"`
}
// Set sets the values from `required` to `k`.
func (k *KMSKeyReference) Set(required *KMSKeyReference) {
if required == nil || k == nil {
return
}
if required.Name != "" {
k.Name = required.Name
}
if required.KeyRing != "" {
k.KeyRing = required.KeyRing
}
if required.ProjectID != "" {
k.ProjectID = required.ProjectID
}
if required.Location != "" {
k.Location = required.Location
}
}