Skip to content

Commit

Permalink
🐛 Fix asset garbage collection (#903)
Browse files Browse the repository at this point in the history
Fix runtime and start separate jobs for objects and container images.

Fixes #893

Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker authored Oct 30, 2023
1 parent 6d85f63 commit f9421b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/mondoo-operator/garbage_collect/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func GarbageCollectCmd(ctx context.Context, client scanapiclient.ScanApiClient,

if platformRuntime != "" {
switch platformRuntime {
case "k8s", "docker-image":
case "k8s-cluster", "docker-image":
gcOpts.PlatformRuntime = platformRuntime
default:
return fmt.Errorf("no matching platform runtime found for (%s)", platformRuntime)
Expand Down
18 changes: 13 additions & 5 deletions cmd/mondoo-operator/k8s_scan/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,23 @@ func init() {

// If scanning successful, now attempt some cleanup of older assets
if *setManagedBy != "" && *cleanupOlderThan != "" {
platformRuntime := "k8s"
if *scanContainerImages {
platformRuntime = "docker-image"
}
platformRuntime := "k8s-cluster"
logger.Info("garbage collecting assets", "platformRuntime", platformRuntime, "cleanupOlderThan", *cleanupOlderThan)

err = garbage_collect.GarbageCollectCmd(ctx, client, platformRuntime, *cleanupOlderThan, *setManagedBy, make(map[string]string), logger)
if err != nil {
logger.Error(err, "error while garbage collecting assets; will attempt on next scan")
logger.Error(err, "error while garbage collecting assets; will attempt on next scan", "platform", platformRuntime)
}
if *scanContainerImages {
platformRuntime = "docker-image"
logger.Info("garbage collecting assets", "platformRuntime", platformRuntime, "cleanupOlderThan", *cleanupOlderThan)
err = garbage_collect.GarbageCollectCmd(ctx, client, platformRuntime, *cleanupOlderThan, *setManagedBy, make(map[string]string), logger)
if err != nil {
logger.Error(err, "error while garbage collecting assets; will attempt on next scan", "platform", platformRuntime)
}
}
} else {
logger.Info("skipping garbage collection of assets; either --set-managed-by or --cleanup-assets-older-than are missing")
}

return nil
Expand Down

0 comments on commit f9421b5

Please sign in to comment.