-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathbase_test.go
More file actions
758 lines (683 loc) · 22.5 KB
/
Copy pathbase_test.go
File metadata and controls
758 lines (683 loc) · 22.5 KB
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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
package functional
import (
"fmt"
. "github.com/onsi/gomega" //revive:disable:dot-imports
"gopkg.in/yaml.v3"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
infrav1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/api/dataplane/v1beta1"
)
var DefaultEdpmServiceAnsibleVarList = []string{
"edpm_frr_image",
"edpm_logrotate_crond_image",
"edpm_neutron_metadata_agent_image",
"edpm_nova_compute_image",
"edpm_ovn_controller_agent_image",
"edpm_ovn_bgp_agent_image",
"edpm_swift_account_image",
"edpm_swift_container_image",
"edpm_swift_object_image",
"edpm_swift_proxy_image",
}
var CustomEdpmServiceDomainTag = "test-image:latest"
var DefaultBackoffLimit = int32(6)
func CreateICSP(name types.NamespacedName, spec map[string]interface{}) client.Object {
raw := map[string]interface{}{
"apiVersion": "operator.openshift.io/v1alpha1",
"kind": "ImageContentSourcePolicy",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": spec,
}
return th.CreateUnstructured(raw)
}
func CreateMachineConfig() client.Object {
raw := map[string]interface{}{
"apiVersion": "machineconfiguration.openshift.io/v1",
"kind": "MachineConfig",
"metadata": map[string]interface{}{
"name": "99-master-generated-registries",
},
"spec": map[string]interface{}{
"config": map[string]interface{}{
"storage": map[string]interface{}{
"files": []interface{}{
map[string]interface{}{
"contents": map[string]interface{}{
"source": "data:text/plain;charset=utf-8;base64,dW5xdWFsaWZpZWQtc2VhcmNoLXJlZ2lzdHJpZXMgPSBbInJlZ2lzdHJ5LmFjY2Vzcy5yZWRoYXQuY29tIiwgImRvY2tlci5pbyJdCnNob3J0LW5hbWUtbW9kZSA9ICIiCgpbW3JlZ2lzdHJ5XV0KICBwcmVmaXggPSAiIgogIGxvY2F0aW9uID0gInJlZ2lzdHJ5LmNpLm9wZW5zaGlmdC5vcmcvb3JpZ2luLzQuMTMtMjAyMy0wMi0yNi0xNjMwMzAiCgogIFtbcmVnaXN0cnkubWlycm9yXV0KICAgIGxvY2F0aW9uID0gInJlZ2lzdHJ5Lm9rZC5ibmUtc2hpZnQubmV0Ojg0NDMvb2tkIgogICAgcHVsbC1mcm9tLW1pcnJvciA9ICJkaWdlc3Qtb25seSIKCltbcmVnaXN0cnldXQogIHByZWZpeCA9ICIiCiAgbG9jYXRpb24gPSAicmVnaXN0cnkuY2kub3BlbnNoaWZ0Lm9yZy9vcmlnaW4vNC4xMy0yMDIzLTAzLTA3LTA5NDQwNiIKCiAgW1tyZWdpc3RyeS5taXJyb3JdXQogICAgbG9jYXRpb24gPSAicmVnaXN0cnkub2tkLmJuZS1zaGlmdC5uZXQ6ODQ0My9va2QiCiAgICBwdWxsLWZyb20tbWlycm9yID0gImRpZ2VzdC1vbmx5IgoKW1tyZWdpc3RyeV1dCiAgcHJlZml4ID0gIiIKICBsb2NhdGlvbiA9ICJyZWdpc3RyeS5jaS5vcGVuc2hpZnQub3JnL29yaWdpbi9yZWxlYXNlIgoKICBbW3JlZ2lzdHJ5Lm1pcnJvcl1dCiAgICBsb2NhdGlvbiA9ICJyZWdpc3RyeS5va2QuYm5lLXNoaWZ0Lm5ldDo4NDQzL29rZCIKICAgIHB1bGwtZnJvbS1taXJyb3IgPSAiZGlnZXN0LW9ubHkiCg==",
"compression": "",
},
},
},
},
},
"overwrite": true,
"mode": 420,
"path": "/etc/containers/registries.conf",
},
}
return th.CreateUnstructured(raw)
}
// Create OpenstackDataPlaneNodeSet in k8s and test that no errors occur
func CreateDataplaneNodeSet(name types.NamespacedName, spec map[string]interface{}) *unstructured.Unstructured {
instance := DefaultDataplaneNodeSetTemplate(name, spec)
return th.CreateUnstructured(instance)
}
// Create OpenStackDataPlaneDeployment in k8s and test that no errors occur
func CreateDataplaneDeployment(name types.NamespacedName, spec map[string]interface{}) *unstructured.Unstructured {
instance := DefaultDataplaneDeploymentTemplate(name, spec)
return th.CreateUnstructured(instance)
}
// Create an OpenStackDataPlaneService with a given NamespacedName, assert on success
func CreateDataplaneService(name types.NamespacedName, globalService bool) *unstructured.Unstructured {
var raw map[string]interface{}
if globalService {
raw = DefaultDataplaneGlobalService(name)
} else {
raw = DefaultDataplaneService(name)
}
return th.CreateUnstructured(raw)
}
func CreateDataplaneServicesWithSameServiceType(name types.NamespacedName) {
CreateDataPlaneServiceFromSpec(name, map[string]interface{}{
"edpmServiceType": "nova"})
CreateDataPlaneServiceFromSpec(types.NamespacedName{
Name: "duplicate-service", Namespace: name.Namespace}, map[string]interface{}{
"edpmServiceType": "nova"})
}
// Create an OpenStackDataPlaneService with a given NamespacedName, and a given unstructured spec
func CreateDataPlaneServiceFromSpec(name types.NamespacedName, spec map[string]interface{}) *unstructured.Unstructured {
if spec["playbook"] == nil && spec["playbookContents"] == nil && spec["role"] == nil {
spec["playbook"] = "test"
}
raw := map[string]interface{}{
"apiVersion": "dataplane.openstack.org/v1beta1",
"kind": "OpenStackDataPlaneService",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": spec,
}
return th.CreateUnstructured(raw)
}
// Build CustomServiceImageSpec struct with empty `Nodes` list
func CustomServiceImageSpec() map[string]interface{} {
var ansibleServiceVars = make(map[string]interface{})
for _, svcName := range DefaultEdpmServiceAnsibleVarList {
imageAddress := fmt.Sprintf(`"%s.%s"`, svcName, CustomEdpmServiceDomainTag)
ansibleServiceVars[svcName] = imageAddress
}
return map[string]interface{}{
"preProvisioned": true,
"nodeTemplate": map[string]interface{}{
"networks": []infrav1.IPSetNetwork{
{Name: "ctlplane", SubnetName: "subnet1"},
},
"ansibleSSHPrivateKeySecret": "dataplane-ansible-ssh-private-key-secret",
"ansible": map[string]interface{}{
"ansibleVars": ansibleServiceVars,
},
},
"nodes": map[string]dataplanev1.NodeSection{"edpm-compute-node-1": {
Ansible: dataplanev1.AnsibleOpts{
AnsibleHost: "192.168.122.100",
},
}},
}
}
func CreateNetConfig(name types.NamespacedName, spec map[string]interface{}) *unstructured.Unstructured {
raw := DefaultNetConfig(name, spec)
return th.CreateUnstructured(raw)
}
func CreateDNSMasq(name types.NamespacedName, spec map[string]interface{}) *unstructured.Unstructured {
raw := DefaultDNSMasq(name, spec)
return th.CreateUnstructured(raw)
}
// Create SSHSecret
func CreateSSHSecret(name types.NamespacedName) *corev1.Secret {
return th.CreateSecret(
types.NamespacedName{Namespace: name.Namespace, Name: name.Name},
map[string][]byte{
"ssh-privatekey": []byte("blah"),
"authorized_keys": []byte("blih"),
},
)
}
// Create CABundleSecret
func CreateCABundleSecret(name types.NamespacedName) *corev1.Secret {
return th.CreateSecret(
types.NamespacedName{Namespace: name.Namespace, Name: name.Name},
map[string][]byte{
"tls-ca-bundle.pem": []byte("blah"),
},
)
}
// Create OpenStackVersion
func CreateOpenStackVersion(name types.NamespacedName) *unstructured.Unstructured {
raw := DefaultOpenStackVersion(name)
return th.CreateUnstructured(raw)
}
// Struct initialization
func DefaultOpenStackVersion(name types.NamespacedName) map[string]interface{} {
return map[string]interface{}{
"apiVersion": "core.openstack.org/v1beta1",
"kind": "OpenStackVersion",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": map[string]interface{}{
"targetVersion": "0.0.1",
},
"status": map[string]interface{}{
"availableVersion": "0.0.1",
},
}
}
func DefaultICSPSpec() map[string]interface{} {
return map[string]interface{}{
"repositoryDigestMirrors": []interface{}{
map[string]interface{}{
"mirrors": []interface{}{
"registry.okd.bne-shift.net:8443/okd", // Change to a string
},
"source": "registry.ci.openshift.org/origin/release", // Move "source" here
},
},
}
}
// Build OpenStackDataPlaneNodeSetSpec struct and fill it with preset values
func DefaultDataPlaneNodeSetSpec(nodeSetName string) map[string]interface{} {
return map[string]interface{}{
"services": []string{
"foo-service",
"foo-update-service",
"global-service",
},
"nodeTemplate": map[string]interface{}{
"ansibleSSHPrivateKeySecret": "dataplane-ansible-ssh-private-key-secret",
"ansible": map[string]interface{}{
"ansibleUser": "cloud-user",
},
},
"nodes": map[string]interface{}{
fmt.Sprintf("%s-node-1", nodeSetName): map[string]interface{}{
"hostName": "edpm-compute-node-1",
"networks": []infrav1.IPSetNetwork{
{Name: "networkinternal", SubnetName: "subnet1"},
{Name: "ctlplane", SubnetName: "subnet1"},
},
"ansible": map[string]interface{}{
"ansibleHost": "192.168.122.100",
},
},
},
"baremetalSetTemplate": map[string]interface{}{
"baremetalHosts": map[string]interface{}{
"ctlPlaneIP": map[string]interface{}{},
},
"deploymentSSHSecret": "dataplane-ansible-ssh-private-key-secret",
"ctlplaneInterface": "172.20.12.1",
},
"secretMaxSize": 1048576,
"tlsEnabled": true,
}
}
func DuplicateServiceNodeSetSpec(nodeSetName string) map[string]interface{} {
return map[string]interface{}{
"services": []string{
"foo-service",
"duplicate-service",
},
"nodeTemplate": map[string]interface{}{
"ansibleSSHPrivateKeySecret": "dataplane-ansible-ssh-private-key-secret",
"ansible": map[string]interface{}{
"ansibleUser": "cloud-user",
},
},
"nodes": map[string]interface{}{
fmt.Sprintf("%s-node-1", nodeSetName): map[string]interface{}{
"hostName": "edpm-compute-node-1",
"networks": []infrav1.IPSetNetwork{
{Name: "networkinternal", SubnetName: "subnet1"},
{Name: "ctlplane", SubnetName: "subnet1"},
},
"ansible": map[string]interface{}{
"ansibleHost": "192.168.122.100",
},
},
},
"secretMaxSize": 1048576,
"tlsEnabled": true,
"preProvisioned": true,
}
}
// Build OpenStackDataPlaneNodeSetSpec struct with empty `Nodes` list
func DefaultDataPlaneNoNodeSetSpec(tlsEnabled bool) map[string]interface{} {
spec := map[string]interface{}{
"preProvisioned": true,
"nodeTemplate": map[string]interface{}{
"networks": []infrav1.IPSetNetwork{
{Name: "networkinternal", SubnetName: "subnet1"},
{Name: "ctlplane", SubnetName: "subnet1"},
},
"ansibleSSHPrivateKeySecret": "dataplane-ansible-ssh-private-key-secret",
},
"nodes": map[string]interface{}{},
}
if tlsEnabled {
spec["tlsEnabled"] = true
}
spec["nodes"] = map[string]dataplanev1.NodeSection{"edpm-compute-node-1": {
Ansible: dataplanev1.AnsibleOpts{
AnsibleHost: "192.168.122.100",
},
}}
return spec
}
// Build OpenStackDataPlnaeDeploymentSpec and fill it with preset values
func DefaultDataPlaneDeploymentSpec() map[string]interface{} {
return map[string]interface{}{
"nodeSets": []string{
"edpm-compute-nodeset",
},
"servicesOverride": []string{},
}
}
func MinorUpdateDataPlaneDeploymentSpec() map[string]interface{} {
return map[string]interface{}{
"nodeSets": []string{
"edpm-compute-nodeset",
},
"servicesOverride": []string{"update"},
}
}
func MinorUpdateServicesDataPlaneDeploymentSpec() map[string]interface{} {
return map[string]interface{}{
"nodeSets": []string{
"edpm-compute-nodeset",
},
"servicesOverride": []string{"update-services"},
}
}
// Build OpenStackDataPlnaeDeploymentSpec with duplicate services
func DuplicateServiceDeploymentSpec() map[string]interface{} {
return map[string]interface{}{
"nodeSets": []string{
"edpm-compute-nodeset",
},
"servicesOverride": []string{
"foo-service",
"duplicate-service",
},
}
}
// Build OpenStackDataPlnaeDeploymentSpec with global service
func GlobalServiceDeploymentSpec() map[string]interface{} {
return map[string]interface{}{
"nodeSets": []string{
"alpha-nodeset",
"beta-nodeset",
},
"servicesOverride": []string{
"foo-service",
"global-service",
"foo-update-service",
},
}
}
// Build OpenStackDataPlnaeDeploymentSpec with single global service
func SingleGlobalServiceDeploymentSpec() map[string]interface{} {
return map[string]interface{}{
"nodeSets": []string{
"alpha-nodeset",
"beta-nodeset",
},
"servicesOverride": []string{
"global-service",
},
}
}
func DefaultNetConfigSpec() map[string]interface{} {
return map[string]interface{}{
"networks": []map[string]interface{}{{
"dnsDomain": "test-domain.test",
"mtu": 1500,
"name": "CtlPlane",
"serviceNet": "ctlplane",
"subnets": []map[string]interface{}{{
"allocationRanges": []map[string]interface{}{{
"end": "172.20.12.120",
"start": "172.20.12.0",
},
},
"name": "subnet1",
"cidr": "172.20.12.0/16",
"gateway": "172.20.12.1",
},
},
}, {
"dnsDomain": "test-domain.test",
"mtu": 1500,
"name": "networkinternal",
"serviceNet": "internalapi",
"subnets": []map[string]interface{}{{
"allocationRanges": []map[string]interface{}{{
"end": "172.20.13.120",
"start": "172.20.13.0",
},
},
"name": "subnet1",
"cidr": "172.20.13.0/16",
"gateway": "172.20.13.1",
},
},
},
},
}
}
func DefaultDNSMasqSpec() map[string]interface{} {
return map[string]interface{}{
"replicas": 1,
}
}
func SimulateDNSMasqComplete(name types.NamespacedName) {
Eventually(func(g Gomega) {
dnsMasq := &infrav1.DNSMasq{}
g.Expect(th.K8sClient.Get(th.Ctx, name, dnsMasq)).Should(Succeed())
dnsMasq.Status.Conditions.MarkTrue(condition.ReadyCondition, condition.ReadyMessage)
dnsMasq.Status.DNSClusterAddresses = []string{"192.168.122.80"}
dnsMasq.Status.DNSAddresses = []string{"192.168.122.80"}
g.Expect(th.K8sClient.Status().Update(th.Ctx, dnsMasq)).To(Succeed())
}, th.Timeout, th.Interval).Should(Succeed())
th.Logger.Info("Simulated DNS creation completed", "on", name)
}
// SimulateIPSetComplete - Simulates the result of the IPSet status
func SimulateDNSDataComplete(name types.NamespacedName) {
Eventually(func(g Gomega) {
dnsData := &infrav1.DNSData{}
g.Expect(th.K8sClient.Get(th.Ctx, name, dnsData)).Should(Succeed())
dnsData.Status.Conditions.MarkTrue(condition.ReadyCondition, condition.ReadyMessage)
// This can return conflict so we have the gomega.Eventually block to retry
g.Expect(th.K8sClient.Status().Update(th.Ctx, dnsData)).To(Succeed())
}, th.Timeout, th.Interval).Should(Succeed())
th.Logger.Info("Simulated dnsData creation completed", "on", name)
}
// SimulateIPSetComplete - Simulates the result of the IPSet status
func SimulateIPSetComplete(name types.NamespacedName) {
Eventually(func(g Gomega) {
IPSet := &infrav1.IPSet{}
g.Expect(th.K8sClient.Get(th.Ctx, name, IPSet)).Should(Succeed())
gateway := "172.20.12.1"
IPSet.Status.Reservation = []infrav1.IPSetReservation{
{
Address: "172.20.12.76",
Cidr: "172.20.12.0/16",
MTU: 1500,
Network: "CtlPlane",
Subnet: "subnet1",
Gateway: &gateway,
ServiceNetwork: "ctlplane",
},
{
Address: "172.20.13.76",
Cidr: "172.20.13.0/16",
MTU: 1500,
Network: "NetworkInternal",
Subnet: "subnet1",
Gateway: &gateway,
ServiceNetwork: "internalapi",
},
}
// This can return conflict so we have the gomega.Eventually block to retry
g.Expect(th.K8sClient.Status().Update(th.Ctx, IPSet)).To(Succeed())
}, th.Timeout, th.Interval).Should(Succeed())
th.Logger.Info("Simulated IPSet creation completed", "on", name)
}
// Build OpenStackDataPlaneNodeSet struct and fill it with preset values
func DefaultDataplaneNodeSetTemplate(name types.NamespacedName, spec map[string]interface{}) map[string]interface{} {
return map[string]interface{}{
"apiVersion": "dataplane.openstack.org/v1beta1",
"kind": "OpenStackDataPlaneNodeSet",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": spec,
}
}
// Build OpenStackDataPlaneDeployment struct and fill it with preset values
func DefaultDataplaneDeploymentTemplate(name types.NamespacedName, spec map[string]interface{}) map[string]interface{} {
return map[string]interface{}{
"apiVersion": "dataplane.openstack.org/v1beta1",
"kind": "OpenStackDataPlaneDeployment",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": spec,
}
}
func DefaultNetConfig(name types.NamespacedName, spec map[string]interface{}) map[string]interface{} {
return map[string]interface{}{
"apiVersion": "network.openstack.org/v1beta1",
"kind": "NetConfig",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": spec,
}
}
func DefaultDNSMasq(name types.NamespacedName, spec map[string]interface{}) map[string]interface{} {
return map[string]interface{}{
"apiVersion": "network.openstack.org/v1beta1",
"kind": "DNSMasq",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": spec,
}
}
// Create an empty OpenStackDataPlaneService struct
// containing only given NamespacedName as metadata
func DefaultDataplaneService(name types.NamespacedName) map[string]interface{} {
return map[string]interface{}{
"apiVersion": "dataplane.openstack.org/v1beta1",
"kind": "OpenStackDataPlaneService",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": map[string]interface{}{
"playbook": "test",
}}
}
// Create an empty OpenStackDataPlaneService struct
// containing only given NamespacedName as metadata
func DefaultDataplaneGlobalService(name types.NamespacedName) map[string]interface{} {
return map[string]interface{}{
"apiVersion": "dataplane.openstack.org/v1beta1",
"kind": "OpenStackDataPlaneService",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": map[string]interface{}{
"deployOnAllNodeSets": true,
"playbook": "test",
},
}
}
func CreateOpenStackControlPlane(name types.NamespacedName, spec map[string]interface{}) client.Object {
raw := map[string]interface{}{
"apiVersion": "core.openstack.org/v1beta1",
"kind": "OpenStackControlPlane",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": spec,
}
return th.CreateUnstructured(raw)
}
func GetDefaultOpenStackControlPlaneSpec(tlsIngress bool, tlsPodlevel bool) map[string]interface{} {
memcachedTemplate := map[string]interface{}{
"memcached": map[string]interface{}{
"replicas": 1,
},
}
rabbitTemplate := map[string]interface{}{
"rabbitmq": map[string]interface{}{
"replicas": 1,
},
"rabbitmq-cell1": map[string]interface{}{
"replicas": 1,
},
}
galeraTemplate := map[string]interface{}{
"openstack": map[string]interface{}{
"storageRequest": "500M",
},
"openstack-cell1": map[string]interface{}{
"storageRequest": "500M",
},
}
keystoneTemplate := map[string]interface{}{
"databaseInstance": "keystone",
"secret": "osp-secret",
}
return map[string]interface{}{
"secret": "osp-secret",
"storageClass": "local-storage",
"galera": map[string]interface{}{
"enabled": true,
"templates": galeraTemplate,
},
"rabbitmq": map[string]interface{}{
"enabled": true,
"templates": rabbitTemplate,
},
"memcached": map[string]interface{}{
"enabled": true,
"templates": memcachedTemplate,
},
"keystone": map[string]interface{}{
"enabled": true,
"template": keystoneTemplate,
},
"tls": map[string]interface{}{
"ingress": map[string]interface{}{
"enabled": tlsIngress,
"ca": map[string]interface{}{
"customIssuer": "custom-issuer",
"duration": "100h",
},
"cert": map[string]interface{}{
"duration": "10h",
},
},
"podLevel": map[string]interface{}{
"enabled": tlsPodlevel,
"internal": map[string]interface{}{
"ca": map[string]interface{}{
"duration": "100h",
},
"cert": map[string]interface{}{
"duration": "10h",
},
},
"ovn": map[string]interface{}{
"ca": map[string]interface{}{
"duration": "100h",
},
"cert": map[string]interface{}{
"duration": "10h",
},
},
},
},
}
}
// Get resources
// Retrieve OpenStackDataPlaneDeployment and check for errors
func GetDataplaneDeployment(name types.NamespacedName) *dataplanev1.OpenStackDataPlaneDeployment {
instance := &dataplanev1.OpenStackDataPlaneDeployment{}
Eventually(func(g Gomega) error {
g.Expect(k8sClient.Get(ctx, name, instance)).Should(Succeed())
return nil
}, timeout, interval).Should(Succeed())
return instance
}
// Retrieve OpenStackDataPlaneDeployment and check for errors
func GetDataplaneNodeSet(name types.NamespacedName) *dataplanev1.OpenStackDataPlaneNodeSet {
instance := &dataplanev1.OpenStackDataPlaneNodeSet{}
Eventually(func(g Gomega) error {
g.Expect(k8sClient.Get(ctx, name, instance)).Should(Succeed())
return nil
}, timeout, interval).Should(Succeed())
return instance
}
// Get service with given NamespacedName, assert on successful retrieval
func GetService(name types.NamespacedName) *dataplanev1.OpenStackDataPlaneService {
foundService := &dataplanev1.OpenStackDataPlaneService{}
Eventually(func(g Gomega) error {
g.Expect(k8sClient.Get(ctx, name, foundService)).Should(Succeed())
return nil
}, timeout, interval).Should(Succeed())
return foundService
}
// Get OpenStackDataPlaneNodeSet conditions
func DataplaneConditionGetter(name types.NamespacedName) condition.Conditions {
instance := GetDataplaneNodeSet(name)
return instance.Status.Conditions
}
// Get OpenStackDataPlaneDeployment conditions
func DataplaneDeploymentConditionGetter(name types.NamespacedName) condition.Conditions {
instance := GetDataplaneDeployment(name)
return instance.Status.Conditions
}
func GetAnsibleee(name types.NamespacedName) *batchv1.Job {
instance := &batchv1.Job{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, name, instance)).Should(Succeed())
}, timeout, interval).Should(Succeed())
return instance
}
// Delete resources
// Delete namespace from k8s, check for errors
func DeleteNamespace(name string) {
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
Expect(k8sClient.Delete(ctx, ns)).Should(Succeed())
}
func getCtlPlaneIP(secret *corev1.Secret) string {
secretData := secret.Data["inventory"]
var inv AnsibleInventory
err := yaml.Unmarshal(secretData, &inv)
if err != nil {
fmt.Printf("Error unmarshalling secretData: %v", err)
}
return inv.EdpmComputeNodeset.Hosts.Node.CtlPlaneIP
}
func findEnvVar(envVars []corev1.EnvVar) corev1.EnvVar {
for _, envVar := range envVars {
if envVar.Name == "RUNNER_EXTRA_VARS" {
return envVar
}
}
return corev1.EnvVar{}
}