@@ -13,6 +13,7 @@ import (
13
13
"k8s.io/apimachinery/pkg/runtime"
14
14
"k8s.io/client-go/kubernetes/fake"
15
15
clienttesting "k8s.io/client-go/testing"
16
+ psapi "k8s.io/pod-security-admission/api"
16
17
"k8s.io/pod-security-admission/policy"
17
18
)
18
19
@@ -68,7 +69,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
68
69
name string
69
70
namespace * corev1.Namespace
70
71
pods []corev1.Pod
71
- enforceLevel string
72
+ enforceLevel psapi. Level
72
73
expectedConditions podSecurityOperatorConditions
73
74
expectError bool
74
75
}{
@@ -80,7 +81,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
80
81
},
81
82
},
82
83
pods : []corev1.Pod {},
83
- enforceLevel : "restricted" ,
84
+ enforceLevel : psapi . LevelRestricted ,
84
85
expectedConditions : podSecurityOperatorConditions {
85
86
violatingRunLevelZeroNamespaces : []string {"kube-system" },
86
87
},
@@ -94,7 +95,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
94
95
},
95
96
},
96
97
pods : []corev1.Pod {},
97
- enforceLevel : "restricted" ,
98
+ enforceLevel : psapi . LevelRestricted ,
98
99
expectedConditions : podSecurityOperatorConditions {
99
100
violatingRunLevelZeroNamespaces : []string {"default" },
100
101
},
@@ -108,7 +109,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
108
109
},
109
110
},
110
111
pods : []corev1.Pod {},
111
- enforceLevel : "restricted" ,
112
+ enforceLevel : psapi . LevelRestricted ,
112
113
expectedConditions : podSecurityOperatorConditions {
113
114
violatingRunLevelZeroNamespaces : []string {"kube-public" },
114
115
},
@@ -122,7 +123,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
122
123
},
123
124
},
124
125
pods : []corev1.Pod {},
125
- enforceLevel : "restricted" ,
126
+ enforceLevel : psapi . LevelRestricted ,
126
127
expectedConditions : podSecurityOperatorConditions {
127
128
violatingOpenShiftNamespaces : []string {"openshift-test" },
128
129
},
@@ -155,7 +156,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
155
156
pods : []corev1.Pod {
156
157
newUserSCCPodPrivileged ("user-pod" , "customer-ns" ),
157
158
},
158
- enforceLevel : "restricted" ,
159
+ enforceLevel : psapi . LevelRestricted ,
159
160
expectedConditions : podSecurityOperatorConditions {
160
161
violatingUserSCCNamespaces : []string {"customer-ns" },
161
162
},
@@ -171,7 +172,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
171
172
pods : []corev1.Pod {
172
173
newUserSCCPodWithPrivilegedContainer ("user-scc-violating-pod" , "user-scc-violation-test" ),
173
174
},
174
- enforceLevel : "restricted" ,
175
+ enforceLevel : psapi . LevelRestricted ,
175
176
expectedConditions : podSecurityOperatorConditions {
176
177
violatingUserSCCNamespaces : []string {"user-scc-violation-test" },
177
178
},
@@ -187,7 +188,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
187
188
pods : []corev1.Pod {
188
189
newServiceAccountPod ("sa-pod" , "customer-ns" ),
189
190
},
190
- enforceLevel : "restricted" ,
191
+ enforceLevel : psapi . LevelRestricted ,
191
192
expectedConditions : podSecurityOperatorConditions {
192
193
violatingCustomerNamespaces : []string {"customer-ns" },
193
194
},
@@ -221,7 +222,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
221
222
pods : []corev1.Pod {
222
223
newUserSCCPodRestricted ("user-pod" , "customer-ns" ),
223
224
},
224
- enforceLevel : "restricted" ,
225
+ enforceLevel : psapi . LevelRestricted ,
225
226
expectedConditions : podSecurityOperatorConditions {
226
227
violatingCustomerNamespaces : []string {"customer-ns" },
227
228
},
@@ -235,7 +236,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
235
236
},
236
237
},
237
238
pods : []corev1.Pod {},
238
- enforceLevel : "restricted" ,
239
+ enforceLevel : psapi . LevelRestricted ,
239
240
expectedConditions : podSecurityOperatorConditions {
240
241
violatingCustomerNamespaces : []string {"customer-ns" },
241
242
},
@@ -265,7 +266,7 @@ func TestClassifyViolatingNamespace(t *testing.T) {
265
266
},
266
267
},
267
268
},
268
- enforceLevel : "restricted" ,
269
+ enforceLevel : psapi . LevelRestricted ,
269
270
expectedConditions : podSecurityOperatorConditions {
270
271
violatingCustomerNamespaces : []string {"customer-ns" },
271
272
},
@@ -281,24 +282,12 @@ func TestClassifyViolatingNamespace(t *testing.T) {
281
282
pods : []corev1.Pod {
282
283
newUserSCCPodPrivileged ("user-pod" , "customer-ns" ),
283
284
},
284
- enforceLevel : "privileged" ,
285
+ enforceLevel : psapi . LevelPrivileged ,
285
286
expectedConditions : podSecurityOperatorConditions {
286
287
violatingCustomerNamespaces : []string {"customer-ns" },
287
288
},
288
289
expectError : false ,
289
290
},
290
- {
291
- name : "invalid PSA level causes error" ,
292
- namespace : & corev1.Namespace {
293
- ObjectMeta : metav1.ObjectMeta {
294
- Name : "customer-ns" ,
295
- },
296
- },
297
- pods : []corev1.Pod {},
298
- enforceLevel : "invalid-level" ,
299
- expectedConditions : podSecurityOperatorConditions {},
300
- expectError : true ,
301
- },
302
291
} {
303
292
t .Run (tt .name , func (t * testing.T ) {
304
293
controller , err := createTestController (tt .pods )
0 commit comments