Create namespace for Pod not to occur error log of namespace not-found

This commit is contained in:
sanposhiho 2022-01-22 13:59:12 +09:00
parent 07c1b4556d
commit d8840405e2

View File

@ -645,7 +645,18 @@ func runWorkload(b *testing.B, tc *testCase, w *workload) []DataItem {
if concreteOp.Namespace != nil {
namespace = *concreteOp.Namespace
} else {
// define Pod's namespace automatically, and create that namespace.
namespace = fmt.Sprintf("namespace-%d", opIndex)
_, err := client.CoreV1().Namespaces().Create(ctx, &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}, metav1.CreateOptions{})
if err != nil && !apierrors.IsAlreadyExists(err) {
b.Fatalf("failed to create namespace for Pod: %v", namespace)
}
b.Cleanup(func() {
err := client.CoreV1().Namespaces().Delete(ctx, namespace, metav1.DeleteOptions{})
if err != nil {
b.Errorf("failed to delete namespace %v", namespace)
}
})
}
var collectors []testDataCollector
var collectorCtx context.Context