mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #5881 from satnam6502/serve_hostnames
Change defaults, retry on errors and report stats for serve_hostnames
This commit is contained in:
commit
35b2c5ce9d
@ -1,2 +1,2 @@
|
|||||||
all:
|
all:
|
||||||
go build serve_hostnames.go
|
go build ./serve_hostnames.go
|
||||||
|
@ -23,6 +23,7 @@ a serivce
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@ -39,12 +40,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
queries = flag.Int("queries", 1000, "Number of hostname queries to make in each iteration")
|
queries = flag.Int("queries", 100, "Number of hostname queries to make in each iteration")
|
||||||
perNode = flag.Int("per_node", 1, "Number of hostname pods per node")
|
perNode = flag.Int("per_node", 1, "Number of hostname pods per node")
|
||||||
upTo = flag.Int("up_to", -1, "Number of iterations or -1 for no limit")
|
upTo = flag.Int("up_to", 1, "Number of iterations or -1 for no limit")
|
||||||
)
|
)
|
||||||
|
|
||||||
const podStartTimeout = 5 * time.Minute
|
const (
|
||||||
|
deleteTimeout = 2 * time.Minute
|
||||||
|
endpointTimeout = 5 * time.Minute
|
||||||
|
podCreateTimeout = 2 * time.Minute
|
||||||
|
podStartTimeout = 5 * time.Minute
|
||||||
|
serviceCreateTimeout = 2 * time.Minute
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -86,31 +93,45 @@ func main() {
|
|||||||
glog.Infof("Using namespace %s for this test.", ns)
|
glog.Infof("Using namespace %s for this test.", ns)
|
||||||
|
|
||||||
// Create a service for these pods.
|
// Create a service for these pods.
|
||||||
glog.Info("Creating service serve-hostnames")
|
glog.Infof("Creating service %s/serve-hostnames", ns)
|
||||||
svc, err := c.Services(ns).Create(&api.Service{
|
// Make several attempts to create a service.
|
||||||
ObjectMeta: api.ObjectMeta{
|
var svc *api.Service
|
||||||
Name: "serve-hostnames",
|
for start := time.Now(); time.Since(start) < serviceCreateTimeout; time.Sleep(2 * time.Second) {
|
||||||
Labels: map[string]string{
|
t := time.Now()
|
||||||
"name": "serve-hostname",
|
svc, err = c.Services(ns).Create(&api.Service{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "serve-hostnames",
|
||||||
|
Labels: map[string]string{
|
||||||
|
"name": "serve-hostname",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
Spec: api.ServiceSpec{
|
||||||
Spec: api.ServiceSpec{
|
Port: 9376,
|
||||||
Port: 9376,
|
TargetPort: util.NewIntOrStringFromInt(9376),
|
||||||
TargetPort: util.NewIntOrStringFromInt(9376),
|
Selector: map[string]string{
|
||||||
Selector: map[string]string{
|
"name": "serve-hostname",
|
||||||
"name": "serve-hostname",
|
},
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
})
|
glog.Infof("Service create %s/server-hostnames took %v", ns, time.Since(t))
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
glog.Warningf("After %v failed to create service %s/serve-hostnames: %v", time.Since(start), ns, err)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("Unable to create service %s/%s: %v", ns, svc.Name, err)
|
glog.Warningf("Unable to create service %s/%s: %v", ns, svc.Name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Clean up service
|
// Clean up service
|
||||||
defer func() {
|
defer func() {
|
||||||
glog.Info("Cleaning up service")
|
glog.Infof("Cleaning up service %s/server-hostnames", ns)
|
||||||
if err := c.Services(ns).Delete(svc.Name); err != nil {
|
// Make several attempts to delete the service.
|
||||||
glog.Warningf("unable to delete service %s/%s: %v", ns, svc.Name, err)
|
for start := time.Now(); time.Since(start) < deleteTimeout; time.Sleep(1 * time.Second) {
|
||||||
|
if err := c.Services(ns).Delete(svc.Name); err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
glog.Warningf("After %v unable to delete service %s/%s: %v", time.Since(start), ns, svc.Name, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -120,27 +141,36 @@ func main() {
|
|||||||
for j := 0; j < *perNode; j++ {
|
for j := 0; j < *perNode; j++ {
|
||||||
podName := fmt.Sprintf("serve-hostname-%d-%d", i, j)
|
podName := fmt.Sprintf("serve-hostname-%d-%d", i, j)
|
||||||
podNames = append(podNames, podName)
|
podNames = append(podNames, podName)
|
||||||
glog.Infof("Creating pod %s/%s on node %s", ns, podName, node.Name)
|
// Make several attempts
|
||||||
_, err := c.Pods(ns).Create(&api.Pod{
|
for start := time.Now(); time.Since(start) < podCreateTimeout; time.Sleep(2 * time.Second) {
|
||||||
ObjectMeta: api.ObjectMeta{
|
glog.Infof("Creating pod %s/%s on node %s", ns, podName, node.Name)
|
||||||
Name: podName,
|
t := time.Now()
|
||||||
Labels: map[string]string{
|
_, err = c.Pods(ns).Create(&api.Pod{
|
||||||
"name": "serve-hostname",
|
ObjectMeta: api.ObjectMeta{
|
||||||
},
|
Name: podName,
|
||||||
},
|
Labels: map[string]string{
|
||||||
Spec: api.PodSpec{
|
"name": "serve-hostname",
|
||||||
Containers: []api.Container{
|
|
||||||
{
|
|
||||||
Name: "serve-hostname",
|
|
||||||
Image: "kubernetes/serve_hostname:1.1",
|
|
||||||
Ports: []api.ContainerPort{{ContainerPort: 9376}},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Host: node.Name,
|
Spec: api.PodSpec{
|
||||||
},
|
Containers: []api.Container{
|
||||||
})
|
{
|
||||||
|
Name: "serve-hostname",
|
||||||
|
Image: "kubernetes/serve_hostname:1.1",
|
||||||
|
Ports: []api.ContainerPort{{ContainerPort: 9376}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Host: node.Name,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
glog.Infof("Pod create %s/%s request took %v", ns, podName, time.Since(t))
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
glog.Warningf("After %s failed to create pod %s/%s: %v", time.Since(start), ns, podName, err)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("Failed to create pod %s: %v", podName, err)
|
glog.Warningf("Failed to create pod %s/%s: %v", ns, podName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,9 +178,13 @@ func main() {
|
|||||||
// Clean up the pods
|
// Clean up the pods
|
||||||
defer func() {
|
defer func() {
|
||||||
glog.Info("Cleaning up pods")
|
glog.Info("Cleaning up pods")
|
||||||
|
// Make several attempts to delete the pods.
|
||||||
for _, podName := range podNames {
|
for _, podName := range podNames {
|
||||||
if err := c.Pods(ns).Delete(podName); err != nil {
|
for start := time.Now(); time.Since(start) < deleteTimeout; time.Sleep(1 * time.Second) {
|
||||||
glog.Warningf("Failed to delete pod %s: %v", podName, err)
|
if err := c.Pods(ns).Delete(podName); err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
glog.Warningf("After %v failed to delete pod %s: %v", time.Since(start), podName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -175,17 +209,42 @@ func main() {
|
|||||||
glog.Infof("%s/%s is running", ns, podName)
|
glog.Infof("%s/%s is running", ns, podName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for the endpoints to propagate.
|
||||||
|
for start := time.Now(); time.Since(start) < endpointTimeout; time.Sleep(10 * time.Second) {
|
||||||
|
hostname, err := c.Get().
|
||||||
|
Namespace(ns).
|
||||||
|
Prefix("proxy").
|
||||||
|
Resource("services").
|
||||||
|
Name("serve-hostnames").
|
||||||
|
DoRaw()
|
||||||
|
if err != nil {
|
||||||
|
glog.Infof("After %v while making a proxy call got error %v", time.Since(start), err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var r api.Status
|
||||||
|
if err := json.Unmarshal(hostname, &r); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if r.Status == api.StatusFailure {
|
||||||
|
glog.Infof("After %v got status %v", time.Since(start), string(hostname))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// Repeatedly make requests.
|
// Repeatedly make requests.
|
||||||
for iteration := 0; iteration != *upTo; iteration++ {
|
for iteration := 0; iteration != *upTo; iteration++ {
|
||||||
responses := make(map[string]int, *perNode*len(nodes.Items))
|
responses := make(map[string]int, *perNode*len(nodes.Items))
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
for q := 0; q < *queries; q++ {
|
for q := 0; q < *queries; q++ {
|
||||||
|
t := time.Now()
|
||||||
hostname, err := c.Get().
|
hostname, err := c.Get().
|
||||||
Namespace(ns).
|
Namespace(ns).
|
||||||
Prefix("proxy").
|
Prefix("proxy").
|
||||||
Resource("services").
|
Resource("services").
|
||||||
Name("serve-hostnames").
|
Name("serve-hostnames").
|
||||||
DoRaw()
|
DoRaw()
|
||||||
|
glog.Infof("Proxy call in namespace %s took %v", ns, time.Since(t))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Infof("Call failed during iteration %d query %d : %v", iteration, q, err)
|
glog.Infof("Call failed during iteration %d query %d : %v", iteration, q, err)
|
||||||
} else {
|
} else {
|
||||||
@ -205,6 +264,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glog.Infof("Iteration %d took %v for %d queries", iteration, time.Since(start), *queries)
|
glog.Infof("Iteration %d took %v for %d queries (%.2f QPS)", iteration, time.Since(start), *queries, float64(*queries)/time.Since(start).Seconds())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user