Skip to content

Commit 9436cca

Browse files
fix(cleanup): properly handle multi-platform images by BuiltWithinLastNHours policy (#6913)
Signed-off-by: Aleksei Igrychev <aleksei.igrychev@palark.com>
1 parent 35137df commit 9436cca

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pkg/cleaning/cleanup.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,22 @@ func (m *cleanupManager) run(ctx context.Context) error {
188188
stage_manager.ProtectionReasonBuiltWithinLastNHoursPolicy.SetDescription(fmt.Sprintf("built within last %d hours", keepImagesBuiltWithinLastNHours))
189189

190190
if !(m.ConfigMetaCleanup.DisableBuiltWithinLastNHoursPolicy || keepImagesBuiltWithinLastNHours == 0) {
191+
loop:
191192
for stageDescToDelete := range m.stageManager.GetStageDescSet().Iter() {
192-
if (time.Since(stageDescToDelete.Info.GetCreatedAt()).Hours()) <= float64(keepImagesBuiltWithinLastNHours) {
193-
m.stageManager.MarkStageDescAsProtected(stageDescToDelete, stage_manager.ProtectionReasonBuiltWithinLastNHoursPolicy, false)
193+
var hoursSinceCreationList []float64
194+
if stageDescToDelete.Info.IsIndex {
195+
for _, platformInfo := range stageDescToDelete.Info.Index {
196+
hoursSinceCreationList = append(hoursSinceCreationList, time.Since(platformInfo.GetCreatedAt()).Hours())
197+
}
198+
} else {
199+
hoursSinceCreationList = append(hoursSinceCreationList, time.Since(stageDescToDelete.Info.GetCreatedAt()).Hours())
200+
}
201+
202+
for _, hoursSinceCreation := range hoursSinceCreationList {
203+
if hoursSinceCreation <= float64(keepImagesBuiltWithinLastNHours) {
204+
m.stageManager.MarkStageDescAsProtected(stageDescToDelete, stage_manager.ProtectionReasonBuiltWithinLastNHoursPolicy, false)
205+
continue loop
206+
}
194207
}
195208
}
196209
}

0 commit comments

Comments
 (0)