update addon name
parent
21d9f50e9c
commit
8739e20fef
|
@ -35,28 +35,37 @@ import (
|
||||||
var incomeCh = make(chan struct{})
|
var incomeCh = make(chan struct{})
|
||||||
var done = make(chan struct{})
|
var done = make(chan struct{})
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var dockerPaused = false
|
|
||||||
|
// TODO: intialize with current state (handle the case that user enables auto-pause after it is already paused)
|
||||||
|
var runtimePaused = false
|
||||||
|
var version = "0.0.1"
|
||||||
|
|
||||||
|
// TODO: make this configurable to support containerd/cri-o
|
||||||
|
var runtime = "docker"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
const interval = time.Minute * 5
|
// TODO: make this configurable
|
||||||
|
const interval = time.Minute * 1
|
||||||
// channel for incoming messages
|
// channel for incoming messages
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
// On each iteration new timer is created
|
// On each iteration new timer is created
|
||||||
select {
|
select {
|
||||||
case <-time.After(interval):
|
case <-time.After(interval):
|
||||||
fmt.Printf("Time out\n")
|
|
||||||
runPause()
|
runPause()
|
||||||
case <-incomeCh:
|
case <-incomeCh:
|
||||||
fmt.Printf("Get request\n")
|
fmt.Printf("Got request\n")
|
||||||
|
if runtimePaused {
|
||||||
runUnpause()
|
runUnpause()
|
||||||
|
}
|
||||||
|
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
http.HandleFunc("/", handler) // each request calls handler
|
http.HandleFunc("/", handler) // each request calls handler
|
||||||
fmt.Printf("Starting server at port 8080\n")
|
fmt.Printf("Starting auto-pause server %s at port 8080 \n", version)
|
||||||
log.Fatal(http.ListenAndServe("0.0.0.0:8080", nil))
|
log.Fatal(http.ListenAndServe("0.0.0.0:8080", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +79,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
func runPause() {
|
func runPause() {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
if dockerPaused {
|
if runtimePaused {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,35 +87,32 @@ func runPause() {
|
||||||
|
|
||||||
r := command.NewExecRunner(true)
|
r := command.NewExecRunner(true)
|
||||||
|
|
||||||
cr, err := cruntime.New(cruntime.Config{Type: "docker", Runner: r})
|
cr, err := cruntime.New(cruntime.Config{Type: runtime, Runner: r})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exit.Error(reason.InternalNewRuntime, "Failed runtime", err)
|
exit.Error(reason.InternalNewRuntime, "Failed runtime", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
uids, err := cluster.Pause(cr, r, nil)
|
uids, err := cluster.Pause(cr, r, []string{"kube-system"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exit.Error(reason.GuestPause, "Pause", err)
|
exit.Error(reason.GuestPause, "Pause", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dockerPaused = true
|
runtimePaused = true
|
||||||
ids = append(ids, uids...)
|
ids = append(ids, uids...)
|
||||||
|
|
||||||
out.Step(style.Unpause, "Paused {{.count}} containers", out.V{"count": len(ids)})
|
out.Step(style.Unpause, "Paused {{.count}} containers", out.V{"count": len(ids)})
|
||||||
}
|
}
|
||||||
|
|
||||||
func runUnpause() {
|
func runUnpause() {
|
||||||
|
fmt.Println("unpausing...")
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
||||||
if !dockerPaused {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ids := []string{}
|
ids := []string{}
|
||||||
|
|
||||||
r := command.NewExecRunner(true)
|
r := command.NewExecRunner(true)
|
||||||
|
|
||||||
cr, err := cruntime.New(cruntime.Config{Type: "docker", Runner: r})
|
cr, err := cruntime.New(cruntime.Config{Type: runtime, Runner: r})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exit.Error(reason.InternalNewRuntime, "Failed runtime", err)
|
exit.Error(reason.InternalNewRuntime, "Failed runtime", err)
|
||||||
}
|
}
|
||||||
|
@ -116,7 +122,7 @@ func runUnpause() {
|
||||||
exit.Error(reason.GuestUnpause, "Unpause", err)
|
exit.Error(reason.GuestUnpause, "Unpause", err)
|
||||||
}
|
}
|
||||||
ids = append(ids, uids...)
|
ids = append(ids, uids...)
|
||||||
dockerPaused = false
|
runtimePaused = false
|
||||||
|
|
||||||
out.Step(style.Unpause, "Unpaused {{.count}} containers", out.V{"count": len(ids)})
|
out.Step(style.Unpause, "Unpaused {{.count}} containers", out.V{"count": len(ids)})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,26 @@
|
||||||
---
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: auto-pause
|
||||||
|
---
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: auto-pause
|
name: auto-pause-proxy
|
||||||
namespace: kube-system
|
namespace: auto-pause
|
||||||
labels:
|
labels:
|
||||||
app: auto-pause
|
app: auto-pause-proxy
|
||||||
spec:
|
spec:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: auto-pause
|
app: auto-pause-proxy
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
creationTimestamp: null
|
creationTimestamp: null
|
||||||
labels:
|
labels:
|
||||||
app: auto-pause
|
app: auto-pause-proxy
|
||||||
spec:
|
spec:
|
||||||
volumes:
|
volumes:
|
||||||
- name: ha-cfg
|
- name: ha-cfg
|
||||||
|
@ -28,7 +33,7 @@ spec:
|
||||||
type: File
|
type: File
|
||||||
containers:
|
containers:
|
||||||
- name: auto-pause
|
- name: auto-pause
|
||||||
image: "haproxy:2.3.5"
|
image: "haproxy:2.3.5-alpine"
|
||||||
ports:
|
ports:
|
||||||
- name: https
|
- name: https
|
||||||
containerPort: 6443
|
containerPort: 6443
|
||||||
|
|
|
@ -28,7 +28,7 @@ backend k8s-api-https
|
||||||
#tcp-request inspect-delay 10s
|
#tcp-request inspect-delay 10s
|
||||||
#tcp-request content lua.foo_action
|
#tcp-request content lua.foo_action
|
||||||
tcp-request inspect-delay 10s
|
tcp-request inspect-delay 10s
|
||||||
tcp-request content lua.unpause 192.168.49.2 8000
|
tcp-request content lua.unpause 192.168.49.2 8080
|
||||||
tcp-request content reject if { var(req.blocked) -m bool }
|
tcp-request content reject if { var(req.blocked) -m bool }
|
||||||
option tcplog
|
option tcplog
|
||||||
option tcp-check
|
option tcp-check
|
||||||
|
|
Loading…
Reference in New Issue