Skip to content

Commit 48ddc4d

Browse files
committed
Try fix - 3
Signed-off-by: Pannaga Rao Bhoja Ramamanohara
1 parent cdb5f6a commit 48ddc4d

File tree

1 file changed

+3
-41
lines changed

1 file changed

+3
-41
lines changed

pkg/controller/jobs/leaderworkerset/leaderworkerset_reconciler.go

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ func (r *Reconciler) filterWorkloads(lws *leaderworkersetv1.LeaderWorkerSet, exi
177177
replicas = ptr.Deref(lws.Spec.Replicas, 1)
178178
)
179179

180-
if lws.Status.Replicas > replicas {
180+
maxSurge := getMaxSurge(lws)
181+
isRollingUpdate := maxSurge > 0 && lws.Status.UpdatedReplicas < replicas
182+
if isRollingUpdate && lws.Status.Replicas > replicas {
181183
replicas = lws.Status.Replicas
182184
}
183185

@@ -194,32 +196,6 @@ func (r *Reconciler) filterWorkloads(lws *leaderworkersetv1.LeaderWorkerSet, exi
194196
}
195197
}
196198

197-
maxSurge := getMaxSurge(lws)
198-
isRollingUpdate := maxSurge > 0 && lws.Status.UpdatedReplicas < ptr.Deref(lws.Spec.Replicas, 1)
199-
200-
if !isRollingUpdate {
201-
specReplicas := ptr.Deref(lws.Spec.Replicas, 1)
202-
203-
var updatedToCreate []workloadToCreate
204-
for _, wc := range toCreate {
205-
if wc.index < int(specReplicas) {
206-
updatedToCreate = append(updatedToCreate, wc)
207-
}
208-
}
209-
toCreate = updatedToCreate
210-
211-
var updatedToUpdate []*kueue.Workload
212-
for _, wl := range toUpdate {
213-
index := getWorkloadIndex(wl)
214-
if index >= 0 && index >= int(specReplicas) {
215-
toDelete[wl.Name] = wl
216-
} else {
217-
updatedToUpdate = append(updatedToUpdate, wl)
218-
}
219-
}
220-
toUpdate = updatedToUpdate
221-
}
222-
223199
return toCreate, toUpdate, slices.Collect(maps.Values(toDelete))
224200
}
225201

@@ -230,20 +206,6 @@ func getMaxSurge(lws *leaderworkersetv1.LeaderWorkerSet) int32 {
230206
return int32(lws.Spec.RolloutStrategy.RollingUpdateConfiguration.MaxSurge.IntValue())
231207
}
232208

233-
func getWorkloadIndex(wl *kueue.Workload) int {
234-
if wl.Annotations == nil {
235-
return -1
236-
}
237-
indexStr, ok := wl.Annotations[constants.ComponentWorkloadIndexAnnotation]
238-
if !ok {
239-
return -1
240-
}
241-
index, err := strconv.Atoi(indexStr)
242-
if err != nil {
243-
return -1
244-
}
245-
return index
246-
}
247209

248210
func (r *Reconciler) createPrebuiltWorkload(ctx context.Context, lws *leaderworkersetv1.LeaderWorkerSet, workloadName string, index int) error {
249211
createdWorkload, err := r.constructWorkload(lws, workloadName, index)

0 commit comments

Comments
 (0)