Skip to content

Commit

Permalink
Merge pull request #11438 from medyagh/autopause-vm
Browse files Browse the repository at this point in the history
Fix auto-pause on VMs (detect right control-plane IP)
  • Loading branch information
medyagh authored May 18, 2021
2 parents e05cad7 + 8ca3d1f commit 8f85fd9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ backend k8s-api-https
#tcp-request inspect-delay 10s
#tcp-request content lua.foo_action
tcp-request inspect-delay 10s
tcp-request content lua.unpause 192.168.49.2 8080
tcp-request content lua.unpause {{.NetworkInfo.ControlPlaneNodeIP}} 8080
tcp-request content reject if { var(req.blocked) -m bool }
option tcplog
option tcp-check
default-server inter 10s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100
server k8s-api-1 192.168.49.2:8443 check
server k8s-api-1 {{.NetworkInfo.ControlPlaneNodeIP}}:{{.NetworkInfo.ControlPlaneNodePort}} check

1 change: 1 addition & 0 deletions pkg/addons/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ https://github.com/kubernetes/minikube/issues/7332`, out.V{"driver_name": cc.Dri
var networkInfo assets.NetworkInfo
if len(cc.Nodes) >= 1 {
networkInfo.ControlPlaneNodeIP = cc.Nodes[0].IP
networkInfo.ControlPlaneNodePort = cc.Nodes[0].Port
} else {
out.WarningT("At least needs control plane nodes to enable addon")
}
Expand Down
14 changes: 8 additions & 6 deletions pkg/minikube/assets/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type Addon struct {

// NetworkInfo contains control plane node IP address used for add on template
type NetworkInfo struct {
ControlPlaneNodeIP string
ControlPlaneNodeIP string
ControlPlaneNodePort int
}

// NewAddon creates a new Addon
Expand Down Expand Up @@ -88,13 +89,13 @@ var Addons = map[string]*Addon{
"auto-pause-hook.yaml",
"0640"),
MustBinAsset(
"deploy/addons/auto-pause/haproxy.cfg",
"/var/lib/minikube/",
"deploy/addons/auto-pause/haproxy.cfg.tmpl",
vmpath.GuestPersistentDir,
"haproxy.cfg",
"0640"),
MustBinAsset(
"deploy/addons/auto-pause/unpause.lua",
"/var/lib/minikube/",
vmpath.GuestPersistentDir,
"unpause.lua",
"0640"),
MustBinAsset(
Expand Down Expand Up @@ -660,7 +661,7 @@ var Addons = map[string]*Addon{
}

// GenerateTemplateData generates template data for template assets
func GenerateTemplateData(addon *Addon, cfg config.KubernetesConfig, networkInfo NetworkInfo) interface{} {
func GenerateTemplateData(addon *Addon, cfg config.KubernetesConfig, netInfo NetworkInfo) interface{} {

a := runtime.GOARCH
// Some legacy docker images still need the -arch suffix
Expand Down Expand Up @@ -697,7 +698,8 @@ func GenerateTemplateData(addon *Addon, cfg config.KubernetesConfig, networkInfo
}

// Network info for generating template
opts.NetworkInfo["ControlPlaneNodeIP"] = networkInfo.ControlPlaneNodeIP
opts.NetworkInfo["ControlPlaneNodeIP"] = netInfo.ControlPlaneNodeIP
opts.NetworkInfo["ControlPlaneNodePort"] = fmt.Sprint(netInfo.ControlPlaneNodePort)

if opts.Images == nil {
opts.Images = make(map[string]string) // Avoid nil access when rendering
Expand Down

0 comments on commit 8f85fd9

Please sign in to comment.