diff --git a/.changelog/16195.txt b/.changelog/16195.txt new file mode 100644 index 000000000..bf9390f7b --- /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 e8d8eb0f5..b3f99d8e5 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -404,6 +404,15 @@ 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 + } else if dur <= time.Duration(0) { + return nil, fmt.Errorf("csi_volume_claim_gc_interval should be greater than 0s") + } + 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 29d357219..8426d5284 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 94d60cdf6..7139c0a60 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", diff --git a/command/agent/testdata/basic.hcl b/command/agent/testdata/basic.hcl index 55b9977b5..92b2f82c6 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 990400acf..7993f24fd 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", diff --git a/website/content/docs/configuration/server.mdx b/website/content/docs/configuration/server.mdx index 7a0d84a04..06dc947df 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".