mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Allow testing graceful shutdown via network-tester
This commit is contained in:
parent
3fce3433d9
commit
9ee7b76bba
@ -51,6 +51,7 @@ current-release-pr
|
|||||||
current-replicas
|
current-replicas
|
||||||
default-container-cpu-limit
|
default-container-cpu-limit
|
||||||
default-container-mem-limit
|
default-container-mem-limit
|
||||||
|
delay-shutdown
|
||||||
deleting-pods-burst
|
deleting-pods-burst
|
||||||
deleting-pods-qps
|
deleting-pods-qps
|
||||||
deployment-label-key
|
deployment-label-key
|
||||||
|
28
test/images/network-tester/slow-pod.json
Normal file
28
test/images/network-tester/slow-pod.json
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"kind": "Pod",
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"metadata": {
|
||||||
|
"name": "slow-pod",
|
||||||
|
"labels": {
|
||||||
|
"name": "nettest"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"name": "webserver",
|
||||||
|
"image": "gcr.io/google_containers/nettest:1.5",
|
||||||
|
"args": [
|
||||||
|
"-service=nettest",
|
||||||
|
"-delay-shutdown=10"
|
||||||
|
],
|
||||||
|
"ports": [
|
||||||
|
{
|
||||||
|
"containerPort": 8080,
|
||||||
|
"protocol": "TCP"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
42
test/images/network-tester/slow-rc.json
Normal file
42
test/images/network-tester/slow-rc.json
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"kind": "ReplicationController",
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"metadata": {
|
||||||
|
"name": "slow-rc",
|
||||||
|
"labels": {
|
||||||
|
"name": "nettest"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"replicas": 8,
|
||||||
|
"selector": {
|
||||||
|
"name": "nettest"
|
||||||
|
},
|
||||||
|
"template": {
|
||||||
|
"metadata": {
|
||||||
|
"labels": {
|
||||||
|
"name": "nettest"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"terminationGracePeriodSeconds": 5,
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"name": "webserver",
|
||||||
|
"image": "gcr.io/google_containers/nettest:1.5",
|
||||||
|
"args": [
|
||||||
|
"-service=nettest",
|
||||||
|
"-delay-shutdown=10"
|
||||||
|
],
|
||||||
|
"ports": [
|
||||||
|
{
|
||||||
|
"containerPort": 8080,
|
||||||
|
"protocol": "TCP"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -39,7 +39,9 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
@ -47,10 +49,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
port = flag.Int("port", 8080, "Port number to serve at.")
|
port = flag.Int("port", 8080, "Port number to serve at.")
|
||||||
peerCount = flag.Int("peers", 8, "Must find at least this many peers for the test to pass.")
|
peerCount = flag.Int("peers", 8, "Must find at least this many peers for the test to pass.")
|
||||||
service = flag.String("service", "nettest", "Service to find other network test pods in.")
|
service = flag.String("service", "nettest", "Service to find other network test pods in.")
|
||||||
namespace = flag.String("namespace", "default", "Namespace of this pod. TODO: kubernetes should make this discoverable.")
|
namespace = flag.String("namespace", "default", "Namespace of this pod. TODO: kubernetes should make this discoverable.")
|
||||||
|
delayShutdown = flag.Int("delay-shutdown", 0, "Number of seconds to delay shutdown when receiving SIGTERM.")
|
||||||
)
|
)
|
||||||
|
|
||||||
// State tracks the internal state of our little http server.
|
// State tracks the internal state of our little http server.
|
||||||
@ -178,6 +181,17 @@ func main() {
|
|||||||
log.Fatalf("Error getting hostname: %v", err)
|
log.Fatalf("Error getting hostname: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *delayShutdown > 0 {
|
||||||
|
termCh := make(chan os.Signal)
|
||||||
|
signal.Notify(termCh, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
<-termCh
|
||||||
|
log.Printf("Sleeping %d seconds before exit ...", *delayShutdown)
|
||||||
|
time.Sleep(time.Duration(*delayShutdown) * time.Second)
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
state := State{
|
state := State{
|
||||||
Hostname: hostname,
|
Hostname: hostname,
|
||||||
StillContactingPeers: true,
|
StillContactingPeers: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user