@@ -27,6 +27,7 @@ import (
27
27
"k8s.io/apimachinery/pkg/util/intstr"
28
28
"k8s.io/client-go/dynamic"
29
29
"k8s.io/client-go/kubernetes/scheme"
30
+ "k8s.io/utils/pointer"
30
31
"sigs.k8s.io/controller-runtime/pkg/client/config"
31
32
"sigs.k8s.io/controller-runtime/pkg/log"
32
33
"sigs.k8s.io/e2e-framework/klient/k8s"
@@ -105,6 +106,35 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
105
106
Expect (err ).ToNot (HaveOccurred ())
106
107
})
107
108
109
+ It ("should create a pod with the correct security context" , func () {
110
+ pod := & v1.Pod {
111
+ ObjectMeta : metav1.ObjectMeta {
112
+ Name : "testpod" ,
113
+ },
114
+ Spec : v1.PodSpec {
115
+ Containers : []v1.Container {
116
+ {
117
+ Name : "test" ,
118
+ Image : "quay.io/jitesoft/nginx:mainline" ,
119
+ SecurityContext : & v1.SecurityContext {
120
+ AllowPrivilegeEscalation : pointer .BoolPtr (false ),
121
+ Capabilities : & v1.Capabilities {
122
+ Drop : []v1.Capability {"ALL" },
123
+ },
124
+ RunAsNonRoot : pointer .BoolPtr (true ),
125
+ SeccompProfile : & v1.SeccompProfile {
126
+ Type : v1 .SeccompProfileTypeRuntimeDefault ,
127
+ },
128
+ },
129
+ },
130
+ },
131
+ },
132
+ }
133
+
134
+ err := client .Create (context .TODO (), pod )
135
+ Expect (err ).NotTo (HaveOccurred ())
136
+ })
137
+
108
138
Describe ("sre-pod-validation" , Ordered , func () {
109
139
const (
110
140
privilegedNamespace = "openshift-backplane"
@@ -125,16 +155,41 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
125
155
Spec : v1.PodSpec {
126
156
Containers : []v1.Container {
127
157
{
128
- Name : "test" ,
158
+ Name : "test-ubi " ,
129
159
Image : "registry.access.redhat.com/ubi8/ubi-minimal" ,
160
+ SecurityContext : & v1.SecurityContext {
161
+ AllowPrivilegeEscalation : pointer .BoolPtr (false ),
162
+ Capabilities : & v1.Capabilities {
163
+ Drop : []v1.Capability {"ALL" },
164
+ },
165
+ RunAsNonRoot : pointer .BoolPtr (true ),
166
+ SeccompProfile : & v1.SeccompProfile {
167
+ Type : v1 .SeccompProfileTypeRuntimeDefault ,
168
+ },
169
+ },
170
+ },
171
+ {
172
+ Name : "test-nginx" ,
173
+ Image : "quay.io/jitesoft/nginx:mainline" ,
174
+ SecurityContext : & v1.SecurityContext {
175
+ AllowPrivilegeEscalation : pointer .BoolPtr (false ),
176
+ Capabilities : & v1.Capabilities {
177
+ Drop : []v1.Capability {"ALL" },
178
+ },
179
+ RunAsNonRoot : pointer .BoolPtr (true ),
180
+ SeccompProfile : & v1.SeccompProfile {
181
+ Type : v1 .SeccompProfileTypeRuntimeDefault ,
182
+ },
183
+ },
130
184
},
131
185
},
132
186
Tolerations : []v1.Toleration {
133
187
{
134
188
Key : "node-role.kubernetes.io/master" ,
135
189
Value : "toleration-key-value" ,
136
190
Effect : v1 .TaintEffectNoSchedule ,
137
- }, {
191
+ },
192
+ {
138
193
Key : "node-role.kubernetes.io/infra" ,
139
194
Value : "toleration-key-value2" ,
140
195
Effect : v1 .TaintEffectNoSchedule ,
0 commit comments