Skip to content

Commit 18fce67

Browse files
committed
ensure the namespace exists
Signed-off-by: Paco Xu <[email protected]>
1 parent 9937f8f commit 18fce67

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

vertical-pod-autoscaler/e2e/v1/common.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@ func getVpaClientSet(f *framework.Framework) vpa_clientset.Interface {
302302
return vpa_clientset.NewForConfigOrDie(config)
303303
}
304304

305+
func CheckNamespaceOrCreate(f *framework.Framework, ns string) {
306+
_, err := f.ClientSet.CoreV1().Namespaces().Get(context.TODO(), ns, metav1.GetOptions{})
307+
if err == nil {
308+
ginkgo.By(fmt.Sprintf("Namespace %v already exists", ns))
309+
}
310+
if err != nil {
311+
ginkgo.By(fmt.Sprintf("Creating namespace %v", ns))
312+
_, err = f.ClientSet.CoreV1().Namespaces().Create(context.TODO(), &apiv1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ns}}, metav1.CreateOptions{})
313+
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "unexpected error creating namespace")
314+
}
315+
}
316+
305317
// InstallVPA installs a VPA object in the test cluster.
306318
func InstallVPA(f *framework.Framework, vpa *vpa_types.VerticalPodAutoscaler) {
307319
vpaClientSet := getVpaClientSet(f)

vertical-pod-autoscaler/e2e/v1/full_vpa.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ var _ = FullVpaE2eDescribe("Pods under VPA", func() {
8181
}
8282

8383
containerName := GetHamsterContainerNameByIndex(0)
84+
// check if the namespace exists and print the namespace name
85+
ginkgo.By(fmt.Sprintf("Namespace name: %s", f.Namespace.Name))
86+
CheckNamespaceOrCreate(f, f.Namespace.Name)
87+
8488
vpaCRD := test.VerticalPodAutoscaler().
8589
WithName("hamster-vpa").
8690
WithNamespace(f.Namespace.Name).

0 commit comments

Comments
 (0)