-
Notifications
You must be signed in to change notification settings - Fork 187
/
namespace.go
78 lines (61 loc) · 2.34 KB
/
namespace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//go:build e2e
// +build e2e
package namespace
import (
"context"
"fmt"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// CreateInput is the input for Create.
type CreateInput struct {
Creator framework.Creator
Name string
}
// Create creates a namespace with the provided name as generate name.
func Create(input CreateInput) *corev1.Namespace {
Expect(input.Creator).NotTo(BeNil(), "input.Creator is required for Namespace.Create")
Expect(input.Name).NotTo(BeEmpty(), "input.Name is required for Namespace.Create")
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-", input.Name),
},
}
Expect(input.Creator.Create(context.TODO(), ns)).Should(Succeed())
By(fmt.Sprintf("Creating namespace \"%s\"", ns.Name))
return ns
}
// CreateWithName creates a namespace with the provided name as the namespace name.
func CreateWithName(input CreateInput) *corev1.Namespace {
Expect(input.Creator).NotTo(BeNil(), "input.Creator is required for Namespace.CreateWithName")
Expect(input.Name).NotTo(BeEmpty(), "input.Name is required for Namespace.CreateWithName")
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: input.Name,
},
}
Expect(input.Creator.Create(context.TODO(), ns)).Should(Succeed())
By(fmt.Sprintf("Creating namespace \"%s\"", ns.Name))
return ns
}
// DeleteInput is the input for Delete.
type DeleteInput struct {
Deleter framework.Deleter
Getter framework.Getter
Namespace *corev1.Namespace
}
// Delete deletes a namespace.
func Delete(input DeleteInput) {
Expect(input.Deleter).NotTo(BeNil(), "input.Deleter is required for Namespace.Delete")
Expect(input.Getter).NotTo(BeNil(), "input.Getter is required for Namespace.Delete")
Expect(input.Namespace).NotTo(BeNil(), "input.Namespace is required for Namespace.Delete")
By(fmt.Sprintf("Deleting namespace \"%s\"", input.Namespace.Name))
Expect(input.Deleter.Delete(context.TODO(), input.Namespace)).Should(Succeed())
Eventually(func() bool {
return input.Getter.Get(context.TODO(), client.ObjectKey{Name: input.Namespace.Name}, &corev1.Namespace{}) != nil
}, framework.Timeout, framework.Polling).Should(BeTrue())
}