addons: Fix auto-pause addon

pull/17866/head
Steven Powell 2023-12-27 17:21:42 -07:00
parent 49595dc9e5
commit 77ac34b1d7
5 changed files with 8 additions and 33 deletions

View File

@ -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

View File

@ -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})

View File

@ -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)

View File

@ -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",
}),

View File

@ -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
}