Skip to content

Commit 5f3fb1f

Browse files
authored
Merge pull request #17 from CoderTH/update-random
Optimize: Skip saving/restoring images when TriggerRound/RecoveryRound <0
2 parents c87b5c7 + 49d8ffd commit 5f3fb1f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

internal/controller/snapshotpod_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ func (r *SnapshotPodReconciler) Reconcile(ctx context.Context, req ctrl.Request)
299299
logger.Error(err, "get instance error")
300300
return ctrl.Result{}, err
301301
}
302+
if sp.Spec.TriggerRound <= 0 {
303+
return ctrl.Result{}, nil
304+
}
302305
type reconciler func(ctx context.Context, sp *snapshotpodv1alpha1.SnapshotPod) error
303306
type rec struct {
304307
typ string

internal/webhooks/pod.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (p *PodImageWebhookAdmission) handlePodCreate(ctx context.Context, pod *cor
183183
pullSecret: sp.Spec.ImageSaveOptions.RegistrySecretRef,
184184
}
185185
})
186-
} else {
186+
} else if sp.Spec.RecoveryRound == 0 {
187187
sort.Slice(sp.Status.Snapshots, func(i, j int) bool {
188188
return sp.Status.Snapshots[i].TriggerRound > sp.Status.Snapshots[j].TriggerRound
189189
})
@@ -199,6 +199,8 @@ func (p *PodImageWebhookAdmission) handlePodCreate(ctx context.Context, pod *cor
199199
}
200200
}
201201
})
202+
} else {
203+
return nil, false
202204
}
203205
return out, len(out) > 0
204206
}

0 commit comments

Comments
 (0)