Skip to content

Commit a7a010e

Browse files
fix reclaim resource context (#30)
1 parent 765507a commit a7a010e

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

synccontrols/sync_control.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ func (r *RealSyncControl) SyncTargets(ctx context.Context, instance api.XSetObje
147147
syncContext.FilteredTarget = filteredTargets
148148
}
149149

150+
if instance.GetDeletionTimestamp() != nil {
151+
return false, nil
152+
}
153+
150154
// sync subresource
151155
// 1. list pvcs using ownerReference
152156
// 2. adopt and retain orphaned pvcs according to PVC retention policy
@@ -904,10 +908,9 @@ func (r *RealSyncControl) CalculateStatus(_ context.Context, instance api.XSetOb
904908

905909
var readyReplicas, scheduledReplicas, replicas, terminatingReplicas, updatedReplicas, operatingReplicas, updatedReadyReplicas, availableReplicas, updatedAvailableReplicas int32
906910

907-
activeTargets := FilterOutActiveTargetWrappers(syncContext.TargetWrappers)
908-
for _, targetWrapper := range activeTargets {
911+
for _, target := range syncContext.FilteredTarget {
909912
// for naming with persistent sequences suffix, terminating targets can be shown in status
910-
if targetWrapper.GetDeletionTimestamp() != nil {
913+
if target.GetDeletionTimestamp() != nil {
911914
terminatingReplicas++
912915
if !IsTargetNamingSuffixPolicyPersistentSequence(r.xsetController.GetXSetSpec(instance)) {
913916
continue
@@ -917,30 +920,30 @@ func (r *RealSyncControl) CalculateStatus(_ context.Context, instance api.XSetOb
917920
replicas++
918921

919922
isUpdated := false
920-
if isUpdated = IsTargetUpdatedRevision(targetWrapper.Object, syncContext.UpdatedRevision.Name); isUpdated {
923+
if isUpdated = IsTargetUpdatedRevision(target, syncContext.UpdatedRevision.Name); isUpdated {
921924
updatedReplicas++
922925
}
923926

924-
if opslifecycle.IsDuringOps(r.updateConfig.XsetLabelAnnoMgr, r.scaleInLifecycleAdapter, targetWrapper) ||
925-
opslifecycle.IsDuringOps(r.updateConfig.XsetLabelAnnoMgr, r.updateLifecycleAdapter, targetWrapper) {
927+
if opslifecycle.IsDuringOps(r.updateConfig.XsetLabelAnnoMgr, r.scaleInLifecycleAdapter, target) ||
928+
opslifecycle.IsDuringOps(r.updateConfig.XsetLabelAnnoMgr, r.updateLifecycleAdapter, target) {
926929
operatingReplicas++
927930
}
928931

929-
if ready, _ := r.xsetController.CheckReadyTime(targetWrapper.Object); ready {
932+
if ready, _ := r.xsetController.CheckReadyTime(target); ready {
930933
readyReplicas++
931934
if isUpdated {
932935
updatedReadyReplicas++
933936
}
934937
}
935938

936-
if r.xsetController.CheckAvailable(targetWrapper.Object) {
939+
if r.xsetController.CheckAvailable(target) {
937940
availableReplicas++
938941
if isUpdated {
939942
updatedAvailableReplicas++
940943
}
941944
}
942945

943-
if r.xsetController.CheckScheduled(targetWrapper.Object) {
946+
if r.xsetController.CheckScheduled(target) {
944947
scheduledReplicas++
945948
}
946949
}

xset_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func (r *xSetCommonReconciler) ensureReclaimTargetsDeletion(ctx context.Context,
351351
for i := range targets {
352352
target := targets[i]
353353
if target.GetDeletionTimestamp() == nil {
354-
r.Recorder.Eventf(instance, corev1.EventTypeNormal, "TargetsDeleted", "waiting for models to be deleted gracefully before xset deleted %s/%s", instance.GetNamespace(), instance.GetName())
354+
r.Recorder.Eventf(instance, corev1.EventTypeNormal, "TargetsDeleted", "waiting for %s to be deleted gracefully before xset deleted %s/%s", instance.GetObjectKind(), instance.GetNamespace(), instance.GetName())
355355
return false, r.syncControl.BatchDeleteTargetsByLabel(ctx, r.targetControl, targets)
356356
}
357357
}

0 commit comments

Comments
 (0)