mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 22:05:59 +00:00
scheduler_perf: refactor common code
This commit is contained in:
parent
5f23f83587
commit
969d28b12b
@ -758,6 +758,7 @@ func runWorkload(ctx context.Context, b *testing.B, tc *testCase, w *workload) [
|
|||||||
// numPodsScheduledPerNamespace has all namespaces created in workload and the number of pods they (will) have.
|
// numPodsScheduledPerNamespace has all namespaces created in workload and the number of pods they (will) have.
|
||||||
// All namespaces listed in numPodsScheduledPerNamespace will be cleaned up.
|
// All namespaces listed in numPodsScheduledPerNamespace will be cleaned up.
|
||||||
numPodsScheduledPerNamespace := make(map[string]int)
|
numPodsScheduledPerNamespace := make(map[string]int)
|
||||||
|
|
||||||
b.Cleanup(func() {
|
b.Cleanup(func() {
|
||||||
for namespace := range numPodsScheduledPerNamespace {
|
for namespace := range numPodsScheduledPerNamespace {
|
||||||
if err := client.CoreV1().Namespaces().Delete(ctx, namespace, metav1.DeleteOptions{}); err != nil {
|
if err := client.CoreV1().Namespaces().Delete(ctx, namespace, metav1.DeleteOptions{}); err != nil {
|
||||||
@ -816,15 +817,7 @@ func runWorkload(ctx context.Context, b *testing.B, tc *testCase, w *workload) [
|
|||||||
if concreteOp.Namespace != nil {
|
if concreteOp.Namespace != nil {
|
||||||
namespace = *concreteOp.Namespace
|
namespace = *concreteOp.Namespace
|
||||||
}
|
}
|
||||||
if _, ok := numPodsScheduledPerNamespace[namespace]; !ok {
|
createNamespaceIfNotPresent(ctx, b, client, namespace, &numPodsScheduledPerNamespace)
|
||||||
// The namespace has not created yet.
|
|
||||||
// So, creat that and register it to numPodsScheduledPerNamespace.
|
|
||||||
_, err := client.CoreV1().Namespaces().Create(ctx, &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}, metav1.CreateOptions{})
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("failed to create namespace for Pod: %v", namespace)
|
|
||||||
}
|
|
||||||
numPodsScheduledPerNamespace[namespace] = 0
|
|
||||||
}
|
|
||||||
if concreteOp.PodTemplatePath == nil {
|
if concreteOp.PodTemplatePath == nil {
|
||||||
concreteOp.PodTemplatePath = tc.DefaultPodTemplatePath
|
concreteOp.PodTemplatePath = tc.DefaultPodTemplatePath
|
||||||
}
|
}
|
||||||
@ -1020,6 +1013,18 @@ func runWorkload(ctx context.Context, b *testing.B, tc *testCase, w *workload) [
|
|||||||
return dataItems
|
return dataItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createNamespaceIfNotPresent(ctx context.Context, b *testing.B, client clientset.Interface, namespace string, podsPerNamespace *map[string]int) {
|
||||||
|
if _, ok := (*podsPerNamespace)[namespace]; !ok {
|
||||||
|
// The namespace has not created yet.
|
||||||
|
// So, create that and register it.
|
||||||
|
_, err := client.CoreV1().Namespaces().Create(ctx, &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}, metav1.CreateOptions{})
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("failed to create namespace for Pod: %v", namespace)
|
||||||
|
}
|
||||||
|
(*podsPerNamespace)[namespace] = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type testDataCollector interface {
|
type testDataCollector interface {
|
||||||
run(ctx context.Context)
|
run(ctx context.Context)
|
||||||
collect() []DataItem
|
collect() []DataItem
|
||||||
|
Loading…
Reference in New Issue
Block a user