@@ -123,6 +123,11 @@ func (r *TensorFusionWorkloadReconciler) Reconcile(ctx context.Context, req ctrl
123
123
return ctrl.Result {RequeueAfter : constants .PendingRequeueDuration }, nil
124
124
}
125
125
126
+ if ! workload .DeletionTimestamp .IsZero () {
127
+ log .Info ("Workload is being deleted, skipping pod creation" , "name" , workload .Name , "namespace" , workload .Namespace )
128
+ return ctrl.Result {}, nil
129
+ }
130
+
126
131
// Fetch the GPUPool
127
132
pool := & tfv1.GPUPool {}
128
133
if err := r .Get (ctx , client.ObjectKey {Name : workload .Spec .PoolName }, pool ); err != nil {
@@ -144,6 +149,27 @@ func (r *TensorFusionWorkloadReconciler) Reconcile(ctx context.Context, req ctrl
144
149
}
145
150
}
146
151
152
+ result , err := r .reconcileScaling (ctx , workload , podList , workerGenerator , podTemplateHash )
153
+ if err != nil || ! result .IsZero () {
154
+ return result , err
155
+ }
156
+
157
+ if err := r .updateStatus (ctx , workload , podList .Items , workerGenerator ); err != nil {
158
+ return ctrl.Result {}, err
159
+ }
160
+
161
+ return ctrl.Result {}, nil
162
+ }
163
+
164
+ // reconcileScaling handles scaling up and down of worker pods and updates replica status
165
+ func (r * TensorFusionWorkloadReconciler ) reconcileScaling (
166
+ ctx context.Context ,
167
+ workload * tfv1.TensorFusionWorkload ,
168
+ podList * corev1.PodList ,
169
+ workerGenerator * worker.WorkerGenerator ,
170
+ podTemplateHash string ,
171
+ ) (ctrl.Result , error ) {
172
+ log := log .FromContext (ctx )
147
173
// Check if there are any Pods using the old podTemplateHash and delete them if any
148
174
if len (podList .Items ) > 0 {
149
175
var outdatedPods []corev1.Pod
@@ -210,10 +236,6 @@ func (r *TensorFusionWorkloadReconciler) Reconcile(ctx context.Context, req ctrl
210
236
}
211
237
}
212
238
213
- if err := r .updateStatus (ctx , workload , podList .Items , workerGenerator ); err != nil {
214
- return ctrl.Result {}, err
215
- }
216
-
217
239
return ctrl.Result {}, nil
218
240
}
219
241
0 commit comments