Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions support/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,48 @@ func deleteTestNamespace(t Test, namespace *corev1.Namespace) {
})
t.Expect(err).NotTo(gomega.HaveOccurred())
}

func CreateTestNamespaceWithName(t Test, namespaceName string, options ...Option[*corev1.Namespace]) *corev1.Namespace {
t.T().Helper()
namespace := &corev1.Namespace{
TypeMeta: metav1.TypeMeta{
APIVersion: corev1.SchemeGroupVersion.String(),
Kind: "Namespace",
},
ObjectMeta: metav1.ObjectMeta{
Name: namespaceName,
},
}

for _, option := range options {
t.Expect(option.applyTo(namespace)).To(gomega.Succeed())
}

namespace, err := t.Client().Core().CoreV1().Namespaces().Create(t.Ctx(), namespace, metav1.CreateOptions{})
t.Expect(err).NotTo(gomega.HaveOccurred())

return namespace
}

func GetNamespaceWithName(t Test, namespaceName string) *corev1.Namespace {
namespace, err := t.Client().Core().CoreV1().Namespaces().Get(t.Ctx(), namespaceName, metav1.GetOptions{})
if err != nil {
t.T().Errorf("Failed to retrieve namespace with name %s: %v", namespaceName, err)
}
return namespace
}

func DeleteTestNamespace(t Test, namespace *corev1.Namespace) {
t.T().Helper()
propagationPolicy := metav1.DeletePropagationBackground
StoreNamespaceLogs(t, namespace)
err := t.Client().Core().CoreV1().Namespaces().Delete(t.Ctx(), namespace.Name, metav1.DeleteOptions{
PropagationPolicy: &propagationPolicy,
})
t.Expect(err).NotTo(gomega.HaveOccurred())
}

func StoreNamespaceLogs(t Test, namespace *corev1.Namespace) {
storeAllPodLogs(t, namespace)
storeEvents(t, namespace)
}