@@ -223,7 +223,7 @@ func (m *MachineScope) SetAddresses(addressList []corev1.NodeAddress) {
223223// ANCHOR: MachineInstanceSpec
224224
225225// InstanceImageSpec returns compute instance image attched-disk spec.
226- func (m * MachineScope ) InstanceImageSpec () * compute.AttachedDisk {
226+ func (m * MachineScope ) InstanceImageSpec (ctx context. Context ) * compute.AttachedDisk {
227227 version := m .Machine .Spec .Version
228228 image := "capi-ubuntu-1804-k8s-" + strings .ReplaceAll (semver .MajorMinor (version ), "." , "-" )
229229 sourceImage := path .Join ("projects" , m .ClusterGetter .Project (), "global" , "images" , "family" , image )
@@ -244,7 +244,7 @@ func (m *MachineScope) InstanceImageSpec() *compute.AttachedDisk {
244244 InitializeParams : & compute.AttachedDiskInitializeParams {
245245 DiskSizeGb : m .GCPMachine .Spec .RootDeviceSize ,
246246 DiskType : path .Join ("zones" , m .Zone (), "diskTypes" , string (diskType )),
247- ResourceManagerTags : shared .ResourceTagConvert (context . TODO () , m .GCPMachine .Spec .ResourceManagerTags ),
247+ ResourceManagerTags : shared .ResourceTagConvert (ctx , m .GCPMachine .Spec .ResourceManagerTags ),
248248 SourceImage : sourceImage ,
249249 Labels : m .ClusterGetter .AdditionalLabels ().AddLabels (m .GCPMachine .Spec .AdditionalLabels ),
250250 },
@@ -406,9 +406,7 @@ func instanceGuestAcceleratorsSpec(guestAccelerators []infrav1.Accelerator) []*c
406406}
407407
408408// InstanceSpec returns instance spec.
409- func (m * MachineScope ) InstanceSpec (log logr.Logger ) * compute.Instance {
410- ctx := context .TODO ()
411-
409+ func (m * MachineScope ) InstanceSpec (ctx context.Context , log logr.Logger ) * compute.Instance {
412410 instance := & compute.Instance {
413411 Name : m .Name (),
414412 Zone : m .Zone (),
@@ -421,7 +419,7 @@ func (m *MachineScope) InstanceSpec(log logr.Logger) *compute.Instance {
421419 ),
422420 },
423421 Params : & compute.InstanceParams {
424- ResourceManagerTags : shared .ResourceTagConvert (context . TODO () , m .ResourceManagerTags ()),
422+ ResourceManagerTags : shared .ResourceTagConvert (ctx , m .ResourceManagerTags ()),
425423 },
426424 Labels : infrav1 .Build (infrav1.BuildParams {
427425 ClusterName : m .ClusterGetter .Name (),
@@ -494,7 +492,7 @@ func (m *MachineScope) InstanceSpec(log logr.Logger) *compute.Instance {
494492 }
495493 }
496494
497- instance .Disks = append (instance .Disks , m .InstanceImageSpec ())
495+ instance .Disks = append (instance .Disks , m .InstanceImageSpec (ctx ))
498496 instance .Disks = append (instance .Disks , instanceAdditionalDiskSpec (ctx , m .GCPMachine .Spec .AdditionalDisks , m .GCPMachine .Spec .RootDiskEncryptionKey , m .Zone (), m .ResourceManagerTags ())... )
499497 instance .Metadata = m .InstanceAdditionalMetadataSpec ()
500498 instance .ServiceAccounts = append (instance .ServiceAccounts , instanceServiceAccountsSpec (m .GCPMachine .Spec .ServiceAccount ))
@@ -510,14 +508,14 @@ func (m *MachineScope) InstanceSpec(log logr.Logger) *compute.Instance {
510508// ANCHOR_END: MachineInstanceSpec
511509
512510// GetBootstrapData returns the bootstrap data from the secret in the Machine's bootstrap.dataSecretName.
513- func (m * MachineScope ) GetBootstrapData () (string , error ) {
511+ func (m * MachineScope ) GetBootstrapData (ctx context. Context ) (string , error ) {
514512 if m .Machine .Spec .Bootstrap .DataSecretName == nil {
515513 return "" , errors .New ("error retrieving bootstrap data: linked Machine's bootstrap.dataSecretName is nil" )
516514 }
517515
518516 secret := & corev1.Secret {}
519517 key := types.NamespacedName {Namespace : m .Namespace (), Name : * m .Machine .Spec .Bootstrap .DataSecretName }
520- if err := m .client .Get (context . TODO () , key , secret ); err != nil {
518+ if err := m .client .Get (ctx , key , secret ); err != nil {
521519 return "" , errors .Wrapf (err , "failed to retrieve bootstrap data secret for GCPMachine %s/%s" , m .Namespace (), m .Name ())
522520 }
523521
@@ -530,13 +528,13 @@ func (m *MachineScope) GetBootstrapData() (string, error) {
530528}
531529
532530// PatchObject persists the cluster configuration and status.
533- func (m * MachineScope ) PatchObject () error {
534- return m .patchHelper .Patch (context . TODO () , m .GCPMachine )
531+ func (m * MachineScope ) PatchObject (ctx context. Context ) error {
532+ return m .patchHelper .Patch (ctx , m .GCPMachine )
535533}
536534
537535// Close closes the current scope persisting the cluster configuration and status.
538- func (m * MachineScope ) Close () error {
539- return m .PatchObject ()
536+ func (m * MachineScope ) Close (ctx context. Context ) error {
537+ return m .PatchObject (ctx )
540538}
541539
542540// ResourceManagerTags merges ResourceManagerTags from the scope's GCPCluster and GCPMachine. If the same key is present in both,
0 commit comments