-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmachine.go
1051 lines (977 loc) · 42.9 KB
/
machine.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
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
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2021, 2022 Oracle and/or its affiliates.
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
https://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 scope
import (
"context"
"crypto/rand"
"encoding/base64"
"fmt"
"math/big"
"net/url"
"strconv"
"github.com/go-logr/logr"
infrastructurev1beta2 "github.com/oracle/cluster-api-provider-oci/api/v1beta2"
"github.com/oracle/cluster-api-provider-oci/cloud/ociutil"
"github.com/oracle/cluster-api-provider-oci/cloud/services/compute"
lb "github.com/oracle/cluster-api-provider-oci/cloud/services/loadbalancer"
nlb "github.com/oracle/cluster-api-provider-oci/cloud/services/networkloadbalancer"
"github.com/oracle/cluster-api-provider-oci/cloud/services/vcn"
"github.com/oracle/oci-go-sdk/v65/common"
"github.com/oracle/oci-go-sdk/v65/core"
"github.com/oracle/oci-go-sdk/v65/loadbalancer"
"github.com/oracle/oci-go-sdk/v65/networkloadbalancer"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2/klogr"
"k8s.io/utils/pointer"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
capierrors "sigs.k8s.io/cluster-api/errors"
capiUtil "sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
)
const OCIMachineKind = "OCIMachine"
// MachineScopeParams defines the params need to create a new MachineScope
type MachineScopeParams struct {
Logger *logr.Logger
Cluster *clusterv1.Cluster
Machine *clusterv1.Machine
Client client.Client
ComputeClient compute.ComputeClient
OCIClusterAccessor OCIClusterAccessor
OCIMachine *infrastructurev1beta2.OCIMachine
VCNClient vcn.Client
NetworkLoadBalancerClient nlb.NetworkLoadBalancerClient
LoadBalancerClient lb.LoadBalancerClient
}
type MachineScope struct {
*logr.Logger
Client client.Client
patchHelper *patch.Helper
Cluster *clusterv1.Cluster
Machine *clusterv1.Machine
ComputeClient compute.ComputeClient
OCIClusterAccessor OCIClusterAccessor
OCIMachine *infrastructurev1beta2.OCIMachine
VCNClient vcn.Client
NetworkLoadBalancerClient nlb.NetworkLoadBalancerClient
LoadBalancerClient lb.LoadBalancerClient
}
// NewMachineScope creates a MachineScope given the MachineScopeParams
func NewMachineScope(params MachineScopeParams) (*MachineScope, error) {
if params.Machine == nil {
return nil, errors.New("failed to generate new scope from nil Machine")
}
if params.OCIClusterAccessor == nil {
return nil, errors.New("failed to generate new scope from nil OCICluster")
}
if params.Logger == nil {
log := klogr.New()
params.Logger = &log
}
helper, err := patch.NewHelper(params.OCIMachine, params.Client)
if err != nil {
return nil, errors.Wrap(err, "failed to init patch helper")
}
return &MachineScope{
Logger: params.Logger,
Client: params.Client,
ComputeClient: params.ComputeClient,
Cluster: params.Cluster,
OCIClusterAccessor: params.OCIClusterAccessor,
patchHelper: helper,
Machine: params.Machine,
OCIMachine: params.OCIMachine,
VCNClient: params.VCNClient,
NetworkLoadBalancerClient: params.NetworkLoadBalancerClient,
LoadBalancerClient: params.LoadBalancerClient,
}, nil
}
// GetOrCreateMachine will get machine instance or create if the instances doesn't exist
func (m *MachineScope) GetOrCreateMachine(ctx context.Context) (*core.Instance, error) {
instance, err := m.GetMachine(ctx)
if err != nil {
return nil, err
}
if instance != nil {
m.Logger.Info("Found an existing instance")
return instance, nil
}
m.Logger.Info("Creating machine with name", "machine-name", m.OCIMachine.GetName())
cloudInitData, err := m.GetBootstrapData()
if err != nil {
return nil, err
}
shapeConfig := core.LaunchInstanceShapeConfigDetails{}
if (m.OCIMachine.Spec.ShapeConfig != infrastructurev1beta2.ShapeConfig{}) {
ocpuString := m.OCIMachine.Spec.ShapeConfig.Ocpus
if ocpuString != "" {
ocpus, err := strconv.ParseFloat(ocpuString, 32)
if err != nil {
return nil, errors.New(fmt.Sprintf("ocpus provided %s is not a valid floating point",
ocpuString))
}
shapeConfig.Ocpus = common.Float32(float32(ocpus))
}
memoryInGBsString := m.OCIMachine.Spec.ShapeConfig.MemoryInGBs
if memoryInGBsString != "" {
memoryInGBs, err := strconv.ParseFloat(memoryInGBsString, 32)
if err != nil {
return nil, errors.New(fmt.Sprintf("memoryInGBs provided %s is not a valid floating point",
memoryInGBsString))
}
shapeConfig.MemoryInGBs = common.Float32(float32(memoryInGBs))
}
baselineOcpuOptString := m.OCIMachine.Spec.ShapeConfig.BaselineOcpuUtilization
if baselineOcpuOptString != "" {
value, err := ociutil.GetBaseLineOcpuOptimizationEnum(baselineOcpuOptString)
if err != nil {
return nil, err
}
shapeConfig.BaselineOcpuUtilization = value
}
}
sourceDetails := core.InstanceSourceViaImageDetails{
ImageId: common.String(m.OCIMachine.Spec.ImageId),
}
if m.OCIMachine.Spec.BootVolumeSizeInGBs != "" {
bootVolumeSizeInGBsString := m.OCIMachine.Spec.BootVolumeSizeInGBs
if bootVolumeSizeInGBsString != "" {
bootVolumeSizeInGBs, err := strconv.ParseFloat(bootVolumeSizeInGBsString, 64)
if err != nil {
return nil, errors.New(fmt.Sprintf("bootVolumeSizeInGBs provided %s is not a valid floating point",
bootVolumeSizeInGBsString))
}
sourceDetails.BootVolumeSizeInGBs = common.Int64(int64(bootVolumeSizeInGBs))
}
}
if m.OCIMachine.Spec.InstanceSourceViaImageDetails != nil {
sourceDetails.KmsKeyId = m.OCIMachine.Spec.InstanceSourceViaImageDetails.KmsKeyId
sourceDetails.BootVolumeVpusPerGB = m.OCIMachine.Spec.InstanceSourceViaImageDetails.BootVolumeVpusPerGB
}
subnetId := m.OCIMachine.Spec.NetworkDetails.SubnetId
if subnetId == nil {
if m.IsControlPlane() {
subnetId = m.getGetControlPlaneMachineSubnet()
} else {
subnetId = m.getWorkerMachineSubnet()
}
}
var nsgIds []string
machineNsgIds := m.OCIMachine.Spec.NetworkDetails.NSGIds
nsgId := m.OCIMachine.Spec.NetworkDetails.NSGId
if machineNsgIds != nil && len(machineNsgIds) > 0 {
nsgIds = machineNsgIds
} else if nsgId != nil {
nsgIds = []string{*nsgId}
} else {
if m.IsControlPlane() {
nsgIds = m.getGetControlPlaneMachineNSGs()
} else {
nsgIds = m.getWorkerMachineNSGs()
}
}
failureDomain := m.Machine.Spec.FailureDomain
var faultDomain string
var availabilityDomain string
if failureDomain != nil {
failureDomainIndex, err := strconv.Atoi(*failureDomain)
if err != nil {
m.Logger.Error(err, "Failure Domain is not a valid integer")
return nil, errors.Wrap(err, "invalid failure domain parameter, must be a valid integer")
}
m.Logger.Info("Failure Domain being used", "failure-domain", failureDomainIndex)
if failureDomainIndex < 1 || failureDomainIndex > 3 {
err = errors.New("failure domain should be a value between 1 and 3")
m.Logger.Error(err, "Failure domain should be a value between 1 and 3")
return nil, err
}
faultDomain = m.OCIClusterAccessor.GetFailureDomains()[*failureDomain].Attributes[FaultDomain]
availabilityDomain = m.OCIClusterAccessor.GetFailureDomains()[*failureDomain].Attributes[AvailabilityDomain]
} else {
randomFailureDomain, err := rand.Int(rand.Reader, big.NewInt(3))
if err != nil {
m.Logger.Error(err, "Failed to generate random failure domain")
return nil, err
}
// the random number generated is between zero and two, whereas we need a number between one and three
failureDomain = common.String(strconv.Itoa(int(randomFailureDomain.Int64()) + 1))
availabilityDomain = m.OCIClusterAccessor.GetFailureDomains()[*failureDomain].Attributes[AvailabilityDomain]
}
metadata := m.OCIMachine.Spec.Metadata
if metadata == nil {
metadata = make(map[string]string)
}
metadata["user_data"] = base64.StdEncoding.EncodeToString([]byte(cloudInitData))
tags := m.getFreeFormTags()
definedTags := ConvertMachineDefinedTags(m.OCIMachine.Spec.DefinedTags)
launchDetails := core.LaunchInstanceDetails{DisplayName: common.String(m.OCIMachine.Name),
SourceDetails: sourceDetails,
CreateVnicDetails: &core.CreateVnicDetails{
SubnetId: subnetId,
AssignPublicIp: common.Bool(m.OCIMachine.Spec.NetworkDetails.AssignPublicIp),
FreeformTags: tags,
DefinedTags: definedTags,
HostnameLabel: m.OCIMachine.Spec.NetworkDetails.HostnameLabel,
SkipSourceDestCheck: m.OCIMachine.Spec.NetworkDetails.SkipSourceDestCheck,
AssignPrivateDnsRecord: m.OCIMachine.Spec.NetworkDetails.AssignPrivateDnsRecord,
DisplayName: m.OCIMachine.Spec.NetworkDetails.DisplayName,
},
ComputeClusterId: m.OCIMachine.Spec.ComputeClusterId,
Metadata: metadata,
Shape: common.String(m.OCIMachine.Spec.Shape),
AvailabilityDomain: common.String(availabilityDomain),
CompartmentId: common.String(m.getCompartmentId()),
IsPvEncryptionInTransitEnabled: common.Bool(m.OCIMachine.Spec.IsPvEncryptionInTransitEnabled),
FreeformTags: tags,
DefinedTags: definedTags,
// ExtendedMetadata: m.OCIMachine.Spec.ExtendedMetadata,
DedicatedVmHostId: m.OCIMachine.Spec.DedicatedVmHostId,
}
// Compute API does not behave well if the shape config is empty for fixed shapes
// hence set it only if it non empty
if (shapeConfig != core.LaunchInstanceShapeConfigDetails{}) {
launchDetails.ShapeConfig = &shapeConfig
}
if faultDomain != "" {
launchDetails.FaultDomain = common.String(faultDomain)
}
launchDetails.CreateVnicDetails.NsgIds = nsgIds
if m.OCIMachine.Spec.CapacityReservationId != nil {
launchDetails.CapacityReservationId = m.OCIMachine.Spec.CapacityReservationId
}
launchDetails.AgentConfig = m.getAgentConfig()
launchDetails.LaunchOptions = m.getLaunchOptions()
launchDetails.InstanceOptions = m.getInstanceOptions()
launchDetails.AvailabilityConfig = m.getAvailabilityConfig()
launchDetails.PreemptibleInstanceConfig = m.getPreemptibleInstanceConfig()
launchDetails.PlatformConfig = m.getPlatformConfig()
launchDetails.LaunchVolumeAttachments = m.getLaunchVolumeAttachments()
req := core.LaunchInstanceRequest{LaunchInstanceDetails: launchDetails,
OpcRetryToken: ociutil.GetOPCRetryToken(string(m.OCIMachine.UID))}
resp, err := m.ComputeClient.LaunchInstance(ctx, req)
if err != nil {
return nil, err
} else {
return &resp.Instance, nil
}
}
func (m *MachineScope) getFreeFormTags() map[string]string {
tags := ociutil.BuildClusterTags(m.OCIClusterAccessor.GetOCIResourceIdentifier())
// first use cluster level tags, then override with machine level tags
if m.OCIClusterAccessor.GetFreeformTags() != nil {
for k, v := range m.OCIClusterAccessor.GetFreeformTags() {
tags[k] = v
}
}
if m.OCIMachine.Spec.FreeformTags != nil {
for k, v := range m.OCIMachine.Spec.FreeformTags {
tags[k] = v
}
}
return tags
}
// DeleteMachine terminates the instance using InstanceId from the OCIMachine spec and deletes the boot volume
func (m *MachineScope) DeleteMachine(ctx context.Context, instance *core.Instance) error {
req := core.TerminateInstanceRequest{InstanceId: instance.Id,
PreserveBootVolume: common.Bool(m.OCIMachine.Spec.PreserveBootVolume),
PreserveDataVolumesCreatedAtLaunch: common.Bool(m.OCIMachine.Spec.PreserveDataVolumesCreatedAtLaunch),
}
_, err := m.ComputeClient.TerminateInstance(ctx, req)
return err
}
// IsResourceCreatedByClusterAPI determines if the instance was created by the cluster using the
// tags created at instance launch.
func (m *MachineScope) IsResourceCreatedByClusterAPI(resourceFreeFormTags map[string]string) bool {
tagsAddedByClusterAPI := ociutil.BuildClusterTags(string(m.OCIClusterAccessor.GetOCIResourceIdentifier()))
for k, v := range tagsAddedByClusterAPI {
if resourceFreeFormTags[k] != v {
return false
}
}
return true
}
func (m *MachineScope) getMachineFromOCID(ctx context.Context, instanceID *string) (*core.Instance, error) {
req := core.GetInstanceRequest{InstanceId: instanceID}
// Send the request using the service client
resp, err := m.ComputeClient.GetInstance(ctx, req)
if err != nil {
return nil, err
}
return &resp.Instance, nil
}
// GetMachineByDisplayName returns the machine from the compartment if there is a matching DisplayName,
// and it was created by the cluster
func (m *MachineScope) GetMachineByDisplayName(ctx context.Context, name string) (*core.Instance, error) {
var page *string
for {
req := core.ListInstancesRequest{DisplayName: common.String(name),
CompartmentId: common.String(m.getCompartmentId()), Page: page}
resp, err := m.ComputeClient.ListInstances(ctx, req)
if err != nil {
return nil, err
}
if len(resp.Items) == 0 {
return nil, nil
}
for _, instance := range resp.Items {
if m.IsResourceCreatedByClusterAPI(instance.FreeformTags) {
return &instance, nil
}
}
if resp.OpcNextPage == nil {
break
} else {
page = resp.OpcNextPage
}
}
return nil, nil
}
// PatchObject persists the cluster configuration and status.
func (m *MachineScope) PatchObject(ctx context.Context) error {
conditions.SetSummary(m.OCIMachine)
return m.patchHelper.Patch(ctx, m.OCIMachine)
}
// Close closes the current scope persisting the cluster configuration and status.
func (m *MachineScope) Close(ctx context.Context) error {
return m.PatchObject(ctx)
}
// GetBootstrapData returns the bootstrap data from the secret in the Machine's bootstrap.dataSecretName.
func (m *MachineScope) GetBootstrapData() (string, error) {
if m.Machine.Spec.Bootstrap.DataSecretName == nil {
return "", errors.New("error retrieving bootstrap data: linked Machine's bootstrap.dataSecretName is nil")
}
secret := &corev1.Secret{}
key := types.NamespacedName{Namespace: m.Machine.Namespace, Name: *m.Machine.Spec.Bootstrap.DataSecretName}
if err := m.Client.Get(context.TODO(), key, secret); err != nil {
return "", errors.Wrapf(err, "failed to retrieve bootstrap data secret for OCIMachine %s/%s", m.Machine.Namespace, m.Machine.Name)
}
value, ok := secret.Data["value"]
if !ok {
return "", errors.New("error retrieving bootstrap data: secret value key is missing")
}
return string(value), nil
}
// Name returns the OCIMachine name.
func (m *MachineScope) Name() string {
return m.OCIMachine.Name
}
// GetInstanceId returns the OCIMachine instance id.
func (m *MachineScope) GetInstanceId() *string {
return m.OCIMachine.Spec.InstanceId
}
// SetReady sets the OCIMachine Ready Status.
func (m *MachineScope) SetReady() {
m.OCIMachine.Status.Ready = true
}
// SetNotReady sets the OCIMachine Ready Status to false.
func (m *MachineScope) SetNotReady() {
m.OCIMachine.Status.Ready = false
}
// IsReady returns the ready status of the machine.
func (m *MachineScope) IsReady() bool {
return m.OCIMachine.Status.Ready
}
// SetFailureMessage sets the OCIMachine status error message.
func (m *MachineScope) SetFailureMessage(v error) {
m.OCIMachine.Status.FailureMessage = pointer.StringPtr(v.Error())
}
// SetFailureReason sets the OCIMachine status error reason.
func (m *MachineScope) SetFailureReason(v capierrors.MachineStatusError) {
m.OCIMachine.Status.FailureReason = &v
}
// GetMachine will attempt to get the machine instance by instance id, or display name if not instance id
func (m *MachineScope) GetMachine(ctx context.Context) (*core.Instance, error) {
if m.GetInstanceId() != nil {
return m.getMachineFromOCID(ctx, m.GetInstanceId())
}
instance, err := m.GetMachineByDisplayName(ctx, m.OCIMachine.Name)
if err != nil {
return nil, err
}
return instance, err
}
// GetMachineIPFromStatus returns the IP address from the OCIMachine's status if it is the Internal IP
func (m *MachineScope) GetMachineIPFromStatus() (string, error) {
machine := m.OCIMachine
if machine.Status.Addresses == nil || len(machine.Status.Addresses) == 0 {
return "", errors.New("could not find machine IP Address in status object")
}
for _, ip := range machine.Status.Addresses {
if ip.Type == clusterv1.MachineInternalIP {
return ip.Address, nil
}
}
return "", errors.New("could not find machine Internal IP Address in status object")
}
// GetInstanceIp returns the OCIMachine's instance IP from its primary VNIC attachment.
//
// See https://docs.oracle.com/en-us/iaas/Content/Network/Tasks/managingVNICs.htm for more on VNICs
func (m *MachineScope) GetInstanceIPs(ctx context.Context) ([]clusterv1.MachineAddress, error) {
addresses := []clusterv1.MachineAddress{}
var page *string
for {
resp, err := m.ComputeClient.ListVnicAttachments(ctx, core.ListVnicAttachmentsRequest{
InstanceId: m.GetInstanceId(),
CompartmentId: common.String(m.getCompartmentId()),
Page: page,
})
if err != nil {
return nil, err
}
for _, attachment := range resp.Items {
if attachment.LifecycleState != core.VnicAttachmentLifecycleStateAttached {
m.Logger.Info("VNIC attachment is not in attached state", "vnicAttachmentID", *attachment.Id)
continue
}
if attachment.VnicId == nil {
// Should never happen but lets be extra cautious as field is non-mandatory in OCI API.
m.Logger.Error(errors.New("VNIC attachment is attached but has no VNIC ID"), "vnicAttachmentID", *attachment.Id)
continue
}
vnic, err := m.VCNClient.GetVnic(ctx, core.GetVnicRequest{
VnicId: attachment.VnicId,
})
if err != nil {
return nil, err
}
if vnic.IsPrimary != nil && *vnic.IsPrimary {
if vnic.PublicIp != nil {
publicIP := clusterv1.MachineAddress{
Address: *vnic.PublicIp,
Type: clusterv1.MachineExternalIP,
}
addresses = append(addresses, publicIP)
return addresses, nil
}
privateIP := clusterv1.MachineAddress{
Address: *vnic.PrivateIp,
Type: clusterv1.MachineInternalIP,
}
addresses = append(addresses, privateIP)
return addresses, nil
}
}
if resp.OpcNextPage == nil {
break
} else {
page = resp.OpcNextPage
}
}
return nil, errors.New("primary VNIC not found")
}
// ReconcileCreateInstanceOnLB sets up backend sets for the load balancer
func (m *MachineScope) ReconcileCreateInstanceOnLB(ctx context.Context) error {
instanceIp, err := m.GetMachineIPFromStatus()
if err != nil {
return err
}
loadbalancerId := m.OCIClusterAccessor.GetNetworkSpec().APIServerLB.LoadBalancerId
m.Logger.Info("Private IP of the instance", "private-ip", instanceIp)
m.Logger.Info("Control Plane load balancer", "id", loadbalancerId)
// Check the load balancer type
loadbalancerType := m.OCIClusterAccessor.GetNetworkSpec().APIServerLB.LoadBalancerType
// By default, the load balancer type is Network Load Balancer
// Unless user specifies the load balancer type to be LBaaS
if loadbalancerType == infrastructurev1beta2.LoadBalancerTypeLB {
lb, err := m.LoadBalancerClient.GetLoadBalancer(ctx, loadbalancer.GetLoadBalancerRequest{
LoadBalancerId: loadbalancerId,
})
if err != nil {
return err
}
backendSet := lb.BackendSets[APIServerLBBackendSetName]
// When creating a LB, there is no way to set the backend Name, default backend name is the instance IP and port
// So we use default backend name instead of machine name
backendName := instanceIp + ":" + strconv.Itoa(int(m.OCIClusterAccessor.GetControlPlaneEndpoint().Port))
if !m.containsLBBackend(backendSet, backendName) {
logger := m.Logger.WithValues("backend-set", *backendSet.Name)
logger.Info("Checking work request status for create backend")
// we always try to create the backend if it exists during a reconcile loop and wait for the work request
// to complete. If there is a work request in progress, in the rare case, CAPOCI pod restarts during the
// work request, the create backend call may throw an error which is ok, as reconcile will go into
// an exponential backoff
resp, err := m.LoadBalancerClient.CreateBackend(ctx, loadbalancer.CreateBackendRequest{
LoadBalancerId: loadbalancerId,
BackendSetName: backendSet.Name,
CreateBackendDetails: loadbalancer.CreateBackendDetails{
IpAddress: common.String(instanceIp),
Port: common.Int(int(m.OCIClusterAccessor.GetControlPlaneEndpoint().Port)),
},
OpcRetryToken: ociutil.GetOPCRetryToken("%s-%s", "create-backend", string(m.OCIMachine.UID)),
})
if err != nil {
return err
}
m.OCIMachine.Status.CreateBackendWorkRequestId = *resp.OpcWorkRequestId
logger.Info("Add instance to LB backend-set", "WorkRequestId", resp.OpcWorkRequestId)
logger.Info("Waiting for LB work request to be complete")
_, err = ociutil.AwaitLBWorkRequest(ctx, m.LoadBalancerClient, resp.OpcWorkRequestId)
if err != nil {
return err
}
}
} else {
lb, err := m.NetworkLoadBalancerClient.GetNetworkLoadBalancer(ctx, networkloadbalancer.GetNetworkLoadBalancerRequest{
NetworkLoadBalancerId: loadbalancerId,
})
if err != nil {
return err
}
backendSet := lb.BackendSets[APIServerLBBackendSetName]
if !m.containsNLBBackend(backendSet, m.Name()) {
logger := m.Logger.WithValues("backend-set", *backendSet.Name)
logger.Info("Checking work request status for create backend")
// we always try to create the backend if it exists during a reconcile loop and wait for the work request
// to complete. If there is a work request in progress, in the rare case, CAPOCI pod restarts during the
// work request, the create backend call may throw an error which is ok, as reconcile will go into
// an exponential backoff
resp, err := m.NetworkLoadBalancerClient.CreateBackend(ctx, networkloadbalancer.CreateBackendRequest{
NetworkLoadBalancerId: loadbalancerId,
BackendSetName: backendSet.Name,
CreateBackendDetails: networkloadbalancer.CreateBackendDetails{
IpAddress: common.String(instanceIp),
Port: common.Int(int(m.OCIClusterAccessor.GetControlPlaneEndpoint().Port)),
Name: common.String(m.Name()),
},
OpcRetryToken: ociutil.GetOPCRetryToken("%s-%s", "create-backend", string(m.OCIMachine.UID)),
})
if err != nil {
return err
}
m.OCIMachine.Status.CreateBackendWorkRequestId = *resp.OpcWorkRequestId
logger.Info("Add instance to NLB backend-set", "WorkRequestId", resp.OpcWorkRequestId)
logger.Info("Waiting for NLB work request to be complete")
_, err = ociutil.AwaitNLBWorkRequest(ctx, m.NetworkLoadBalancerClient, resp.OpcWorkRequestId)
if err != nil {
return err
}
logger.Info("NLB Backend addition work request is complete")
}
}
return nil
}
// ReconcileDeleteInstanceOnLB checks to make sure the instance is part of a backend set then deletes the backend
// on the NetworkLoadBalancer
//
// # It will await the Work Request completion before returning
//
// See https://docs.oracle.com/en-us/iaas/Content/NetworkLoadBalancer/BackendServers/backend_server_management.htm#BackendServerManagement
// for more info on Backend Server Management
func (m *MachineScope) ReconcileDeleteInstanceOnLB(ctx context.Context) error {
loadbalancerId := m.OCIClusterAccessor.GetNetworkSpec().APIServerLB.LoadBalancerId
// Check the load balancer type
loadbalancerType := m.OCIClusterAccessor.GetNetworkSpec().APIServerLB.LoadBalancerType
if loadbalancerType == infrastructurev1beta2.LoadBalancerTypeLB {
lb, err := m.LoadBalancerClient.GetLoadBalancer(ctx, loadbalancer.GetLoadBalancerRequest{
LoadBalancerId: loadbalancerId,
})
if err != nil {
if ociutil.IsNotFound(err) {
m.Logger.Info("LB has been deleted", "lb", *loadbalancerId)
return nil
}
return err
}
backendSet := lb.BackendSets[APIServerLBBackendSetName]
// in case of delete from LB backend, if the instance does not have an IP, we consider
// the instance to not have been added in first place and hence return nil
if len(m.OCIMachine.Status.Addresses) <= 0 {
m.Logger.Info("Instance does not have IP Address, hence ignoring LBaaS reconciliation on delete")
return nil
}
instanceIp, err := m.GetMachineIPFromStatus()
if err != nil {
return err
}
backendName := instanceIp + ":" + strconv.Itoa(int(m.OCIClusterAccessor.GetControlPlaneEndpoint().Port))
if m.containsLBBackend(backendSet, backendName) {
logger := m.Logger.WithValues("backend-set", *backendSet.Name)
// in OCI CLI, the colon in the backend name is replaced by %3A
// replace the colon in the backend name by %3A to avoid the error in PCA
escapedBackendName := url.QueryEscape(backendName)
// we always try to delete the backend if it exists during a reconcile loop and wait for the work request
// to complete. If there is a work request in progress, in the rare case, CAPOCI pod restarts during the
// work request, the delete backend call may throw an error which is ok, as reconcile will go into
// an exponential backoff
resp, err := m.LoadBalancerClient.DeleteBackend(ctx, loadbalancer.DeleteBackendRequest{
LoadBalancerId: loadbalancerId,
BackendSetName: backendSet.Name,
BackendName: common.String(escapedBackendName),
})
if err != nil {
logger.Error(err, "Delete instance from LB backend-set failed",
"backendSetName", *backendSet.Name,
"backendName", escapedBackendName,
)
return err
}
m.OCIMachine.Status.DeleteBackendWorkRequestId = *resp.OpcWorkRequestId
logger.Info("Delete instance from LB backend-set", "WorkRequestId", resp.OpcWorkRequestId)
logger.Info("Waiting for LB work request to be complete")
_, err = ociutil.AwaitLBWorkRequest(ctx, m.LoadBalancerClient, resp.OpcWorkRequestId)
if err != nil {
return err
}
logger.Info("LB Backend addition work request is complete")
}
} else {
lb, err := m.NetworkLoadBalancerClient.GetNetworkLoadBalancer(ctx, networkloadbalancer.GetNetworkLoadBalancerRequest{
NetworkLoadBalancerId: loadbalancerId,
})
if err != nil {
if ociutil.IsNotFound(err) {
m.Logger.Info("NLB has been deleted", "nlb", *loadbalancerId)
return nil
}
return err
}
backendSet := lb.BackendSets[APIServerLBBackendSetName]
if m.containsNLBBackend(backendSet, m.Name()) {
logger := m.Logger.WithValues("backend-set", *backendSet.Name)
// we always try to delete the backend if it exists during a reconcile loop and wait for the work request
// to complete. If there is a work request in progress, in the rare case, CAPOCI pod restarts during the
// work request, the delete backend call may throw an error which is ok, as reconcile will go into
// an exponential backoff
resp, err := m.NetworkLoadBalancerClient.DeleteBackend(ctx, networkloadbalancer.DeleteBackendRequest{
NetworkLoadBalancerId: loadbalancerId,
BackendSetName: backendSet.Name,
BackendName: common.String(m.Name()),
})
if err != nil {
return err
}
m.OCIMachine.Status.DeleteBackendWorkRequestId = *resp.OpcWorkRequestId
logger.Info("Delete instance from LB backend-set", "WorkRequestId", resp.OpcWorkRequestId)
logger.Info("Waiting for LB work request to be complete")
_, err = ociutil.AwaitNLBWorkRequest(ctx, m.NetworkLoadBalancerClient, resp.OpcWorkRequestId)
if err != nil {
return err
}
}
}
return nil
}
func (m *MachineScope) containsNLBBackend(backendSet networkloadbalancer.BackendSet, backendName string) bool {
for _, backend := range backendSet.Backends {
if *backend.Name == backendName {
m.Logger.Info("Instance present in the backend")
return true
}
}
return false
}
func (m *MachineScope) containsLBBackend(backendSet loadbalancer.BackendSet, backendName string) bool {
for _, backend := range backendSet.Backends {
if *backend.Name == backendName {
m.Logger.Info("Instance present in the backend")
return true
}
}
return false
}
// IsControlPlane returns true if the machine is a control plane.
func (m *MachineScope) IsControlPlane() bool {
return capiUtil.IsControlPlaneMachine(m.Machine)
}
func (m *MachineScope) getCompartmentId() string {
if m.OCIMachine.Spec.CompartmentId != "" {
return m.OCIMachine.Spec.CompartmentId
}
return m.OCIClusterAccessor.GetCompartmentId()
}
func (m *MachineScope) getGetControlPlaneMachineSubnet() *string {
for _, subnet := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
if subnet.Role == infrastructurev1beta2.ControlPlaneRole {
return subnet.ID
}
}
return nil
}
func (m *MachineScope) getGetControlPlaneMachineNSGs() []string {
nsgs := make([]string, 0)
for _, nsg := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
if nsg.Role == infrastructurev1beta2.ControlPlaneRole {
if nsg.ID != nil {
nsgs = append(nsgs, *nsg.ID)
}
}
}
return nsgs
}
// getMachineSubnet iterates through the OCICluster Vcn subnets
// and returns the subnet ID if the name matches
func (m *MachineScope) getMachineSubnet(name string) (*string, error) {
for _, subnet := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
if subnet.Name == name {
return subnet.ID, nil
}
}
return nil, errors.New(fmt.Sprintf("Subnet with name %s not found for cluster %s", name, m.OCIClusterAccessor.GetName()))
}
func (m *MachineScope) getWorkerMachineSubnet() *string {
for _, subnet := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
if subnet.Role == infrastructurev1beta2.WorkerRole {
// if a subnet name is defined, use the correct subnet
if m.OCIMachine.Spec.SubnetName != "" {
if m.OCIMachine.Spec.SubnetName == subnet.Name {
return subnet.ID
}
} else {
return subnet.ID
}
}
}
return nil
}
func (m *MachineScope) getWorkerMachineNSGs() []string {
if len(m.OCIMachine.Spec.NetworkDetails.NsgNames) > 0 {
nsgs := make([]string, 0)
for _, nsgName := range m.OCIMachine.Spec.NetworkDetails.NsgNames {
for _, nsg := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
if nsg.Name == nsgName {
if nsg.ID != nil {
nsgs = append(nsgs, *nsg.ID)
}
}
}
}
return nsgs
} else {
nsgs := make([]string, 0)
for _, nsg := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
if nsg.Role == infrastructurev1beta2.WorkerRole {
if nsg.ID != nil {
nsgs = append(nsgs, *nsg.ID)
}
}
}
return nsgs
}
}
func (m *MachineScope) getAgentConfig() *core.LaunchInstanceAgentConfigDetails {
agentConfigSpec := m.OCIMachine.Spec.AgentConfig
if agentConfigSpec != nil {
agentConfig := &core.LaunchInstanceAgentConfigDetails{
IsMonitoringDisabled: agentConfigSpec.IsMonitoringDisabled,
IsManagementDisabled: agentConfigSpec.IsManagementDisabled,
AreAllPluginsDisabled: agentConfigSpec.AreAllPluginsDisabled,
}
if len(agentConfigSpec.PluginsConfig) > 0 {
pluginConfigList := make([]core.InstanceAgentPluginConfigDetails, len(agentConfigSpec.PluginsConfig))
for i, pluginConfigSpec := range agentConfigSpec.PluginsConfig {
pluginConfigRequest := core.InstanceAgentPluginConfigDetails{
Name: pluginConfigSpec.Name,
}
desiredState, _ := core.GetMappingInstanceAgentPluginConfigDetailsDesiredStateEnum(string(pluginConfigSpec.DesiredState))
pluginConfigRequest.DesiredState = desiredState
pluginConfigList[i] = pluginConfigRequest
}
agentConfig.PluginsConfig = pluginConfigList
}
return agentConfig
}
return nil
}
func (m *MachineScope) getLaunchOptions() *core.LaunchOptions {
launcOptionsSpec := m.OCIMachine.Spec.LaunchOptions
if launcOptionsSpec != nil {
launchOptions := &core.LaunchOptions{
IsConsistentVolumeNamingEnabled: launcOptionsSpec.IsConsistentVolumeNamingEnabled,
}
if launcOptionsSpec.BootVolumeType != "" {
bootVolume, _ := core.GetMappingLaunchOptionsBootVolumeTypeEnum(string(launcOptionsSpec.BootVolumeType))
launchOptions.BootVolumeType = bootVolume
}
if launcOptionsSpec.Firmware != "" {
firmware, _ := core.GetMappingLaunchOptionsFirmwareEnum(string(launcOptionsSpec.Firmware))
launchOptions.Firmware = firmware
}
if launcOptionsSpec.NetworkType != "" {
networkType, _ := core.GetMappingLaunchOptionsNetworkTypeEnum(string(launcOptionsSpec.NetworkType))
launchOptions.NetworkType = networkType
}
if launcOptionsSpec.RemoteDataVolumeType != "" {
remoteVolumeType, _ := core.GetMappingLaunchOptionsRemoteDataVolumeTypeEnum(string(launcOptionsSpec.RemoteDataVolumeType))
launchOptions.RemoteDataVolumeType = remoteVolumeType
}
return launchOptions
}
return nil
}
func (m *MachineScope) getInstanceOptions() *core.InstanceOptions {
instanceOptionsSpec := m.OCIMachine.Spec.InstanceOptions
if instanceOptionsSpec != nil {
return &core.InstanceOptions{
AreLegacyImdsEndpointsDisabled: instanceOptionsSpec.AreLegacyImdsEndpointsDisabled,
}
}
return nil
}
func (m *MachineScope) getAvailabilityConfig() *core.LaunchInstanceAvailabilityConfigDetails {
avalabilityConfigSpec := m.OCIMachine.Spec.AvailabilityConfig
if avalabilityConfigSpec != nil {
recoveryAction, _ := core.GetMappingLaunchInstanceAvailabilityConfigDetailsRecoveryActionEnum(string(avalabilityConfigSpec.RecoveryAction))
return &core.LaunchInstanceAvailabilityConfigDetails{
IsLiveMigrationPreferred: avalabilityConfigSpec.IsLiveMigrationPreferred,
RecoveryAction: recoveryAction,
}
}
return nil
}
func (m *MachineScope) getPreemptibleInstanceConfig() *core.PreemptibleInstanceConfigDetails {
preEmptibleInstanceConfigSpec := m.OCIMachine.Spec.PreemptibleInstanceConfig
if preEmptibleInstanceConfigSpec != nil {
preemptibleInstanceConfig := &core.PreemptibleInstanceConfigDetails{}
if preEmptibleInstanceConfigSpec.TerminatePreemptionAction != nil {
preemptibleInstanceConfig.PreemptionAction = core.TerminatePreemptionAction{
PreserveBootVolume: preEmptibleInstanceConfigSpec.TerminatePreemptionAction.PreserveBootVolume,
}
}
return preemptibleInstanceConfig
}
return nil
}
func (m *MachineScope) getPlatformConfig() core.PlatformConfig {
platformConfig := m.OCIMachine.Spec.PlatformConfig
if platformConfig != nil {
switch platformConfig.PlatformConfigType {
case infrastructurev1beta2.PlatformConfigTypeAmdRomeBmGpu:
numaNodesPerSocket, _ := core.GetMappingAmdRomeBmGpuPlatformConfigNumaNodesPerSocketEnum(string(platformConfig.AmdRomeBmGpuPlatformConfig.NumaNodesPerSocket))
return core.AmdRomeBmGpuPlatformConfig{
IsSecureBootEnabled: platformConfig.AmdRomeBmGpuPlatformConfig.IsSecureBootEnabled,
IsTrustedPlatformModuleEnabled: platformConfig.AmdRomeBmGpuPlatformConfig.IsTrustedPlatformModuleEnabled,
IsMeasuredBootEnabled: platformConfig.AmdRomeBmGpuPlatformConfig.IsMeasuredBootEnabled,
IsMemoryEncryptionEnabled: platformConfig.AmdRomeBmGpuPlatformConfig.IsMemoryEncryptionEnabled,
IsSymmetricMultiThreadingEnabled: platformConfig.AmdRomeBmGpuPlatformConfig.IsSymmetricMultiThreadingEnabled,
IsAccessControlServiceEnabled: platformConfig.AmdRomeBmGpuPlatformConfig.IsAccessControlServiceEnabled,
AreVirtualInstructionsEnabled: platformConfig.AmdRomeBmGpuPlatformConfig.AreVirtualInstructionsEnabled,
IsInputOutputMemoryManagementUnitEnabled: platformConfig.AmdRomeBmGpuPlatformConfig.IsInputOutputMemoryManagementUnitEnabled,
NumaNodesPerSocket: numaNodesPerSocket,
}
case infrastructurev1beta2.PlatformConfigTypeAmdRomeBm:
numaNodesPerSocket, _ := core.GetMappingAmdRomeBmPlatformConfigNumaNodesPerSocketEnum(string(platformConfig.AmdRomeBmPlatformConfig.NumaNodesPerSocket))
return core.AmdRomeBmPlatformConfig{
IsSecureBootEnabled: platformConfig.AmdRomeBmPlatformConfig.IsSecureBootEnabled,
IsTrustedPlatformModuleEnabled: platformConfig.AmdRomeBmPlatformConfig.IsTrustedPlatformModuleEnabled,
IsMeasuredBootEnabled: platformConfig.AmdRomeBmPlatformConfig.IsMeasuredBootEnabled,
IsMemoryEncryptionEnabled: platformConfig.AmdRomeBmPlatformConfig.IsMemoryEncryptionEnabled,
IsSymmetricMultiThreadingEnabled: platformConfig.AmdRomeBmPlatformConfig.IsSymmetricMultiThreadingEnabled,
IsAccessControlServiceEnabled: platformConfig.AmdRomeBmPlatformConfig.IsAccessControlServiceEnabled,
AreVirtualInstructionsEnabled: platformConfig.AmdRomeBmPlatformConfig.AreVirtualInstructionsEnabled,
IsInputOutputMemoryManagementUnitEnabled: platformConfig.AmdRomeBmPlatformConfig.IsInputOutputMemoryManagementUnitEnabled,
PercentageOfCoresEnabled: platformConfig.AmdRomeBmPlatformConfig.PercentageOfCoresEnabled,
NumaNodesPerSocket: numaNodesPerSocket,
}
case infrastructurev1beta2.PlatformConfigTypeIntelIcelakeBm:
numaNodesPerSocket, _ := core.GetMappingIntelIcelakeBmPlatformConfigNumaNodesPerSocketEnum(string(platformConfig.IntelIcelakeBmPlatformConfig.NumaNodesPerSocket))
return core.IntelIcelakeBmPlatformConfig{
IsSecureBootEnabled: platformConfig.IntelIcelakeBmPlatformConfig.IsSecureBootEnabled,
IsTrustedPlatformModuleEnabled: platformConfig.IntelIcelakeBmPlatformConfig.IsTrustedPlatformModuleEnabled,
IsMeasuredBootEnabled: platformConfig.IntelIcelakeBmPlatformConfig.IsMeasuredBootEnabled,
IsMemoryEncryptionEnabled: platformConfig.IntelIcelakeBmPlatformConfig.IsMemoryEncryptionEnabled,
IsSymmetricMultiThreadingEnabled: platformConfig.IntelIcelakeBmPlatformConfig.IsSymmetricMultiThreadingEnabled,
PercentageOfCoresEnabled: platformConfig.IntelIcelakeBmPlatformConfig.PercentageOfCoresEnabled,
IsInputOutputMemoryManagementUnitEnabled: platformConfig.IntelIcelakeBmPlatformConfig.IsInputOutputMemoryManagementUnitEnabled,
NumaNodesPerSocket: numaNodesPerSocket,
}
case infrastructurev1beta2.PlatformConfigTypeAmdvm:
return core.AmdVmPlatformConfig{
IsSecureBootEnabled: platformConfig.AmdVmPlatformConfig.IsSecureBootEnabled,
IsTrustedPlatformModuleEnabled: platformConfig.AmdVmPlatformConfig.IsTrustedPlatformModuleEnabled,
IsMeasuredBootEnabled: platformConfig.AmdVmPlatformConfig.IsMeasuredBootEnabled,
IsMemoryEncryptionEnabled: platformConfig.AmdVmPlatformConfig.IsMemoryEncryptionEnabled,
}
case infrastructurev1beta2.PlatformConfigTypeIntelVm:
return core.IntelVmPlatformConfig{
IsSecureBootEnabled: platformConfig.IntelVmPlatformConfig.IsSecureBootEnabled,
IsTrustedPlatformModuleEnabled: platformConfig.IntelVmPlatformConfig.IsTrustedPlatformModuleEnabled,
IsMeasuredBootEnabled: platformConfig.IntelVmPlatformConfig.IsMeasuredBootEnabled,
IsMemoryEncryptionEnabled: platformConfig.IntelVmPlatformConfig.IsMemoryEncryptionEnabled,
}
case infrastructurev1beta2.PlatformConfigTypeIntelSkylakeBm:
return core.IntelSkylakeBmPlatformConfig{
IsSecureBootEnabled: platformConfig.IntelSkylakeBmPlatformConfig.IsSecureBootEnabled,
IsTrustedPlatformModuleEnabled: platformConfig.IntelSkylakeBmPlatformConfig.IsTrustedPlatformModuleEnabled,
IsMeasuredBootEnabled: platformConfig.IntelSkylakeBmPlatformConfig.IsMeasuredBootEnabled,
IsMemoryEncryptionEnabled: platformConfig.IntelSkylakeBmPlatformConfig.IsMemoryEncryptionEnabled,
}
case infrastructurev1beta2.PlatformConfigTypeAmdMilanBm:
numaNodesPerSocket, _ := core.GetMappingAmdMilanBmPlatformConfigNumaNodesPerSocketEnum(string(platformConfig.AmdMilanBmPlatformConfig.NumaNodesPerSocket))
return core.AmdMilanBmPlatformConfig{
IsSecureBootEnabled: platformConfig.AmdMilanBmPlatformConfig.IsSecureBootEnabled,
IsTrustedPlatformModuleEnabled: platformConfig.AmdMilanBmPlatformConfig.IsTrustedPlatformModuleEnabled,
IsMeasuredBootEnabled: platformConfig.AmdMilanBmPlatformConfig.IsMeasuredBootEnabled,
IsMemoryEncryptionEnabled: platformConfig.AmdMilanBmPlatformConfig.IsMemoryEncryptionEnabled,
IsSymmetricMultiThreadingEnabled: platformConfig.AmdMilanBmPlatformConfig.IsSymmetricMultiThreadingEnabled,
IsAccessControlServiceEnabled: platformConfig.AmdMilanBmPlatformConfig.IsAccessControlServiceEnabled,
AreVirtualInstructionsEnabled: platformConfig.AmdMilanBmPlatformConfig.AreVirtualInstructionsEnabled,
IsInputOutputMemoryManagementUnitEnabled: platformConfig.AmdMilanBmPlatformConfig.IsInputOutputMemoryManagementUnitEnabled,
PercentageOfCoresEnabled: platformConfig.AmdMilanBmPlatformConfig.PercentageOfCoresEnabled,
NumaNodesPerSocket: numaNodesPerSocket,
}
default:
}
}
return nil
}
func (m *MachineScope) getLaunchVolumeAttachments() []core.LaunchAttachVolumeDetails {