@@ -25,12 +25,13 @@ import (
25
25
clientset "k8s.io/client-go/kubernetes"
26
26
"k8s.io/kubernetes/test/e2e/framework"
27
27
28
- . "github.com/onsi/gomega"
28
+ "github.com/onsi/gomega"
29
29
"github.com/onsi/gomega/gstruct"
30
30
)
31
31
32
32
// ServiceAccounts utils
33
33
34
+ // ExpectServiceAccount expects to be able to get the ServiceAccount with specific name from the namespace
34
35
func ExpectServiceAccount (c clientset.Interface , namespace , name string ) {
35
36
_ , err := c .CoreV1 ().
36
37
ServiceAccounts (namespace ).
@@ -40,6 +41,7 @@ func ExpectServiceAccount(c clientset.Interface, namespace, name string) {
40
41
41
42
// Secret utils
42
43
44
+ // GetSecret gets Secret with specific name from the namespace
43
45
func GetSecret (c clientset.Interface , namespace , name string ) * corev1.Secret {
44
46
r , err := c .CoreV1 ().
45
47
Secrets (namespace ).
@@ -50,6 +52,7 @@ func GetSecret(c clientset.Interface, namespace, name string) *corev1.Secret {
50
52
51
53
// ConfigMaps utils
52
54
55
+ // GetConfigMap gets ConfigMap with specific name from the namespace
53
56
func GetConfigMap (c clientset.Interface , namespace , name string ) * corev1.ConfigMap {
54
57
r , err := c .CoreV1 ().
55
58
ConfigMaps (namespace ).
@@ -60,6 +63,7 @@ func GetConfigMap(c clientset.Interface, namespace, name string) *corev1.ConfigM
60
63
61
64
// Service utils
62
65
66
+ // ExpectService expects to be able to get the Service with specific name from the namespace
63
67
func ExpectService (c clientset.Interface , namespace , name string ) {
64
68
_ , err := c .CoreV1 ().
65
69
Services (namespace ).
@@ -69,6 +73,7 @@ func ExpectService(c clientset.Interface, namespace, name string) {
69
73
70
74
// Deployments utils
71
75
76
+ // GetDeployment gets Deployment with specific name from the namespace
72
77
func GetDeployment (c clientset.Interface , namespace , name string ) * appsv1.Deployment {
73
78
r , err := c .AppsV1 ().
74
79
Deployments (namespace ).
@@ -79,6 +84,7 @@ func GetDeployment(c clientset.Interface, namespace, name string) *appsv1.Deploy
79
84
80
85
// DaemonSets utils
81
86
87
+ // GetDaemonSet gets DaemonSet with specific name from the namespace
82
88
func GetDaemonSet (c clientset.Interface , namespace , name string ) * appsv1.DaemonSet {
83
89
r , err := c .AppsV1 ().
84
90
DaemonSets (namespace ).
@@ -89,52 +95,58 @@ func GetDaemonSet(c clientset.Interface, namespace, name string) *appsv1.DaemonS
89
95
90
96
// RBAC utils
91
97
98
+ // ExpectRole expects to be able to get the Role with specific name from the namespace
92
99
func ExpectRole (c clientset.Interface , namespace , name string ) {
93
100
_ , err := c .RbacV1 ().
94
101
Roles (namespace ).
95
102
Get (name , metav1.GetOptions {})
96
103
framework .ExpectNoError (err , "error getting Role %q from namespace %q" , name , namespace )
97
104
}
98
105
106
+ // ExpectRoleBinding expects to be able to get the RoleBinding with specific name from the namespace
99
107
func ExpectRoleBinding (c clientset.Interface , namespace , name string ) {
100
108
_ , err := c .RbacV1 ().
101
109
RoleBindings (namespace ).
102
110
Get (name , metav1.GetOptions {})
103
111
framework .ExpectNoError (err , "error getting RoleBinding %q from namespace %q" , name , namespace )
104
112
}
105
113
114
+ // ExpectClusterRole expects to be able to get the ClusterRole with specific name
106
115
func ExpectClusterRole (c clientset.Interface , name string ) {
107
116
_ , err := c .RbacV1 ().
108
117
ClusterRoles ().
109
118
Get (name , metav1.GetOptions {})
110
119
framework .ExpectNoError (err , "error getting ClusterRole %q" , name )
111
120
}
112
121
122
+ // ExpectClusterRoleBinding expects to be able to get the ClusterRoleBinding with specific name
113
123
func ExpectClusterRoleBinding (c clientset.Interface , name string ) {
114
124
_ , err := c .RbacV1 ().
115
125
ClusterRoleBindings ().
116
126
Get (name , metav1.GetOptions {})
117
127
framework .ExpectNoError (err , "error getting ClusterRoleBindings %q" , name )
118
128
}
119
129
130
+ // ExpectClusterRoleBindingWithSubjectAndRole expects to be able to get the ClusterRoleBinding with specific name, subject and role
120
131
func ExpectClusterRoleBindingWithSubjectAndRole (c clientset.Interface , name , subjectKind , subject , role string ) {
121
132
binding , err := c .RbacV1 ().
122
133
ClusterRoleBindings ().
123
134
Get (name , metav1.GetOptions {})
124
135
framework .ExpectNoError (err , "error getting ClusterRoleBindings %q" , name )
125
- Expect (binding .Subjects ).To (
126
- ContainElement (subjectMatcher (
136
+ gomega . Expect (binding .Subjects ).To (
137
+ gomega . ContainElement (subjectMatcher (
127
138
subject ,
128
139
subjectKind ,
129
140
)),
130
141
"ClusterRole %q does not have %s %q as subject" , name , subjectKind , subject ,
131
142
)
132
- Expect (binding .RoleRef .Name ).To (
133
- Equal (role ),
143
+ gomega . Expect (binding .RoleRef .Name ).To (
144
+ gomega . Equal (role ),
134
145
"ClusterRole %q does not have %q as role" , name , role ,
135
146
)
136
147
}
137
148
149
+ // ExpectSubjectHasAccessToResource expects that the subject has access to the target resource
138
150
func ExpectSubjectHasAccessToResource (c clientset.Interface , subjectKind , subject string , resource * authv1.ResourceAttributes ) {
139
151
var sar * authv1.SubjectAccessReview
140
152
switch subjectKind {
@@ -161,14 +173,14 @@ func ExpectSubjectHasAccessToResource(c clientset.Interface, subjectKind, subjec
161
173
s , err := c .AuthorizationV1 ().SubjectAccessReviews ().Create (sar )
162
174
framework .ExpectNoError (err , "error getting SubjectAccessReview for %s %s to resource %+v" , subjectKind , subject , * sar .Spec .ResourceAttributes )
163
175
164
- Expect (s .Status .Allowed ).Should (BeTrue (), "%s %s has no access to resource %+v" , subjectKind , subject , * sar .Spec .ResourceAttributes )
176
+ gomega . Expect (s .Status .Allowed ).Should (gomega . BeTrue (), "%s %s has no access to resource %+v" , subjectKind , subject , * sar .Spec .ResourceAttributes )
165
177
}
166
178
167
179
// matchers
168
180
169
- func subjectMatcher (name , kind string ) OmegaMatcher {
181
+ func subjectMatcher (name , kind string ) gomega. OmegaMatcher {
170
182
return gstruct .MatchFields (gstruct .IgnoreExtras , gstruct.Fields {
171
- "Name" : Equal (name ),
172
- "Kind" : Equal (kind ),
183
+ "Name" : gomega . Equal (name ),
184
+ "Kind" : gomega . Equal (kind ),
173
185
})
174
186
}
0 commit comments