@@ -34,10 +34,12 @@ func verifyCreateUpdateAndDelete(kubeConfig, manifestPath string, parameters []s
3434 if err != nil {
3535 return err
3636 }
37+ ctx := context .Background ()
38+
3739 // This test inherently relies on replicas being one so we enforce that
3840 machineDeployment .Spec .Replicas = getInt32Ptr (1 )
3941
40- machineDeployment , err = createAndAssure (machineDeployment , client , timeout )
42+ machineDeployment , err = createAndAssure (ctx , machineDeployment , client , timeout )
4143 if err != nil {
4244 return fmt .Errorf ("failed to verify creation of node for MachineDeployment: %w" , err )
4345 }
@@ -50,7 +52,7 @@ func verifyCreateUpdateAndDelete(kubeConfig, manifestPath string, parameters []s
5052
5153 klog .Infof ("Waiting for second MachineSet to appear after updating MachineDeployment %s" , machineDeployment .Name )
5254 var machineSets []clusterv1alpha1.MachineSet
53- if err := wait .PollUntilContextTimeout (context . Background () , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
55+ if err := wait .PollUntilContextTimeout (ctx , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
5456 machineSets , err = getMatchingMachineSets (machineDeployment , client )
5557 if err != nil {
5658 return false , err
@@ -79,7 +81,7 @@ func verifyCreateUpdateAndDelete(kubeConfig, manifestPath string, parameters []s
7981 oldMachineSet = machineSets [1 ]
8082 }
8183 var machines []clusterv1alpha1.Machine
82- if err := wait .PollUntilContextTimeout (context . Background () , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
84+ if err := wait .PollUntilContextTimeout (ctx , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
8385 machines , err = getMatchingMachinesForMachineset (& newestMachineSet , client )
8486 if err != nil {
8587 return false , err
@@ -94,18 +96,18 @@ func verifyCreateUpdateAndDelete(kubeConfig, manifestPath string, parameters []s
9496 klog .Infof ("New MachineSet %s appeared with %v machines" , newestMachineSet .Name , len (machines ))
9597
9698 klog .Infof ("Waiting for new MachineSet %s to get a ready node" , newestMachineSet .Name )
97- if err := wait .PollUntilContextTimeout (context . Background () , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
98- return hasMachineReadyNode (& machines [0 ], client )
99+ if err := wait .PollUntilContextTimeout (ctx , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
100+ return hasMachineReadyNode (ctx , & machines [0 ], client )
99101 }); err != nil {
100102 return err
101103 }
102104 klog .Infof ("Found ready node for MachineSet %s" , newestMachineSet .Name )
103105
104106 klog .Infof ("Waiting for old MachineSet %s to be scaled down and have no associated machines" ,
105107 oldMachineSet .Name )
106- if err := wait .PollUntilContextTimeout (context . Background () , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
108+ if err := wait .PollUntilContextTimeout (ctx , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
107109 machineSet := & clusterv1alpha1.MachineSet {}
108- if err := client .Get (context . Background () , types.NamespacedName {Namespace : oldMachineSet .Namespace , Name : oldMachineSet .Name }, machineSet ); err != nil {
110+ if err := client .Get (ctx , types.NamespacedName {Namespace : oldMachineSet .Namespace , Name : oldMachineSet .Name }, machineSet ); err != nil {
109111 return false , err
110112 }
111113 if * machineSet .Spec .Replicas != int32 (0 ) {
@@ -130,7 +132,7 @@ func verifyCreateUpdateAndDelete(kubeConfig, manifestPath string, parameters []s
130132 klog .Infof ("Successfully set replicas of MachineDeployment %s to 0" , machineDeployment .Name )
131133
132134 klog .Infof ("Waiting for MachineDeployment %s to not have any associated machines" , machineDeployment .Name )
133- if err := wait .PollUntilContextTimeout (context . Background () , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
135+ if err := wait .PollUntilContextTimeout (ctx , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
134136 machines , err := getMatchingMachines (machineDeployment , client )
135137 return len (machines ) == 0 , err
136138 }); err != nil {
@@ -139,11 +141,11 @@ func verifyCreateUpdateAndDelete(kubeConfig, manifestPath string, parameters []s
139141 klog .Infof ("Successfully waited for MachineDeployment %s to not have any associated machines" , machineDeployment .Name )
140142
141143 klog .Infof ("Deleting MachineDeployment %s and waiting for it to disappear" , machineDeployment .Name )
142- if err := client .Delete (context . Background () , machineDeployment ); err != nil {
144+ if err := client .Delete (ctx , machineDeployment ); err != nil {
143145 return fmt .Errorf ("failed to delete MachineDeployment %s: %w" , machineDeployment .Name , err )
144146 }
145- if err := wait .PollUntilContextTimeout (context . Background () , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
146- err = client .Get (context . Background () , types.NamespacedName {Namespace : machineDeployment .Namespace , Name : machineDeployment .Name }, & clusterv1alpha1.MachineDeployment {})
147+ if err := wait .PollUntilContextTimeout (ctx , 5 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
148+ err = client .Get (ctx , types.NamespacedName {Namespace : machineDeployment .Namespace , Name : machineDeployment .Name }, & clusterv1alpha1.MachineDeployment {})
147149 if kerrors .IsNotFound (err ) {
148150 return true , nil
149151 }
0 commit comments