@@ -274,16 +274,16 @@ func (m *MachineScope) InstanceImageSpec() *compute.AttachedDisk {
274
274
return disk
275
275
}
276
276
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 {
281
281
additionalDisk := & compute.AttachedDisk {
282
282
AutoDelete : true ,
283
283
InitializeParams : & compute.AttachedDiskInitializeParams {
284
284
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 ),
287
287
},
288
288
}
289
289
if strings .HasSuffix (additionalDisk .InitializeParams .DiskType , string (infrav1 .LocalSsdDiskType )) {
@@ -297,20 +297,20 @@ func (m *MachineScope) InstanceAdditionalDiskSpec() []*compute.AttachedDisk {
297
297
additionalDisk .Interface = "NVME"
298
298
}
299
299
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 {
301
301
additionalDisk .DiskEncryptionKey = & compute.CustomerEncryptionKey {
302
- KmsKeyName : m . GCPMachine . Spec . RootDiskEncryptionKey .ManagedKey .KMSKeyName ,
302
+ KmsKeyName : rootDiskEncryptionKey .ManagedKey .KMSKeyName ,
303
303
}
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
306
306
}
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 {
308
308
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 ),
311
311
}
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
314
314
}
315
315
}
316
316
}
@@ -375,6 +375,8 @@ func (m *MachineScope) InstanceAdditionalMetadataSpec() *compute.Metadata {
375
375
376
376
// InstanceSpec returns instance spec.
377
377
func (m * MachineScope ) InstanceSpec (log logr.Logger ) * compute.Instance {
378
+ ctx := context .TODO ()
379
+
378
380
instance := & compute.Instance {
379
381
Name : m .Name (),
380
382
Zone : m .Zone (),
@@ -461,7 +463,7 @@ func (m *MachineScope) InstanceSpec(log logr.Logger) *compute.Instance {
461
463
}
462
464
463
465
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 () )... )
465
467
instance .Metadata = m .InstanceAdditionalMetadataSpec ()
466
468
instance .ServiceAccounts = append (instance .ServiceAccounts , m .InstanceServiceAccountsSpec ())
467
469
instance .NetworkInterfaces = append (instance .NetworkInterfaces , m .InstanceNetworkInterfaceSpec ())
0 commit comments