-
Notifications
You must be signed in to change notification settings - Fork 274
/
cloudstack.go
553 lines (475 loc) Β· 23.5 KB
/
cloudstack.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
package framework
import (
"context"
"fmt"
"os"
"strings"
"testing"
"time"
"github.com/aws/eks-anywhere/internal/pkg/api"
"github.com/aws/eks-anywhere/internal/test/cleanup"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/executables"
"github.com/aws/eks-anywhere/pkg/retrier"
releasev1 "github.com/aws/eks-anywhere/release/api/v1alpha1"
clusterf "github.com/aws/eks-anywhere/test/framework/cluster"
"github.com/aws/eks-anywhere/test/framework/cluster/validations"
)
const (
cloudstackDomainVar = "T_CLOUDSTACK_DOMAIN"
cloudstackMultiLevelDomainVar = "T_CLOUDSTACK_MULTILEVEL_DOMAIN"
cloudstackZoneVar = "T_CLOUDSTACK_ZONE"
cloudstackZone2Var = "T_CLOUDSTACK_ZONE_2"
cloudstackZone3Var = "T_CLOUDSTACK_ZONE_3"
cloudstackAccountVar = "T_CLOUDSTACK_ACCOUNT"
cloudstackAccountForMultiLevelDomainVar = "T_CLOUDSTACK_ACCOUNT_FOR_MULTILEVEL_DOMAIN"
cloudstackNetworkVar = "T_CLOUDSTACK_NETWORK"
cloudstackNetwork2Var = "T_CLOUDSTACK_NETWORK_2"
cloudstackNetwork3Var = "T_CLOUDSTACK_NETWORK_3"
cloudstackCredentialsVar = "T_CLOUDSTACK_CREDENTIALS"
cloudstackCredentials2Var = "T_CLOUDSTACK_CREDENTIALS_2"
cloudstackCredentials3Var = "T_CLOUDSTACK_CREDENTIALS_3"
cloudstackCredentialsForMultiLevelDomainVar = "T_CLOUDSTACK_CREDENTIALS_FOR_MULTILEVEL_DOMAIN"
cloudstackManagementServerVar = "T_CLOUDSTACK_MANAGEMENT_SERVER"
cloudstackManagementServer2Var = "T_CLOUDSTACK_MANAGEMENT_SERVER_2"
cloudstackManagementServer3Var = "T_CLOUDSTACK_MANAGEMENT_SERVER_3"
cloudstackSSHAuthorizedKeyVar = "T_CLOUDSTACK_SSH_AUTHORIZED_KEY"
cloudstackComputeOfferingLargeVar = "T_CLOUDSTACK_COMPUTE_OFFERING_LARGE"
cloudstackComputeOfferingLargerVar = "T_CLOUDSTACK_COMPUTE_OFFERING_LARGER"
cloudStackClusterIPPoolEnvVar = "T_CLOUDSTACK_CLUSTER_IP_POOL"
cloudStackCidrVar = "T_CLOUDSTACK_CIDR"
podCidrVar = "T_CLOUDSTACK_POD_CIDR"
serviceCidrVar = "T_CLOUDSTACK_SERVICE_CIDR"
cloudstackFeatureGateEnvVar = "CLOUDSTACK_PROVIDER"
cloudstackB64EncodedSecretEnvVar = "EKSA_CLOUDSTACK_B64ENCODED_SECRET"
)
var requiredCloudStackEnvVars = []string{
cloudstackAccountVar,
cloudstackAccountForMultiLevelDomainVar,
cloudstackDomainVar,
cloudstackMultiLevelDomainVar,
cloudstackZoneVar,
cloudstackZone2Var,
cloudstackZone3Var,
cloudstackCredentialsVar,
cloudstackCredentials2Var,
cloudstackCredentials3Var,
cloudstackCredentialsForMultiLevelDomainVar,
cloudstackAccountVar,
cloudstackNetworkVar,
cloudstackNetwork2Var,
cloudstackNetwork3Var,
cloudstackManagementServerVar,
cloudstackManagementServer2Var,
cloudstackManagementServer3Var,
cloudstackSSHAuthorizedKeyVar,
cloudstackComputeOfferingLargeVar,
cloudstackComputeOfferingLargerVar,
cloudStackCidrVar,
podCidrVar,
serviceCidrVar,
cloudstackFeatureGateEnvVar,
cloudstackB64EncodedSecretEnvVar,
}
type CloudStack struct {
t *testing.T
fillers []api.CloudStackFiller
clusterFillers []api.ClusterFiller
cidr string
podCidr string
serviceCidr string
cmkClient *executables.Cmk
devRelease *releasev1.EksARelease
templatesRegistry *templateRegistry
}
type CloudStackOpt func(*CloudStack)
func UpdateLargerCloudStackComputeOffering() api.CloudStackFiller {
return api.WithCloudStackStringFromEnvVar(cloudstackComputeOfferingLargerVar, api.WithCloudStackComputeOfferingForAllMachines)
}
// UpdateAddCloudStackAz4 add availability zone 4 to the cluster spec.
func UpdateAddCloudStackAz4() api.CloudStackFiller {
return api.WithCloudStackAzFromEnvVars(cloudstackAccountForMultiLevelDomainVar, cloudstackMultiLevelDomainVar, cloudstackZoneVar, cloudstackCredentialsForMultiLevelDomainVar, cloudstackNetworkVar,
cloudstackManagementServerVar, api.WithCloudStackAz)
}
// UpdateAddCloudStackAz3 add availability zone 3 to the cluster spec.
func UpdateAddCloudStackAz3() api.CloudStackFiller {
return api.WithCloudStackAzFromEnvVars(cloudstackAccountVar, cloudstackDomainVar, cloudstackZone3Var, cloudstackCredentials3Var, cloudstackNetwork3Var,
cloudstackManagementServer3Var, api.WithCloudStackAz)
}
func UpdateAddCloudStackAz2() api.CloudStackFiller {
return api.WithCloudStackAzFromEnvVars(cloudstackAccountVar, cloudstackDomainVar, cloudstackZone2Var, cloudstackCredentials2Var, cloudstackNetwork2Var,
cloudstackManagementServer2Var, api.WithCloudStackAz)
}
func UpdateAddCloudStackAz1() api.CloudStackFiller {
return api.WithCloudStackAzFromEnvVars(cloudstackAccountVar, cloudstackDomainVar, cloudstackZoneVar, cloudstackCredentialsVar, cloudstackNetworkVar,
cloudstackManagementServerVar, api.WithCloudStackAz)
}
func RemoveAllCloudStackAzs() api.CloudStackFiller {
return api.RemoveCloudStackAzs()
}
// CloudStackCredentialsAz1 returns the value of the environment variable for cloudstackCredentialsVar.
func CloudStackCredentialsAz1() string {
return os.Getenv(cloudstackCredentialsVar)
}
func NewCloudStack(t *testing.T, opts ...CloudStackOpt) *CloudStack {
checkRequiredEnvVars(t, requiredCloudStackEnvVars)
cmk := buildCmk(t)
c := &CloudStack{
t: t,
cmkClient: cmk,
fillers: []api.CloudStackFiller{
api.RemoveCloudStackAzs(),
api.WithCloudStackAzFromEnvVars(cloudstackAccountVar, cloudstackDomainVar, cloudstackZoneVar, cloudstackCredentialsVar, cloudstackNetworkVar,
cloudstackManagementServerVar, api.WithCloudStackAz),
api.WithCloudStackStringFromEnvVar(cloudstackSSHAuthorizedKeyVar, api.WithCloudStackSSHAuthorizedKey),
api.WithCloudStackStringFromEnvVar(cloudstackComputeOfferingLargeVar, api.WithCloudStackComputeOfferingForAllMachines),
},
}
c.cidr = os.Getenv(cloudStackCidrVar)
c.podCidr = os.Getenv(podCidrVar)
c.serviceCidr = os.Getenv(serviceCidrVar)
c.templatesRegistry = &templateRegistry{cache: map[string]string{}, generator: c}
for _, opt := range opts {
opt(c)
}
return c
}
func WithCloudStackWorkerNodeGroup(name string, workerNodeGroup *WorkerNodeGroup, fillers ...api.CloudStackMachineConfigFiller) CloudStackOpt {
return func(c *CloudStack) {
c.fillers = append(c.fillers, cloudStackMachineConfig(name, fillers...))
c.clusterFillers = append(c.clusterFillers, buildCloudStackWorkerNodeGroupClusterFiller(name, workerNodeGroup))
}
}
// WithKubeVersionAndOS returns a CloudStack Opt that adds API fillers to use a CloudStack template for
// the specified OS family and version (default if not provided), corresponding to a particular
// Kubernetes version, in addition to configuring all machine configs to use this OS family.
func withCloudStackKubeVersionAndOS(kubeVersion anywherev1.KubernetesVersion, os OS, release *releasev1.EksARelease) CloudStackOpt {
return func(c *CloudStack) {
c.fillers = append(c.fillers,
c.templateForKubeVersionAndOS(kubeVersion, os, release),
)
}
}
// WithCloudStackRedhat125 returns a function which can be invoked to configure the Cloudstack object to be compatible with K8s 1.25.
func WithCloudStackRedhat125() CloudStackOpt {
return withCloudStackKubeVersionAndOS(anywherev1.Kube125, RedHat8, nil)
}
// WithCloudStackRedhat126 returns a function which can be invoked to configure the Cloudstack object to be compatible with K8s 1.26.
func WithCloudStackRedhat126() CloudStackOpt {
return withCloudStackKubeVersionAndOS(anywherev1.Kube126, RedHat8, nil)
}
// WithCloudStackRedhat127 returns a function which can be invoked to configure the Cloudstack object to be compatible with K8s 1.27.
func WithCloudStackRedhat127() CloudStackOpt {
return withCloudStackKubeVersionAndOS(anywherev1.Kube127, RedHat8, nil)
}
// WithCloudStackRedhat128 returns a function which can be invoked to configure the Cloudstack object to be compatible with K8s 1.28.
func WithCloudStackRedhat128() CloudStackOpt {
return withCloudStackKubeVersionAndOS(anywherev1.Kube128, RedHat8, nil)
}
// WithCloudStackRedhat129 returns a function which can be invoked to configure the Cloudstack object to be compatible with K8s 1.29.
func WithCloudStackRedhat129() CloudStackOpt {
return withCloudStackKubeVersionAndOS(anywherev1.Kube129, RedHat8, nil)
}
// WithCloudStackRedhat9Kubernetes125 returns a function which can be invoked to configure the Cloudstack object to be compatible with K8s 1.25.
func WithCloudStackRedhat9Kubernetes125() CloudStackOpt {
return withCloudStackKubeVersionAndOS(anywherev1.Kube125, RedHat9, nil)
}
// WithCloudStackRedhat9Kubernetes126 returns a function which can be invoked to configure the Cloudstack object to be compatible with K8s 1.26.
func WithCloudStackRedhat9Kubernetes126() CloudStackOpt {
return withCloudStackKubeVersionAndOS(anywherev1.Kube126, RedHat9, nil)
}
// WithCloudStackRedhat9Kubernetes127 returns a function which can be invoked to configure the Cloudstack object to be compatible with K8s 1.27.
func WithCloudStackRedhat9Kubernetes127() CloudStackOpt {
return withCloudStackKubeVersionAndOS(anywherev1.Kube127, RedHat9, nil)
}
// WithCloudStackRedhat9Kubernetes128 returns a function which can be invoked to configure the Cloudstack object to be compatible with K8s 1.28.
func WithCloudStackRedhat9Kubernetes128() CloudStackOpt {
return withCloudStackKubeVersionAndOS(anywherev1.Kube128, RedHat9, nil)
}
// WithCloudStackRedhat9Kubernetes129 returns a function which can be invoked to configure the Cloudstack object to be compatible with K8s 1.29.
func WithCloudStackRedhat9Kubernetes129() CloudStackOpt {
return withCloudStackKubeVersionAndOS(anywherev1.Kube129, RedHat9, nil)
}
func WithCloudStackFillers(fillers ...api.CloudStackFiller) CloudStackOpt {
return func(c *CloudStack) {
c.fillers = append(c.fillers, fillers...)
}
}
func (c *CloudStack) Name() string {
return "cloudstack"
}
func (c *CloudStack) Setup() {}
// UpdateKubeConfig customizes generated kubeconfig for the provider.
func (c *CloudStack) UpdateKubeConfig(content *[]byte, clusterName string) error {
return nil
}
// ClusterConfigUpdates satisfies the test framework Provider.
func (c *CloudStack) ClusterConfigUpdates() []api.ClusterConfigFiller {
controlPlaneIP, err := GetIP(c.cidr, ClusterIPPoolEnvVar)
if err != nil {
c.t.Fatalf("failed to get cluster ip for test environment: %v", err)
}
f := make([]api.ClusterFiller, 0, len(c.clusterFillers)+3)
f = append(f, c.clusterFillers...)
f = append(f,
api.WithPodCidr(os.Getenv(podCidrVar)),
api.WithServiceCidr(os.Getenv(serviceCidrVar)),
api.WithControlPlaneEndpointIP(controlPlaneIP))
return []api.ClusterConfigFiller{api.ClusterToConfigFiller(f...), api.CloudStackToConfigFiller(c.fillers...)}
}
func (c *CloudStack) CleanupVMs(clusterName string) error {
return cleanup.CleanUpCloudstackTestResources(context.Background(), clusterName, false)
}
func (c *CloudStack) WithProviderUpgrade(fillers ...api.CloudStackFiller) ClusterE2ETestOpt {
return func(e *ClusterE2ETest) {
e.UpdateClusterConfig(api.CloudStackToConfigFiller(fillers...))
}
}
func (c *CloudStack) WithProviderUpgradeGit(fillers ...api.CloudStackFiller) ClusterE2ETestOpt {
return func(e *ClusterE2ETest) {
e.UpdateClusterConfig(api.CloudStackToConfigFiller(fillers...))
}
}
func (c *CloudStack) getControlPlaneIP() (string, error) {
value, ok := os.LookupEnv(cloudStackClusterIPPoolEnvVar)
var clusterIP string
var err error
if ok && value != "" {
clusterIP, err = PopIPFromEnv(cloudStackClusterIPPoolEnvVar)
if err != nil {
c.t.Fatalf("failed to pop cluster ip from test environment: %v", err)
}
} else {
clusterIP, err = GenerateUniqueIp(c.cidr)
if err != nil {
c.t.Fatalf("failed to generate ip for cloudstack %s: %v", c.cidr, err)
}
}
return clusterIP, nil
}
func RequiredCloudstackEnvVars() []string {
return requiredCloudStackEnvVars
}
func (c *CloudStack) WithNewCloudStackWorkerNodeGroup(name string, workerNodeGroup *WorkerNodeGroup, fillers ...api.CloudStackMachineConfigFiller) ClusterE2ETestOpt {
return func(e *ClusterE2ETest) {
e.UpdateClusterConfig(
api.CloudStackToConfigFiller(cloudStackMachineConfig(name, fillers...)),
api.ClusterToConfigFiller(buildCloudStackWorkerNodeGroupClusterFiller(name, workerNodeGroup)),
)
}
}
// WithNewWorkerNodeGroup returns an api.ClusterFiller that adds a new workerNodeGroupConfiguration and
// a corresponding CloudStackMachineConfig to the cluster config.
func (c *CloudStack) WithNewWorkerNodeGroup(name string, workerNodeGroup *WorkerNodeGroup) api.ClusterConfigFiller {
return api.JoinClusterConfigFillers(
api.CloudStackToConfigFiller(cloudStackMachineConfig(name)),
api.ClusterToConfigFiller(buildCloudStackWorkerNodeGroupClusterFiller(name, workerNodeGroup)),
)
}
// WithWorkerNodeGroupConfiguration returns an api.ClusterFiller that adds a new workerNodeGroupConfiguration item to the cluster config.
func (c *CloudStack) WithWorkerNodeGroupConfiguration(name string, workerNodeGroup *WorkerNodeGroup) api.ClusterConfigFiller {
return api.ClusterToConfigFiller(buildCloudStackWorkerNodeGroupClusterFiller(name, workerNodeGroup))
}
func cloudStackMachineConfig(name string, fillers ...api.CloudStackMachineConfigFiller) api.CloudStackFiller {
f := make([]api.CloudStackMachineConfigFiller, 0, len(fillers)+2)
// Need to add these because at this point the default fillers that assign these
// values to all machines have already ran
f = append(f,
api.WithCloudStackComputeOffering(os.Getenv(cloudstackComputeOfferingLargeVar)),
api.WithCloudStackSSHKey(os.Getenv(cloudstackSSHAuthorizedKeyVar)),
)
f = append(f, fillers...)
return api.WithCloudStackMachineConfig(name, f...)
}
// templateForKubeVersionAndOS returns a CloudStack filler for the given OS and Kubernetes version.
func (c *CloudStack) templateForKubeVersionAndOS(kubeVersion anywherev1.KubernetesVersion, os OS, release *releasev1.EksARelease) api.CloudStackFiller {
var template string
if release == nil {
template = c.templateForDevRelease(kubeVersion, os)
} else {
template = c.templatesRegistry.templateForRelease(c.t, release, kubeVersion, os)
}
return api.WithCloudStackTemplateForAllMachines(template)
}
// Redhat125Template returns cloudstack filler for 1.25 RedHat.
func (c *CloudStack) Redhat125Template() api.CloudStackFiller {
return c.templateForKubeVersionAndOS(anywherev1.Kube125, RedHat8, nil)
}
// Redhat126Template returns cloudstack filler for 1.26 RedHat.
func (c *CloudStack) Redhat126Template() api.CloudStackFiller {
return c.templateForKubeVersionAndOS(anywherev1.Kube126, RedHat8, nil)
}
// Redhat127Template returns cloudstack filler for 1.27 RedHat.
func (c *CloudStack) Redhat127Template() api.CloudStackFiller {
return c.templateForKubeVersionAndOS(anywherev1.Kube127, RedHat8, nil)
}
// Redhat128Template returns cloudstack filler for 1.28 RedHat.
func (c *CloudStack) Redhat128Template() api.CloudStackFiller {
return c.templateForKubeVersionAndOS(anywherev1.Kube128, RedHat8, nil)
}
// Redhat129Template returns cloudstack filler for 1.29 RedHat.
func (c *CloudStack) Redhat129Template() api.CloudStackFiller {
return c.templateForKubeVersionAndOS(anywherev1.Kube129, RedHat9, nil)
}
// Redhat9Kubernetes125Template returns cloudstack filler for 1.25 RedHat.
func (c *CloudStack) Redhat9Kubernetes125Template() api.CloudStackFiller {
return c.templateForKubeVersionAndOS(anywherev1.Kube125, RedHat9, nil)
}
// Redhat9Kubernetes126Template returns cloudstack filler for 1.26 RedHat.
func (c *CloudStack) Redhat9Kubernetes126Template() api.CloudStackFiller {
return c.templateForKubeVersionAndOS(anywherev1.Kube126, RedHat9, nil)
}
// Redhat9Kubernetes127Template returns cloudstack filler for 1.27 RedHat.
func (c *CloudStack) Redhat9Kubernetes127Template() api.CloudStackFiller {
return c.templateForKubeVersionAndOS(anywherev1.Kube127, RedHat9, nil)
}
// Redhat9Kubernetes128Template returns cloudstack filler for 1.28 RedHat.
func (c *CloudStack) Redhat9Kubernetes128Template() api.CloudStackFiller {
return c.templateForKubeVersionAndOS(anywherev1.Kube128, RedHat9, nil)
}
// Redhat9Kubernetes129Template returns cloudstack filler for 1.29 RedHat.
func (c *CloudStack) Redhat9Kubernetes129Template() api.CloudStackFiller {
return c.templateForKubeVersionAndOS(anywherev1.Kube129, RedHat9, nil)
}
func buildCloudStackWorkerNodeGroupClusterFiller(machineConfigName string, workerNodeGroup *WorkerNodeGroup) api.ClusterFiller {
// Set worker node group ref to cloudstack machine config
workerNodeGroup.MachineConfigKind = anywherev1.CloudStackMachineConfigKind
workerNodeGroup.MachineConfigName = machineConfigName
return workerNodeGroup.ClusterFiller()
}
// ClusterStateValidations returns a list of provider specific validations.
func (c *CloudStack) ClusterStateValidations() []clusterf.StateValidation {
return []clusterf.StateValidation{
clusterf.RetriableStateValidation(
retrier.NewWithMaxRetries(60, 5*time.Second),
validations.ValidateAvailabilityZones,
),
}
}
// WithKubeVersionAndOS returns a cluster config filler that sets the cluster kube version and the right template for all
// cloudstack machine configs.
func (c *CloudStack) WithKubeVersionAndOS(kubeVersion anywherev1.KubernetesVersion, os OS, release *releasev1.EksARelease) api.ClusterConfigFiller {
return api.JoinClusterConfigFillers(
api.ClusterToConfigFiller(api.WithKubernetesVersion(kubeVersion)),
api.CloudStackToConfigFiller(
c.templateForKubeVersionAndOS(kubeVersion, os, release),
),
)
}
// WithRedhat125 returns a cluster config filler that sets the kubernetes version of the cluster to 1.25
// as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhat125() api.ClusterConfigFiller {
return c.WithKubeVersionAndOS(anywherev1.Kube125, RedHat8, nil)
}
// WithRedhat126 returns a cluster config filler that sets the kubernetes version of the cluster to 1.26
// as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhat126() api.ClusterConfigFiller {
return c.WithKubeVersionAndOS(anywherev1.Kube126, RedHat8, nil)
}
// WithRedhat127 returns a cluster config filler that sets the kubernetes version of the cluster to 1.27
// as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhat127() api.ClusterConfigFiller {
return c.WithKubeVersionAndOS(anywherev1.Kube127, RedHat8, nil)
}
// WithRedhat128 returns a cluster config filler that sets the kubernetes version of the cluster to 1.28
// as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhat128() api.ClusterConfigFiller {
return c.WithKubeVersionAndOS(anywherev1.Kube128, RedHat8, nil)
}
// WithRedhat129 returns a cluster config filler that sets the kubernetes version of the cluster to 1.29
// as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhat129() api.ClusterConfigFiller {
return c.WithKubeVersionAndOS(anywherev1.Kube129, RedHat8, nil)
}
// WithRedhat9Kubernetes125 returns a cluster config filler that sets the kubernetes version of the cluster to 1.25
// as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhat9Kubernetes125() api.ClusterConfigFiller {
return c.WithKubeVersionAndOS(anywherev1.Kube125, RedHat9, nil)
}
// WithRedhat9Kubernetes126 returns a cluster config filler that sets the kubernetes version of the cluster to 1.26
// as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhat9Kubernetes126() api.ClusterConfigFiller {
return c.WithKubeVersionAndOS(anywherev1.Kube126, RedHat9, nil)
}
// WithRedhat9Kubernetes127 returns a cluster config filler that sets the kubernetes version of the cluster to 1.27
// as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhat9Kubernetes127() api.ClusterConfigFiller {
return c.WithKubeVersionAndOS(anywherev1.Kube127, RedHat9, nil)
}
// WithRedhat9Kubernetes128 returns a cluster config filler that sets the kubernetes version of the cluster to 1.28
// as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhat9Kubernetes128() api.ClusterConfigFiller {
return c.WithKubeVersionAndOS(anywherev1.Kube128, RedHat9, nil)
}
// WithRedhat9Kubernetes129 returns a cluster config filler that sets the kubernetes version of the cluster to 1.29
// as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhat9Kubernetes129() api.ClusterConfigFiller {
return c.WithKubeVersionAndOS(anywherev1.Kube129, RedHat9, nil)
}
// WithRedhatVersion returns a cluster config filler that sets the kubernetes version of the cluster to the k8s
// version provider, as well as the right redhat template for all CloudStackMachineConfigs.
func (c *CloudStack) WithRedhatVersion(version anywherev1.KubernetesVersion) api.ClusterConfigFiller {
switch version {
case anywherev1.Kube125:
return c.WithRedhat125()
case anywherev1.Kube126:
return c.WithRedhat126()
case anywherev1.Kube127:
return c.WithRedhat127()
case anywherev1.Kube128:
return c.WithRedhat128()
case anywherev1.Kube129:
return c.WithRedhat129()
default:
return nil
}
}
func (c *CloudStack) getDevRelease() *releasev1.EksARelease {
if c.devRelease == nil {
localDevRelease, err := localEksaCLIDevVersionRelease()
if err != nil {
c.t.Fatal(err)
}
c.t.Log("Using local eksa dev release:", localDevRelease.Version)
c.devRelease = localDevRelease
}
return c.devRelease
}
func (c *CloudStack) templateForDevRelease(kubeVersion anywherev1.KubernetesVersion, os OS) string {
c.t.Helper()
return c.templatesRegistry.templateForRelease(c.t, c.getDevRelease(), kubeVersion, os)
}
// envVarForTemplate Looks for explicit configuration through an env var: "T_CLOUDSTACK_TEMPLATE_{osFamily}_{eks-d version}"
// eg: T_CLOUDSTACK_TEMPLATE_REDHAT_KUBERNETES_1_23_EKS_22.
func (c *CloudStack) envVarForTemplate(os OS, eksDName string) string {
return fmt.Sprintf("T_CLOUDSTACK_TEMPLATE_%s_%s", strings.ToUpper(strings.ReplaceAll(string(os), "-", "_")), strings.ToUpper(strings.ReplaceAll(eksDName, "-", "_")))
}
// defaultNameForTemplate looks for a template: "{eks-d version}-{osFamily}"
// eg: kubernetes-1-23-eks-22-redhat.
func (c *CloudStack) defaultNameForTemplate(os OS, eksDName string) string {
return fmt.Sprintf("%s-%s", strings.ToLower(eksDName), strings.ToLower(string(os)))
}
// defaultEnvVarForTemplate returns the value of the default template env vars: "T_CLOUDSTACK_TEMPLATE_{osFamily}_{kubeVersion}"
// eg. T_CLOUDSTACK_TEMPLATE_REDHAT_1_23.
func (c *CloudStack) defaultEnvVarForTemplate(os OS, kubeVersion anywherev1.KubernetesVersion) string {
if osFamiliesForOS[os] == anywherev1.Bottlerocket {
os = OS(strings.ReplaceAll(string(os), "bottlerocket", "br"))
}
return fmt.Sprintf("T_CLOUDSTACK_TEMPLATE_%s_%s", strings.ToUpper(strings.ReplaceAll(string(os), "-", "_")), strings.ReplaceAll(string(kubeVersion), ".", "_"))
}
// searchTemplate returns template name if the given template exists in the datacenter.
func (c *CloudStack) searchTemplate(ctx context.Context, template string) (string, error) {
profile, ok := os.LookupEnv(cloudstackCredentialsVar)
if !ok {
return "", fmt.Errorf("Required environment variable for CloudStack not set: %s", cloudstackCredentialsVar)
}
templateResource := v1alpha1.CloudStackResourceIdentifier{
Name: template,
}
template, err := c.cmkClient.SearchTemplate(context.Background(), profile, templateResource)
if err != nil {
return "", err
}
return template, nil
}