From d5d4bd0b8f0ec01bd27f43d557b9b0abc6cba0f4 Mon Sep 17 00:00:00 2001 From: Mathieu Tortuyaux Date: Tue, 3 Dec 2024 11:52:18 +0100 Subject: [PATCH] cmd/ore: add akamai garbage collection Signed-off-by: Mathieu Tortuyaux --- cmd/ore/akamai/gc.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 cmd/ore/akamai/gc.go diff --git a/cmd/ore/akamai/gc.go b/cmd/ore/akamai/gc.go new file mode 100644 index 000000000..990ede762 --- /dev/null +++ b/cmd/ore/akamai/gc.go @@ -0,0 +1,35 @@ +// Copyright The Mantle Authors. +// SPDX-License-Identifier: Apache-2.0 + +package akamai + +import ( + "fmt" + "time" + + "github.com/spf13/cobra" +) + +var ( + cmdGC = &cobra.Command{ + Use: "gc", + Short: "GC resources in Akamai", + Long: `Delete instances and images created over the given duration ago`, + RunE: runGC, + } + + gcDuration time.Duration +) + +func init() { + Akamai.AddCommand(cmdGC) + cmdGC.Flags().DurationVar(&gcDuration, "duration", 5*time.Hour, "how old resources must be before they're considered garbage") +} + +func runGC(cmd *cobra.Command, args []string) error { + if err := API.GC(cmd.Context(), gcDuration); err != nil { + return fmt.Errorf("running garbage collection: %w", err) + } + + return nil +}