@@ -274,16 +274,16 @@ func (m *MachineScope) InstanceImageSpec() *compute.AttachedDisk {
274274 return disk
275275}
276276
277- // InstanceAdditionalDiskSpec returns compute instance additional attched-disk spec.
278- func ( m * MachineScope ) InstanceAdditionalDiskSpec ( ) []* compute.AttachedDisk {
279- additionalDisks := make ([]* compute.AttachedDisk , 0 , len (m . GCPMachine . Spec . AdditionalDisks ))
280- for _ , disk := range m . GCPMachine . Spec . AdditionalDisks {
277+ // instanceAdditionalDiskSpec returns compute instance additional attched-disk spec.
278+ func instanceAdditionalDiskSpec ( ctx context. Context , spec []infrav1. AttachedDiskSpec , rootDiskEncryptionKey * infrav1. CustomerEncryptionKey , zone string , resourceManagerTags infrav1. ResourceManagerTags ) []* compute.AttachedDisk {
279+ additionalDisks := make ([]* compute.AttachedDisk , 0 , len (spec ))
280+ for _ , disk := range spec {
281281 additionalDisk := & compute.AttachedDisk {
282282 AutoDelete : true ,
283283 InitializeParams : & compute.AttachedDiskInitializeParams {
284284 DiskSizeGb : ptr .Deref (disk .Size , 30 ),
285- DiskType : path .Join ("zones" , m . Zone () , "diskTypes" , string (* disk .DeviceType )),
286- ResourceManagerTags : shared .ResourceTagConvert (context . TODO (), m . GCPMachine . Spec . ResourceManagerTags ),
285+ DiskType : path .Join ("zones" , zone , "diskTypes" , string (* disk .DeviceType )),
286+ ResourceManagerTags : shared .ResourceTagConvert (ctx , resourceManagerTags ),
287287 },
288288 }
289289 if strings .HasSuffix (additionalDisk .InitializeParams .DiskType , string (infrav1 .LocalSsdDiskType )) {
@@ -297,20 +297,20 @@ func (m *MachineScope) InstanceAdditionalDiskSpec() []*compute.AttachedDisk {
297297 additionalDisk .Interface = "NVME"
298298 }
299299 if disk .EncryptionKey != nil {
300- if m . GCPMachine . Spec . RootDiskEncryptionKey . KeyType == infrav1 .CustomerManagedKey && m . GCPMachine . Spec . RootDiskEncryptionKey .ManagedKey != nil {
300+ if rootDiskEncryptionKey . KeyType == infrav1 .CustomerManagedKey && rootDiskEncryptionKey .ManagedKey != nil {
301301 additionalDisk .DiskEncryptionKey = & compute.CustomerEncryptionKey {
302- KmsKeyName : m . GCPMachine . Spec . RootDiskEncryptionKey .ManagedKey .KMSKeyName ,
302+ KmsKeyName : rootDiskEncryptionKey .ManagedKey .KMSKeyName ,
303303 }
304- if m . GCPMachine . Spec . RootDiskEncryptionKey .KMSKeyServiceAccount != nil {
305- additionalDisk .DiskEncryptionKey .KmsKeyServiceAccount = * m . GCPMachine . Spec . RootDiskEncryptionKey .KMSKeyServiceAccount
304+ if rootDiskEncryptionKey .KMSKeyServiceAccount != nil {
305+ additionalDisk .DiskEncryptionKey .KmsKeyServiceAccount = * rootDiskEncryptionKey .KMSKeyServiceAccount
306306 }
307- } else if m . GCPMachine . Spec . RootDiskEncryptionKey . KeyType == infrav1 .CustomerSuppliedKey && m . GCPMachine . Spec . RootDiskEncryptionKey .SuppliedKey != nil {
307+ } else if rootDiskEncryptionKey . KeyType == infrav1 .CustomerSuppliedKey && rootDiskEncryptionKey .SuppliedKey != nil {
308308 additionalDisk .DiskEncryptionKey = & compute.CustomerEncryptionKey {
309- RawKey : string (m . GCPMachine . Spec . RootDiskEncryptionKey .SuppliedKey .RawKey ),
310- RsaEncryptedKey : string (m . GCPMachine . Spec . RootDiskEncryptionKey .SuppliedKey .RSAEncryptedKey ),
309+ RawKey : string (rootDiskEncryptionKey .SuppliedKey .RawKey ),
310+ RsaEncryptedKey : string (rootDiskEncryptionKey .SuppliedKey .RSAEncryptedKey ),
311311 }
312- if m . GCPMachine . Spec . RootDiskEncryptionKey .KMSKeyServiceAccount != nil {
313- additionalDisk .DiskEncryptionKey .KmsKeyServiceAccount = * m . GCPMachine . Spec . RootDiskEncryptionKey .KMSKeyServiceAccount
312+ if rootDiskEncryptionKey .KMSKeyServiceAccount != nil {
313+ additionalDisk .DiskEncryptionKey .KmsKeyServiceAccount = * rootDiskEncryptionKey .KMSKeyServiceAccount
314314 }
315315 }
316316 }
@@ -375,6 +375,8 @@ func (m *MachineScope) InstanceAdditionalMetadataSpec() *compute.Metadata {
375375
376376// InstanceSpec returns instance spec.
377377func (m * MachineScope ) InstanceSpec (log logr.Logger ) * compute.Instance {
378+ ctx := context .TODO ()
379+
378380 instance := & compute.Instance {
379381 Name : m .Name (),
380382 Zone : m .Zone (),
@@ -461,7 +463,7 @@ func (m *MachineScope) InstanceSpec(log logr.Logger) *compute.Instance {
461463 }
462464
463465 instance .Disks = append (instance .Disks , m .InstanceImageSpec ())
464- instance .Disks = append (instance .Disks , m . InstanceAdditionalDiskSpec ( )... )
466+ instance .Disks = append (instance .Disks , instanceAdditionalDiskSpec ( ctx , m . GCPMachine . Spec . AdditionalDisks , m . GCPMachine . Spec . RootDiskEncryptionKey , m . Zone (), m . ResourceManagerTags () )... )
465467 instance .Metadata = m .InstanceAdditionalMetadataSpec ()
466468 instance .ServiceAccounts = append (instance .ServiceAccounts , m .InstanceServiceAccountsSpec ())
467469 instance .NetworkInterfaces = append (instance .NetworkInterfaces , m .InstanceNetworkInterfaceSpec ())
0 commit comments