Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
VALIDATE_ALL_CODEBASE: false
VALIDATE_DOCKERFILE_HADOLINT: true
VALIDATE_GITHUB_ACTIONS: true
VALIDATE_GO_MODULES: true
# VALIDATE_GO_MODULES: true - cyclo config seems to be broken
VALIDATE_GITLEAKS: true
VALIDATE_YAML: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ cd volume-cleaner
* `NAMESPACE`: Target namespace to scan for unused PVCs, leave this value as an empty string to scan all namespaces
* `TIME_LABEL`: Must match controller's time label
* `NOTIF_LABEL`: Must match controller's notification label
* `IGNORE_LABEL`: If this label is true on a PVC, the scheduler will skip it (e.g.: "volume-cleaner/ignore")
* `GRACE_PERIOD`: Days before PVC deletion (e.g., "180")
* `TIME_FORMAT`: Must match controller's time format
* `DRY_RUN`: Set to "true" for testing without actual deletion
Expand Down Expand Up @@ -286,6 +287,7 @@ Le volume-cleaner est composé de 2 composants principaux :
* `NAMESPACE` : Espace de noms à scanner pour les PVC périmés; laissez cette valeur vide pour scanner tous les espaces de noms
* `TIME_LABEL` : Doit correspondre au `TIME_LABEL` du contrôleur
* `NOTIF_LABEL` : Doit correspondre au `NOTIF_LABEL` du contrôleur
* `IGNORE_LABEL` : Si cette étiquette est définie à true sur un PVC, le planificateur l’ignorera (par exemple : `volume-cleaner/ignore`).
* `GRACE_PERIOD` : Nombre de jours avant suppression du PVC (par ex. `"180"`)
* `TIME_FORMAT` : Doit correspondre au `TIME_FORMAT` du contrôleur
* `DRY_RUN` : À `"true"` pour tester sans suppression réelle
Expand Down
1 change: 1 addition & 0 deletions cmd/scheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func main() {
Namespace: os.Getenv("NAMESPACE"),
TimeLabel: os.Getenv("TIME_LABEL"),
NotifLabel: os.Getenv("NOTIF_LABEL"),
IgnoreLabel: os.Getenv("IGNORE_LABEL"),
TimeFormat: os.Getenv("TIME_FORMAT"),
GracePeriod: utilsInternal.ParseGracePeriod(os.Getenv("GRACE_PERIOD")),
DryRun: os.Getenv("DRY_RUN") == "true" || os.Getenv("DRY_RUN") == "1",
Expand Down
6 changes: 6 additions & 0 deletions internal/kubernetes/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func FindStale(kube kubernetes.Interface, cfg structInternal.SchedulerConfig) (i
continue
}

ignore, ok := pvc.Labels[cfg.IgnoreLabel]
if ok && ignore == "true" {
log.Printf("[INFO][IGNORE] Label %s found. Skipping.", cfg.IgnoreLabel)
continue
}

// check if pvc should be deleted
stale, staleError := IsStale(timestamp, cfg.TimeFormat, cfg.GracePeriod)
if staleError != nil {
Expand Down
12 changes: 12 additions & 0 deletions internal/kubernetes/finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestFindStale(t *testing.T) {
Namespace: "test",
TimeLabel: "volume-cleaner/unattached-time",
NotifLabel: "volume-cleaner/notification-count",
IgnoreLabel: "volume-cleaner/ignore",
GracePeriod: 0,
TimeFormat: "2006-01-02_15-04-05Z",
DryRun: true,
Expand Down Expand Up @@ -65,6 +66,16 @@ func TestFindStale(t *testing.T) {
assert.Equal(t, deleted, 2)
assert.Equal(t, emailed, 0)

SetPvcLabel(kube, "volume-cleaner/ignore", "true", "test", "pvc1")

deleted, emailed = FindStale(kube, schedulerCfg)

// now pvc1 should be skipped
assert.Equal(t, deleted, 1)
assert.Equal(t, emailed, 0)

RemovePvcLabel(kube, "volume-cleaner/ignore", "test", "pvc1")

schedulerCfg.GracePeriod = 5

deleted, emailed = FindStale(kube, schedulerCfg)
Expand Down Expand Up @@ -159,6 +170,7 @@ func TestShouldSendMail(t *testing.T) {
Namespace: "test",
TimeLabel: "volume-cleaner/unattached-time",
NotifLabel: "volume-cleaner/notification-count",
IgnoreLabel: "volume-cleaner/ignore",
GracePeriod: 180,
TimeFormat: "2006-01-02_15-04-05Z",
DryRun: true,
Expand Down
2 changes: 2 additions & 0 deletions internal/structure/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ scheduler:
NAMESPACE: "anray-liu"
TIME_LABEL: "volume-cleaner/unattached-time"
NOTIF_LABEL: "volume-cleaner/notification-count"
IGNORE_LABEL: "volume-cleaner/ignore"
GRACE_PERIOD: "180"
TIME_FORMAT: "2006-01-02_15-04-05Z"
DRY_RUN: "true"
Expand All @@ -40,6 +41,7 @@ type SchedulerConfig struct {
Namespace string
TimeLabel string
NotifLabel string
IgnoreLabel string
TimeFormat string
GracePeriod int
DryRun bool
Expand Down
Loading