mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 05:36:12 +00:00
Enable network-tester to test graceful deletion
This commit is contained in:
28
contrib/for-tests/network-tester/slow-pod.json
Normal file
28
contrib/for-tests/network-tester/slow-pod.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "v1beta3",
|
||||
"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
contrib/for-tests/network-tester/slow-rc.json
Normal file
42
contrib/for-tests/network-tester/slow-rc.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"kind": "ReplicationController",
|
||||
"apiVersion": "v1beta3",
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -40,7 +40,9 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
@@ -48,10 +50,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
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.")
|
||||
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.")
|
||||
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.")
|
||||
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.")
|
||||
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.
|
||||
@@ -179,6 +182,17 @@ func main() {
|
||||
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{
|
||||
Hostname: hostname,
|
||||
StillContactingPeers: true,
|
||||
|
Reference in New Issue
Block a user