Skip to content

Commit

Permalink
addons: Fix auto-pause addon
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Dec 28, 2023
1 parent 9f22db8 commit ed692fc
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 33 deletions.
13 changes: 7 additions & 6 deletions cmd/auto-pause/auto-pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
21 changes: 0 additions & 21 deletions cmd/minikube/cmd/config/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"net"
"os"
"regexp"
"strconv"
"time"

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/addons"
Expand Down Expand Up @@ -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})
Expand Down
4 changes: 0 additions & 4 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ const (
socketVMnetClientPath = "socket-vmnet-client-path"
socketVMnetPath = "socket-vmnet-path"
staticIP = "static-ip"
autoPauseInterval = "auto-pause-interval"
gpus = "gpus"
)

Expand Down Expand Up @@ -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)")
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/assets/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}),
Expand Down
1 change: 0 additions & 1 deletion pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit ed692fc

Please sign in to comment.