mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #8175 from piosz/load_generator
Added more logging to load e2e test
This commit is contained in:
commit
881f11adbf
@ -19,13 +19,13 @@ package e2e
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@ -89,9 +89,9 @@ var _ = Describe("Load", func() {
|
|||||||
wg.Add(threads)
|
wg.Add(threads)
|
||||||
|
|
||||||
// Run RC load for all kinds of RC.
|
// Run RC load for all kinds of RC.
|
||||||
runRCLoad(c, &wg, ns, smallRCSize, smallRCCount)
|
runRCLoad(c, &wg, ns, "load-test-small-rc", smallRCSize, smallRCCount)
|
||||||
runRCLoad(c, &wg, ns, mediumRCSize, mediumRCCount)
|
runRCLoad(c, &wg, ns, "load-test-medium-rc", mediumRCSize, mediumRCCount)
|
||||||
runRCLoad(c, &wg, ns, bigRCSize, bigRCCount)
|
runRCLoad(c, &wg, ns, "load-test-big-rc", bigRCSize, bigRCCount)
|
||||||
|
|
||||||
// Wait for all the pods from all the RC's to return.
|
// Wait for all the pods from all the RC's to return.
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
@ -113,35 +113,33 @@ func computeRCCounts(total int) (int, int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The function creates a RC and then every few second resize it and with 0.1 probability deletes it.
|
// The function creates a RC and then every few second resize it and with 0.1 probability deletes it.
|
||||||
func playWithRC(c *client.Client, wg *sync.WaitGroup, ns string, size int) {
|
func playWithRC(c *client.Client, wg *sync.WaitGroup, ns, name string, size int) {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
rcExist := false
|
rcExist := false
|
||||||
var name string
|
|
||||||
// Once every 1-2 minutes perform resize of RC.
|
// Once every 1-2 minutes perform resize of RC.
|
||||||
for start := time.Now(); time.Since(start) < simulationTime; time.Sleep(time.Duration(60+rand.Intn(60)) * time.Second) {
|
for start := time.Now(); time.Since(start) < simulationTime; time.Sleep(time.Duration(60+rand.Intn(60)) * time.Second) {
|
||||||
if !rcExist {
|
if !rcExist {
|
||||||
name = "load-test-" + string(util.NewUUID())
|
expectNoError(RunRC(c, name, ns, image, size), fmt.Sprintf("creating rc %s in namespace %s", name, ns))
|
||||||
expectNoError(RunRC(c, name, ns, image, size))
|
|
||||||
rcExist = true
|
rcExist = true
|
||||||
}
|
}
|
||||||
// Resize RC to a random size between 0.5x and 1.5x of the original size.
|
// Resize RC to a random size between 0.5x and 1.5x of the original size.
|
||||||
newSize := uint(rand.Intn(size+1) + size/2)
|
newSize := uint(rand.Intn(size+1) + size/2)
|
||||||
expectNoError(ResizeRC(c, ns, name, newSize))
|
expectNoError(ResizeRC(c, ns, name, newSize), fmt.Sprintf("resizing rc %s in namespace %s", name, ns))
|
||||||
// With probability 0.1 remove this RC.
|
// With probability 0.1 remove this RC.
|
||||||
if rand.Intn(10) == 0 {
|
if rand.Intn(10) == 0 {
|
||||||
expectNoError(DeleteRC(c, ns, name))
|
expectNoError(DeleteRC(c, ns, name), fmt.Sprintf("deleting rc %s in namespace %s", name, ns))
|
||||||
rcExist = false
|
rcExist = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rcExist {
|
if rcExist {
|
||||||
expectNoError(DeleteRC(c, ns, name))
|
expectNoError(DeleteRC(c, ns, name), fmt.Sprintf("deleting rc %s in namespace %s after test completion", name, ns))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runRCLoad(c *client.Client, wg *sync.WaitGroup, ns string, size, count int) {
|
func runRCLoad(c *client.Client, wg *sync.WaitGroup, ns, groupName string, size, count int) {
|
||||||
By(fmt.Sprintf("Running %v Replication Controllers with size %v and playing with them", count, size))
|
By(fmt.Sprintf("Running %v Replication Controllers with size %v and playing with them", count, size))
|
||||||
for i := 0; i < count; i++ {
|
for i := 1; i <= count; i++ {
|
||||||
go playWithRC(c, wg, ns, size)
|
go playWithRC(c, wg, ns, groupName+"-"+strconv.Itoa(i), size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,7 +420,7 @@ func RunRC(c *client.Client, name string, ns, image string, replicas int) error
|
|||||||
current := 0
|
current := 0
|
||||||
same := 0
|
same := 0
|
||||||
|
|
||||||
By(fmt.Sprintf("Creating replication controller %s", name))
|
By(fmt.Sprintf("Creating replication controller %s in namespace %s", name, ns))
|
||||||
_, err := c.ReplicationControllers(ns).Create(&api.ReplicationController{
|
_, err := c.ReplicationControllers(ns).Create(&api.ReplicationController{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -450,7 +450,7 @@ func RunRC(c *client.Client, name string, ns, image string, replicas int) error
|
|||||||
return fmt.Errorf("Error creating replication controller: %v", err)
|
return fmt.Errorf("Error creating replication controller: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
By(fmt.Sprintf("Making sure all %d replicas exist", replicas))
|
By(fmt.Sprintf("Making sure all %d replicas of rc %s in namespace %s exist", replicas, name, ns))
|
||||||
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": name}))
|
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": name}))
|
||||||
pods, err := listPods(c, ns, label, fields.Everything())
|
pods, err := listPods(c, ns, label, fields.Everything())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user