Add namespace utility test functions

This commit is contained in:
Wojciech Tyczyński 2022-05-21 18:04:46 +02:00
parent eb37a5d9c1
commit 6ae4bbbfc2
2 changed files with 21 additions and 0 deletions

View File

@ -402,6 +402,9 @@ func NewControlPlaneConfigWithOptions(opts *ControlPlaneConfigOptions) *controlp
// CloseFunc can be called to cleanup the API server // CloseFunc can be called to cleanup the API server
type CloseFunc func() 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. // RunAnAPIServer starts a API server with the provided config.
func RunAnAPIServer(controlPlaneConfig *controlplane.Config) (*controlplane.Instance, *httptest.Server, CloseFunc) { func RunAnAPIServer(controlPlaneConfig *controlplane.Config) (*controlplane.Instance, *httptest.Server, CloseFunc) {
if controlPlaneConfig == nil { if controlPlaneConfig == nil {

View File

@ -66,6 +66,24 @@ func DeleteTestingNamespace(ns *v1.Namespace, t *testing.T) {
// cleaning up data they create has no impact. // 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. // GetReadySchedulableNodes addresses the common use case of getting nodes you can do work on.
// 1) Needs to be schedulable. // 1) Needs to be schedulable.
// 2) Needs to be ready. // 2) Needs to be ready.