From ed692fc678e3ba3036da44b1ef1079a1b443618c Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 27 Dec 2023 17:21:42 -0700 Subject: [PATCH] addons: Fix auto-pause addon --- cmd/auto-pause/auto-pause.go | 13 +++++++------ cmd/minikube/cmd/config/configure.go | 21 --------------------- cmd/minikube/cmd/start_flags.go | 4 ---- pkg/minikube/assets/addons.go | 2 +- pkg/minikube/config/types.go | 1 - 5 files changed, 8 insertions(+), 33 deletions(-) diff --git a/cmd/auto-pause/auto-pause.go b/cmd/auto-pause/auto-pause.go index d51f69a7f013..6c80d530fcb6 100644 --- a/cmd/auto-pause/auto-pause.go +++ b/cmd/auto-pause/auto-pause.go @@ -24,13 +24,10 @@ import ( "sync" "time" - "github.com/spf13/viper" "k8s.io/minikube/pkg/minikube/cluster" "k8s.io/minikube/pkg/minikube/command" - "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/cruntime" "k8s.io/minikube/pkg/minikube/exit" - "k8s.io/minikube/pkg/minikube/mustload" "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/reason" "k8s.io/minikube/pkg/minikube/style" @@ -48,10 +45,14 @@ var runtime = flag.String("container-runtime", "docker", "Container runtime to u func main() { flag.Parse() - profile := viper.GetString(config.ProfileName) - _, cfg := mustload.Partial(profile) - interval := cfg.AutoPauseInterval + // TODO: #10595 make this configurable + const interval = time.Minute * 1 + // Check if interval is greater than 0 so NewTicker does not panic. + if interval <= 0 { + exit.Message(reason.Usage, "Auto-pause interval must be greater than 0,"+ + " not current value of {{.interval}}", out.V{"interval": interval.String()}) + } tickerChannel := time.NewTicker(interval) // Check current state diff --git a/cmd/minikube/cmd/config/configure.go b/cmd/minikube/cmd/config/configure.go index d6f89e75128e..c0d77e9cf784 100644 --- a/cmd/minikube/cmd/config/configure.go +++ b/cmd/minikube/cmd/config/configure.go @@ -20,8 +20,6 @@ import ( "net" "os" "regexp" - "strconv" - "time" "github.com/spf13/cobra" "k8s.io/minikube/pkg/addons" @@ -257,25 +255,6 @@ var addonsConfigureCmd = &cobra.Command{ out.ErrT(style.Fatal, "Failed to configure registry-aliases {{.profile}}", out.V{"profile": profile}) } } - case "auto-pause-interval": - profile := ClusterFlagValue() - _, cfg := mustload.Partial(profile) - - intervalInput := AskForStaticValue("-- Enter interval time of auto-pause-interval (in minutes): ") - intervalTime, err := strconv.Atoi(intervalInput) - if err != nil { - out.ErrT(style.Fatal, "Failed to extract integer in minutes to pause.") - } - - if intervalTime <= 0 { - out.ErrT(style.Fatal, "Auto-pause interval must be greater than 0,"+ - " not current value of {{.interval}}", out.V{"interval": intervalTime}) - } - - cfg.AutoPauseInterval = time.Minute * time.Duration(intervalTime) - if err := config.SaveProfile(profile, cfg); err != nil { - out.ErrT(style.Fatal, "Failed to save config {{.profile}}", out.V{"profile": profile}) - } default: out.FailureT("{{.name}} has no available configuration options", out.V{"name": addon}) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 22b1378dd874..5be215b8505b 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -141,7 +141,6 @@ const ( socketVMnetClientPath = "socket-vmnet-client-path" socketVMnetPath = "socket-vmnet-path" staticIP = "static-ip" - autoPauseInterval = "auto-pause-interval" gpus = "gpus" ) @@ -204,7 +203,6 @@ func initMinikubeFlags() { startCmd.Flags().Bool(disableOptimizations, false, "If set, disables optimizations that are set for local Kubernetes. Including decreasing CoreDNS replicas from 2 to 1. Defaults to false.") startCmd.Flags().Bool(disableMetrics, false, "If set, disables metrics reporting (CPU and memory usage), this can improve CPU usage. Defaults to false.") startCmd.Flags().String(staticIP, "", "Set a static IP for the minikube cluster, the IP must be: private, IPv4, and the last octet must be between 2 and 254, for example 192.168.200.200 (Docker and Podman drivers only)") - startCmd.Flags().Duration(autoPauseInterval, time.Minute*1, "Duration of inactivity before the minikube VM is paused (default 1m0s). To disable, set to 0s") startCmd.Flags().StringP(gpus, "g", "", "Allow pods to use your NVIDIA GPUs. Options include: [all,nvidia] (Docker driver with Docker container-runtime only)") } @@ -604,7 +602,6 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str NodePort: viper.GetInt(apiServerPort), }, MultiNodeRequested: viper.GetInt(nodes) > 1, - AutoPauseInterval: viper.GetDuration(autoPauseInterval), GPUs: viper.GetString(gpus), } cc.VerifyComponents = interpretWaitFlag(*cmd) @@ -820,7 +817,6 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC updateStringFromFlag(cmd, &cc.CustomQemuFirmwarePath, qemuFirmwarePath) updateStringFromFlag(cmd, &cc.SocketVMnetClientPath, socketVMnetClientPath) updateStringFromFlag(cmd, &cc.SocketVMnetPath, socketVMnetPath) - updateDurationFromFlag(cmd, &cc.AutoPauseInterval, autoPauseInterval) if cmd.Flags().Changed(kubernetesVersion) { kubeVer, err := getKubernetesVersion(existing) diff --git a/pkg/minikube/assets/addons.go b/pkg/minikube/assets/addons.go index 039b15409e73..52f1159bb6b1 100644 --- a/pkg/minikube/assets/addons.go +++ b/pkg/minikube/assets/addons.go @@ -135,7 +135,7 @@ var Addons = map[string]*Addon{ // GuestPersistentDir }, false, "auto-pause", "minikube", "", "", map[string]string{ - "AutoPauseHook": "k8s-minikube/auto-pause-hook:v0.0.4@sha256:c1792e370216fcdfd8c4540a87e3fa867da204dd5521623796e2d28498a894ff", + "AutoPauseHook": "k8s-minikube/auto-pause-hook:v0.0.5@sha256:d613ed2c891882b602b5aca668e92d4606a1b3832d96750ab25804de15929522", }, map[string]string{ "AutoPauseHook": "gcr.io", }), diff --git a/pkg/minikube/config/types.go b/pkg/minikube/config/types.go index 245f5c10e7e3..3a3e962128f3 100644 --- a/pkg/minikube/config/types.go +++ b/pkg/minikube/config/types.go @@ -107,7 +107,6 @@ type ClusterConfig struct { StaticIP string SSHAuthSock string SSHAgentPID int - AutoPauseInterval time.Duration // Specifies interval of time to wait before checking if cluster should be paused GPUs string }