forked from openshift/cluster-api-actuator-pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenstackmachine.go
283 lines (241 loc) · 9.92 KB
/
openstackmachine.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
Copyright 2025 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1beta1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capov1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
//nolint:staticcheck // Ignore SA1019 (deprecation) until capi v1beta2.
"sigs.k8s.io/cluster-api/errors"
)
// OpenStackMachine creates a new OpenStackMachine builder.
func OpenStackMachine() OpenStackMachineBuilder {
return OpenStackMachineBuilder{}
}
// OpenStackMachineBuilder is used to build out an OpenStackMachine object.
type OpenStackMachineBuilder struct {
// ObjectMeta fields.
annotations map[string]string
labels map[string]string
name string
namespace string
ownerReferences []metav1.OwnerReference
// Spec fields.
additionalBlockDevices []capov1.AdditionalBlockDevice
configDrive *bool
flavor *string
flavorID *string
floatingIPPoolRef *corev1.TypedLocalObjectReference
identityRef *capov1.OpenStackIdentityReference
image capov1.ImageParam
ports []capov1.PortOpts
rootVolume *capov1.RootVolume
schedulerHintAdditionalProperties []capov1.SchedulerHintAdditionalProperty
securityGroups []capov1.SecurityGroupParam
serverGroup *capov1.ServerGroupParam
serverMetadata []capov1.ServerMetadata
sshKeyName string
tags []string
trunk bool
// Status fields.
addresses []corev1.NodeAddress
conditions clusterv1.Conditions
failureMessage *string
failureReason *errors.MachineStatusError
instanceID *string
instanceState *capov1.InstanceState
ready bool
}
// Build builds a new OpenStackMachine based on the configuration provided.
func (a OpenStackMachineBuilder) Build() *capov1.OpenStackMachine {
openstackMachine := &capov1.OpenStackMachine{
TypeMeta: metav1.TypeMeta{
APIVersion: capov1.SchemeGroupVersion.String(),
Kind: "OpenStackMachine",
},
ObjectMeta: metav1.ObjectMeta{
Name: a.name,
Namespace: a.namespace,
Labels: a.labels,
Annotations: a.annotations,
OwnerReferences: a.ownerReferences,
},
Spec: capov1.OpenStackMachineSpec{
AdditionalBlockDevices: a.additionalBlockDevices,
ConfigDrive: a.configDrive,
Flavor: a.flavor,
FlavorID: a.flavorID,
FloatingIPPoolRef: a.floatingIPPoolRef,
IdentityRef: a.identityRef,
Image: a.image,
Ports: a.ports,
RootVolume: a.rootVolume,
SchedulerHintAdditionalProperties: a.schedulerHintAdditionalProperties,
SecurityGroups: a.securityGroups,
ServerGroup: a.serverGroup,
ServerMetadata: a.serverMetadata,
SSHKeyName: a.sshKeyName,
Tags: a.tags,
Trunk: a.trunk,
},
Status: capov1.OpenStackMachineStatus{
Addresses: a.addresses,
Conditions: a.conditions,
FailureMessage: a.failureMessage,
FailureReason: a.failureReason,
InstanceID: a.instanceID,
InstanceState: a.instanceState,
Ready: a.ready,
},
}
return openstackMachine
}
// Object meta fields.
// WithAnnotations sets the annotations for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithAnnotations(annotations map[string]string) OpenStackMachineBuilder {
a.annotations = annotations
return a
}
// WithLabels sets the labels for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithLabels(labels map[string]string) OpenStackMachineBuilder {
a.labels = labels
return a
}
// WithName sets the name for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithName(name string) OpenStackMachineBuilder {
a.name = name
return a
}
// WithNamespace sets the namespace for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithNamespace(namespace string) OpenStackMachineBuilder {
a.namespace = namespace
return a
}
// WithOwnerReferences sets the OwnerReferences for the machine builder.
func (a OpenStackMachineBuilder) WithOwnerReferences(ownerRefs []metav1.OwnerReference) OpenStackMachineBuilder {
a.ownerReferences = ownerRefs
return a
}
// Spec fields.
// WithAdditionalBlockDevices sets the additionalBlockDevices for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithAdditionalBlockDevices(additionalBlockDevices []capov1.AdditionalBlockDevice) OpenStackMachineBuilder {
a.additionalBlockDevices = additionalBlockDevices
return a
}
// WithConfigDrive sets the configDrive for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithConfigDrive(configDrive *bool) OpenStackMachineBuilder {
a.configDrive = configDrive
return a
}
// WithFlavor sets the flavor for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithFlavor(flavor *string) OpenStackMachineBuilder {
a.flavor = flavor
return a
}
// WithFlavorID sets the flavorID for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithFlavorID(flavorID *string) OpenStackMachineBuilder {
a.flavorID = flavorID
return a
}
// WithIdentityRef sets the identityRef for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithIdentityRef(identityRef *capov1.OpenStackIdentityReference) OpenStackMachineBuilder {
a.identityRef = identityRef
return a
}
// WithImage sets the image for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithImage(image capov1.ImageParam) OpenStackMachineBuilder {
a.image = image
return a
}
// WithPorts sets the ports for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithPorts(ports []capov1.PortOpts) OpenStackMachineBuilder {
a.ports = ports
return a
}
// WithRootVolume sets the rootVolume for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithRootVolume(rootVolume *capov1.RootVolume) OpenStackMachineBuilder {
a.rootVolume = rootVolume
return a
}
// WithSchedulerHintAdditionalProperties sets the schedulerHintAdditionalProperties for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithSchedulerHintAdditionalProperties(schedulerHintAdditionalProperties []capov1.SchedulerHintAdditionalProperty) OpenStackMachineBuilder {
a.schedulerHintAdditionalProperties = schedulerHintAdditionalProperties
return a
}
// WithSecurityGroups sets the securityGroups for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithSecurityGroups(securityGroups []capov1.SecurityGroupParam) OpenStackMachineBuilder {
a.securityGroups = securityGroups
return a
}
// WithServerGroup sets the serverGroup for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithServerGroup(serverGroup *capov1.ServerGroupParam) OpenStackMachineBuilder {
a.serverGroup = serverGroup
return a
}
// WithServerMetadata sets the serverMetadata for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithServerMetadata(serverMetadata []capov1.ServerMetadata) OpenStackMachineBuilder {
a.serverMetadata = serverMetadata
return a
}
// WithSSHKeyName sets the sshKeyName for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithSSHKeyName(sshKeyName string) OpenStackMachineBuilder {
a.sshKeyName = sshKeyName
return a
}
// WithTags sets the tags for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithTags(tags []string) OpenStackMachineBuilder {
a.tags = tags
return a
}
// WithTrunk sets the trunk for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithTrunk(trunk bool) OpenStackMachineBuilder {
a.trunk = trunk
return a
}
// Status fields.
// WithAddresses sets the addresses for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithAddresses(addresses []corev1.NodeAddress) OpenStackMachineBuilder {
a.addresses = addresses
return a
}
// WithConditions sets the conditions for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithConditions(conditions clusterv1.Conditions) OpenStackMachineBuilder {
a.conditions = conditions
return a
}
// WithFailureMessage sets the failureMessage for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithFailureMessage(failureMessage *string) OpenStackMachineBuilder {
a.failureMessage = failureMessage
return a
}
// WithFailureReason sets the failureReason for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithFailureReason(failureReason *errors.MachineStatusError) OpenStackMachineBuilder {
a.failureReason = failureReason
return a
}
// WithInstanceID sets the instanceID for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithInstanceID(instanceID *string) OpenStackMachineBuilder {
a.instanceID = instanceID
return a
}
// WithInstanceState sets the instanceState for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithInstanceState(instanceState *capov1.InstanceState) OpenStackMachineBuilder {
a.instanceState = instanceState
return a
}
// WithReady sets the ready for the OpenStackMachine builder.
func (a OpenStackMachineBuilder) WithReady(ready bool) OpenStackMachineBuilder {
a.ready = ready
return a
}