From 7085020021734024148fffe5d2cb335f304dc2e0 Mon Sep 17 00:00:00 2001 From: "viswesh.swaminathan" Date: Wed, 15 Feb 2023 21:39:30 -0500 Subject: [PATCH 1/3] client: add option to configure CSIVolumeClaimGCInterval --- command/agent/agent.go | 7 +++++++ command/agent/config.go | 7 +++++++ command/agent/config_parse_test.go | 1 + 3 files changed, 15 insertions(+) diff --git a/command/agent/agent.go b/command/agent/agent.go index e8d8eb0f5c9..99df0240448 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -404,6 +404,13 @@ func convertServerConfig(agentConfig *Config) (*nomad.Config, error) { } conf.DeploymentGCThreshold = dur } + if gcInterval := agentConfig.Server.CSIVolumeClaimGCInterval; gcInterval != "" { + dur, err := time.ParseDuration(gcInterval) + if err != nil { + return nil, err + } + conf.CSIVolumeClaimGCInterval = dur + } if gcThreshold := agentConfig.Server.CSIVolumeClaimGCThreshold; gcThreshold != "" { dur, err := time.ParseDuration(gcThreshold) if err != nil { diff --git a/command/agent/config.go b/command/agent/config.go index 29d357219a8..8426d5284a0 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -490,6 +490,10 @@ type ServerConfig struct { // GCed but the threshold can be used to filter by age. DeploymentGCThreshold string `hcl:"deployment_gc_threshold"` + // CSIVolumeClaimGCInterval is how often we dispatch a job to GC + // volume claims. + CSIVolumeClaimGCInterval string `hcl:"csi_volume_claim_gc_interval"` + // CSIVolumeClaimGCThreshold controls how "old" a CSI volume must be to // have its claims collected by GC. Age is not the only requirement for // a volume to be GCed but the threshold can be used to filter by age. @@ -1876,6 +1880,9 @@ func (s *ServerConfig) Merge(b *ServerConfig) *ServerConfig { if b.DeploymentGCThreshold != "" { result.DeploymentGCThreshold = b.DeploymentGCThreshold } + if b.CSIVolumeClaimGCInterval != "" { + result.CSIVolumeClaimGCInterval = b.CSIVolumeClaimGCInterval + } if b.CSIVolumeClaimGCThreshold != "" { result.CSIVolumeClaimGCThreshold = b.CSIVolumeClaimGCThreshold } diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 94d60cdf691..7139c0a60f0 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -105,6 +105,7 @@ var basicConfig = &Config{ JobGCInterval: "3m", JobGCThreshold: "12h", DeploymentGCThreshold: "12h", + CSIVolumeClaimGCInterval: "3m", CSIVolumeClaimGCThreshold: "12h", CSIPluginGCThreshold: "12h", ACLTokenGCThreshold: "12h", From c51f8a7b8f85e135f6662392d4d835028a5940d6 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Thu, 16 Feb 2023 09:02:30 -0500 Subject: [PATCH 2/3] add validation, changelog, docs --- .changelog/16195.txt | 3 +++ command/agent/agent.go | 2 ++ website/content/docs/configuration/server.mdx | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 .changelog/16195.txt diff --git a/.changelog/16195.txt b/.changelog/16195.txt new file mode 100644 index 00000000000..bf9390f7b83 --- /dev/null +++ b/.changelog/16195.txt @@ -0,0 +1,3 @@ +```release-note:improvement +csi: Added server configuration for `csi_volume_claim_gc_interval` +``` diff --git a/command/agent/agent.go b/command/agent/agent.go index 99df0240448..b3f99d8e5f3 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -408,6 +408,8 @@ func convertServerConfig(agentConfig *Config) (*nomad.Config, error) { dur, err := time.ParseDuration(gcInterval) if err != nil { return nil, err + } else if dur <= time.Duration(0) { + return nil, fmt.Errorf("csi_volume_claim_gc_interval should be greater than 0s") } conf.CSIVolumeClaimGCInterval = dur } diff --git a/website/content/docs/configuration/server.mdx b/website/content/docs/configuration/server.mdx index 7a0d84a0456..06dc947df0e 100644 --- a/website/content/docs/configuration/server.mdx +++ b/website/content/docs/configuration/server.mdx @@ -107,6 +107,9 @@ server { deployment must be in the terminal state before it is eligible for garbage collection. This is specified using a label suffix like "30s" or "1h". +- `csi_volume_claim_gc_interval` `(string: "5m")` - Specifies the interval + between CSI volume claim garbage collections. + - `csi_volume_claim_gc_threshold` `(string: "1h")` - Specifies the minimum age of a CSI volume before it is eligible to have its claims garbage collected. This is specified using a label suffix like "30s" or "1h". From 0159051d9295a0dcfe9722e026bb318a7cd7b445 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Thu, 16 Feb 2023 09:38:10 -0500 Subject: [PATCH 3/3] fixed test fixtures --- command/agent/testdata/basic.hcl | 1 + command/agent/testdata/basic.json | 1 + 2 files changed, 2 insertions(+) diff --git a/command/agent/testdata/basic.hcl b/command/agent/testdata/basic.hcl index 55b9977b5b6..92b2f82c675 100644 --- a/command/agent/testdata/basic.hcl +++ b/command/agent/testdata/basic.hcl @@ -114,6 +114,7 @@ server { job_gc_threshold = "12h" eval_gc_threshold = "12h" deployment_gc_threshold = "12h" + csi_volume_claim_gc_interval = "3m" csi_volume_claim_gc_threshold = "12h" csi_plugin_gc_threshold = "12h" acl_token_gc_threshold = "12h" diff --git a/command/agent/testdata/basic.json b/command/agent/testdata/basic.json index 990400acf2d..7993f24fdd9 100644 --- a/command/agent/testdata/basic.json +++ b/command/agent/testdata/basic.json @@ -273,6 +273,7 @@ ], "encrypt": "abc", "eval_gc_threshold": "12h", + "csi_volume_claim_gc_interval": "3m", "heartbeat_grace": "30s", "job_gc_interval": "3m", "job_gc_threshold": "12h",