From 6ae4bbbfc27861d23199f10e87e0238c57cb302f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Tyczy=C5=84ski?= Date: Sat, 21 May 2022 18:04:46 +0200 Subject: [PATCH] Add namespace utility test functions --- .../framework/controlplane_utils.go | 3 +++ test/integration/framework/util.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/test/integration/framework/controlplane_utils.go b/test/integration/framework/controlplane_utils.go index c133e58cd0a..d1416342b9f 100644 --- a/test/integration/framework/controlplane_utils.go +++ b/test/integration/framework/controlplane_utils.go @@ -402,6 +402,9 @@ func NewControlPlaneConfigWithOptions(opts *ControlPlaneConfigOptions) *controlp // CloseFunc can be called to cleanup the API server type CloseFunc func() +// DEPRECATED: Use StartTestServer or directly StartTestServer directly +// from cmd/kube-apiserver/app/testing. +// // RunAnAPIServer starts a API server with the provided config. func RunAnAPIServer(controlPlaneConfig *controlplane.Config) (*controlplane.Instance, *httptest.Server, CloseFunc) { if controlPlaneConfig == nil { diff --git a/test/integration/framework/util.go b/test/integration/framework/util.go index 457a6e8f91f..db8da91d64c 100644 --- a/test/integration/framework/util.go +++ b/test/integration/framework/util.go @@ -66,6 +66,24 @@ func DeleteTestingNamespace(ns *v1.Namespace, t *testing.T) { // cleaning up data they create has no impact. } +// CreateNamespaceOrDie creates a namespace. +func CreateNamespaceOrDie(c clientset.Interface, baseName string, t *testing.T) *v1.Namespace { + ns := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: baseName}} + result, err := c.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{}) + if err != nil { + t.Fatalf("Failed to create namespace: %v", err) + } + return result +} + +// DeleteNamespaceOrDie deletes a namespace. +func DeleteNamespaceOrDie(c clientset.Interface, ns *v1.Namespace, t *testing.T) { + err := c.CoreV1().Namespaces().Delete(context.TODO(), ns.Name, metav1.DeleteOptions{}) + if err != nil { + t.Fatalf("Failed to delete namespace: %v", err) + } +} + // GetReadySchedulableNodes addresses the common use case of getting nodes you can do work on. // 1) Needs to be schedulable. // 2) Needs to be ready.