@@ -26,12 +26,11 @@ import (
2626 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727 utilerrors "k8s.io/apimachinery/pkg/util/errors"
2828 "k8s.io/apimachinery/pkg/util/sets"
29+
2930 v1clientset "tkestack.io/tke/api/client/clientset/versioned/typed/platform/v1"
30- platformv1 "tkestack.io/tke/api/platform/v1"
3131 v1 "tkestack.io/tke/api/platform/v1"
3232 clusterprovider "tkestack.io/tke/pkg/platform/provider/cluster"
3333 machineprovider "tkestack.io/tke/pkg/platform/provider/machine"
34- "tkestack.io/tke/pkg/util/apiclient"
3534 "tkestack.io/tke/pkg/util/log"
3635)
3736
@@ -101,7 +100,7 @@ func (d *machineDeleter) Delete(ctx context.Context, name string) error {
101100
102101 // ensure that the status is up to date on the machine
103102 // if we get a not found error, we assume the machine is truly gone
104- machine , err = d .retryOnConflictError (machine , d .updateMachineStatusFunc )
103+ machine , err = d .retryOnConflictError (ctx , machine , d .updateMachineStatusFunc )
105104 if err != nil {
106105 if errors .IsNotFound (err ) {
107106 return nil
@@ -126,7 +125,7 @@ func (d *machineDeleter) Delete(ctx context.Context, name string) error {
126125 }
127126
128127 // we have removed content, so mark it finalized by us
129- machine , err = d .retryOnConflictError (machine , d .finalizeMachine )
128+ machine , err = d .retryOnConflictError (ctx , machine , d .finalizeMachine )
130129 if err != nil {
131130 // in normal practice, this should not be possible, but if a deployment is running
132131 // two controllers to do machine deletion that share a common finalizer token it's
@@ -159,15 +158,15 @@ func (d *machineDeleter) deleteMachine(machine *v1.Machine) error {
159158}
160159
161160// updateMachineFunc is a function that makes an update to a namespace
162- type updateMachineFunc func (machine * v1.Machine ) (* v1.Machine , error )
161+ type updateMachineFunc func (ctx context. Context , machine * v1.Machine ) (* v1.Machine , error )
163162
164163// retryOnConflictError retries the specified fn if there was a conflict error
165164// it will return an error if the UID for an object changes across retry operations.
166165// TODO RetryOnConflict should be a generic concept in client code
167- func (d * machineDeleter ) retryOnConflictError (machine * v1.Machine , fn updateMachineFunc ) (result * v1.Machine , err error ) {
166+ func (d * machineDeleter ) retryOnConflictError (ctx context. Context , machine * v1.Machine , fn updateMachineFunc ) (result * v1.Machine , err error ) {
168167 latestMachine := machine
169168 for {
170- result , err = fn (latestMachine )
169+ result , err = fn (ctx , latestMachine )
171170 if err == nil {
172171 return result , nil
173172 }
@@ -186,7 +185,7 @@ func (d *machineDeleter) retryOnConflictError(machine *v1.Machine, fn updateMach
186185}
187186
188187// updateMachineStatusFunc will verify that the status of the machine is correct
189- func (d * machineDeleter ) updateMachineStatusFunc (machine * v1.Machine ) (* v1.Machine , error ) {
188+ func (d * machineDeleter ) updateMachineStatusFunc (ctx context. Context , machine * v1.Machine ) (* v1.Machine , error ) {
190189 if machine .DeletionTimestamp .IsZero () || machine .Status .Phase == v1 .MachineTerminating {
191190 return machine , nil
192191 }
@@ -203,7 +202,7 @@ func finalized(machine *v1.Machine) bool {
203202}
204203
205204// finalizeMachine removes the specified finalizerToken and finalizes the machine
206- func (d * machineDeleter ) finalizeMachine (machine * v1.Machine ) (* v1.Machine , error ) {
205+ func (d * machineDeleter ) finalizeMachine (ctx context. Context , machine * v1.Machine ) (* v1.Machine , error ) {
207206 machineFinalize := v1.Machine {}
208207 machineFinalize .ObjectMeta = machine .ObjectMeta
209208 machineFinalize .Spec = machine .Spec
@@ -225,7 +224,7 @@ func (d *machineDeleter) finalizeMachine(machine *v1.Machine) (*v1.Machine, erro
225224 Name (machineFinalize .Name ).
226225 SubResource ("finalize" ).
227226 Body (& machineFinalize ).
228- Do (context . Background () ).
227+ Do (ctx ).
229228 Into (machine )
230229
231230 if err != nil {
@@ -241,7 +240,6 @@ type deleteResourceFunc func(ctx context.Context, deleter *machineDeleter, machi
241240
242241var deleteResourceFuncs = []deleteResourceFunc {
243242 deleteMachineProvider ,
244- deleteNode ,
245243}
246244
247245// deleteAllContent will use the client to delete each resource identified in machine.
@@ -287,39 +285,3 @@ func deleteMachineProvider(ctx context.Context, deleter *machineDeleter, machine
287285
288286 return nil
289287}
290-
291- func deleteNode (ctx context.Context , deleter * machineDeleter , machine * v1.Machine ) error {
292- log .FromContext (ctx ).Info ("deleteNode doing" )
293-
294- cluster , err := clusterprovider .GetV1ClusterByName (context .Background (), deleter .platformClient , machine .Spec .ClusterName , clusterprovider .AdminUsername )
295- if err != nil {
296- return err
297- }
298- if cluster .Status .Phase == platformv1 .ClusterTerminating {
299- return nil
300- }
301- clientset , err := cluster .Clientset ()
302- if err != nil {
303- return err
304- }
305-
306- node , err := apiclient .GetNodeByMachineIP (ctx , clientset , machine .Spec .IP )
307- if err != nil {
308- if ! errors .IsNotFound (err ) {
309- return err
310- }
311- log .FromContext (ctx ).Info ("deleteNode done" )
312- return nil
313- }
314-
315- err = clientset .CoreV1 ().Nodes ().Delete (context .Background (), node .Name , metav1.DeleteOptions {})
316- if err != nil {
317- if ! errors .IsNotFound (err ) {
318- return err
319- }
320- }
321-
322- log .FromContext (ctx ).Info ("deleteNode done" )
323-
324- return nil
325- }
0 commit comments