Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20260706-113000.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: Add --job-pod-requests-ephemeral-storage and --job-pod-limits-ephemeral-storage flags (in MB) to set the job pod's ephemeral-storage request and limit; both default to unset
time: 2026-07-06T11:30:00.000000000Z
2 changes: 2 additions & 0 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func init() {
rootCmd.PersistentFlags().Int64("job-pod-requests-memory", 1024, "The job pod resource requests in MB.")
rootCmd.PersistentFlags().Int64("job-pod-limits-cpu", 1000, "The job pod resource limits cpu millicores.")
rootCmd.PersistentFlags().Int64("job-pod-limits-memory", 1024, "The job pod resource limits in MB.")
rootCmd.PersistentFlags().Int64("job-pod-requests-ephemeral-storage", 0, "The job pod resource requests ephemeral storage in MB. 0 leaves the request unset.")
rootCmd.PersistentFlags().Int64("job-pod-limits-ephemeral-storage", 0, "The job pod resource limits ephemeral storage in MB. 0 leaves the limit unset.")
rootCmd.PersistentFlags().String("job-pod-shell", "/bin/sh", "The job pod shell to use for commands run inside the pod.")
rootCmd.PersistentFlags().String("job-pod-workdir", "/jobs", "The job pod working directory.")
rootCmd.PersistentFlags().Int("job-pod-log-max-interval", 30, "The max amount of time between when pod logs are shipped to OpsLevel. Works in tandem with 'job-pod-log-max-size'")
Expand Down
8 changes: 8 additions & 0 deletions src/pkg/k8s_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func ReadPodConfig(path string) (*K8SPodConfig, error) {
HelperImage: viper.GetString("job-pod-helper-image"),
},
}
// Ephemeral storage is only set when configured so existing deployments are unaffected;
// a literal 0 limit would kill any pod that writes to disk.
if v := viper.GetInt64("job-pod-requests-ephemeral-storage"); v > 0 {
config.Kubernetes.Resources.Requests[corev1.ResourceEphemeralStorage] = *resource.NewQuantity(v*1024*1024, resource.BinarySI)
}
if v := viper.GetInt64("job-pod-limits-ephemeral-storage"); v > 0 {
config.Kubernetes.Resources.Limits[corev1.ResourceEphemeralStorage] = *resource.NewQuantity(v*1024*1024, resource.BinarySI)
}
// Early out with viper defaults if config file doesn't exist
if _, err := os.Stat(path); os.IsNotExist(err) {
return &config.Kubernetes, nil
Expand Down
39 changes: 39 additions & 0 deletions src/pkg/k8s_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package pkg

import (
"testing"

"github.com/rocktavious/autopilot/v2023"
"github.com/spf13/viper"
corev1 "k8s.io/api/core/v1"
)

func TestReadPodConfig_EphemeralStorageUnsetByDefault(t *testing.T) {
// Arrange
viper.Reset()
t.Cleanup(viper.Reset)
// Act
config, err := ReadPodConfig("does-not-exist.yaml")
// Assert
autopilot.Ok(t, err)
_, hasRequest := config.Resources.Requests[corev1.ResourceEphemeralStorage]
_, hasLimit := config.Resources.Limits[corev1.ResourceEphemeralStorage]
autopilot.Equals(t, false, hasRequest)
autopilot.Equals(t, false, hasLimit)
}

func TestReadPodConfig_EphemeralStorageSet(t *testing.T) {
// Arrange
viper.Reset()
t.Cleanup(viper.Reset)
viper.Set("job-pod-requests-ephemeral-storage", 5120)
viper.Set("job-pod-limits-ephemeral-storage", 20480)
// Act
config, err := ReadPodConfig("does-not-exist.yaml")
// Assert
autopilot.Ok(t, err)
request := config.Resources.Requests[corev1.ResourceEphemeralStorage]
limit := config.Resources.Limits[corev1.ResourceEphemeralStorage]
autopilot.Equals(t, "5Gi", request.String())
autopilot.Equals(t, "20Gi", limit.String())
}
Loading