@@ -85,7 +85,7 @@ func CompareWorkflows(actual *v1alpha1.Workflow, expected *v1alpha1.Workflow) {
8585 gomega .Expect (actual .Spec .Priority ).To (gomega .Equal (expected .Spec .Priority ), "Priority is not same" )
8686 gomega .Expect (actual .Spec .RetryStrategy ).To (gomega .Equal (expected .Spec .RetryStrategy ), "RetryStrategy is not same" )
8787 gomega .Expect (actual .Spec .SchedulerName ).To (gomega .Equal (expected .Spec .SchedulerName ), "SchedulerName is not same" )
88- gomega . Expect (actual .Spec .SecurityContext ). To ( gomega . Equal ( expected .Spec .SecurityContext ) , "SecurityContext is not same" )
88+ matchPodSecurityContext (actual .Spec .SecurityContext , expected .Spec .SecurityContext , "WorkflowSpec SecurityContext is not same" )
8989 gomega .Expect (actual .Spec .Shutdown ).To (gomega .Equal (expected .Spec .Shutdown ), "Shutdown is not same" )
9090 gomega .Expect (actual .Spec .ServiceAccountName ).To (gomega .Equal (expected .Spec .ServiceAccountName ), "ServiceAccountName is not same" )
9191 gomega .Expect (actual .Spec .Suspend ).To (gomega .Equal (expected .Spec .Suspend ), "Suspend is not same" )
@@ -100,7 +100,7 @@ func CompareWorkflows(actual *v1alpha1.Workflow, expected *v1alpha1.Workflow) {
100100 gomega .Expect (actual .Spec .Templates [index ].Synchronization ).To (gomega .Equal (template .Synchronization ), "Synchronization is not same" )
101101 gomega .Expect (actual .Spec .Templates [index ].Volumes ).To (gomega .Equal (template .Volumes ), "Volumes is not same" )
102102 gomega .Expect (actual .Spec .Templates [index ].Suspend ).To (gomega .Equal (template .Suspend ), "Suspend is not same" )
103- gomega . Expect (actual .Spec .Templates [index ].SecurityContext ). To ( gomega . Equal ( template .SecurityContext ) , "SecurityContext is not same" )
103+ matchPodSecurityContext (actual .Spec .Templates [index ].SecurityContext , template .SecurityContext , "Template SecurityContext is not same" )
104104 gomega .Expect (actual .Spec .Templates [index ].SchedulerName ).To (gomega .Equal (template .SchedulerName ), "SchedulerName is not same" )
105105 gomega .Expect (actual .Spec .Templates [index ].RetryStrategy ).To (gomega .Equal (template .RetryStrategy ), "RetryStrategy is not same" )
106106 gomega .Expect (actual .Spec .Templates [index ].Parallelism ).To (gomega .Equal (template .Parallelism ), "Parallelism is not same" )
@@ -163,7 +163,7 @@ func MatchContainer(actual *v1.Container, expected *v1.Container) {
163163 if expected != nil {
164164 gomega .Expect (actual .Name ).To (gomega .Equal (expected .Name ), "Container Name is not same" )
165165 gomega .Expect (actual .Args ).To (gomega .ConsistOf (expected .Args ), "Container Args is not same" )
166- gomega . Expect (actual .SecurityContext ). To ( gomega . Equal ( expected .SecurityContext ) , "Container SecurityContext is not same" )
166+ matchContainerSecurityContext (actual .SecurityContext , expected .SecurityContext , "Container SecurityContext is not same" )
167167 gomega .Expect (actual .Env ).To (gomega .Equal (expected .Env ), "Container Env is not same" )
168168 gomega .Expect (actual .EnvFrom ).To (gomega .Equal (expected .EnvFrom ), "Container EnvFrom is not same" )
169169 gomega .Expect (actual .Command ).To (gomega .Equal (expected .Command ), "Container Command is not same" )
@@ -197,7 +197,7 @@ func MatchUserContainer(actual *v1alpha1.UserContainer, expected *v1alpha1.UserC
197197 if expected != nil {
198198 gomega .Expect (actual .Name ).To (gomega .Equal (expected .Name ), "User Container Name is not same" )
199199 gomega .Expect (actual .Args ).To (gomega .ConsistOf (expected .Args ), "User Container Args is not same" )
200- gomega . Expect (actual .SecurityContext ). To ( gomega . Equal ( expected .SecurityContext ) , "User Container SecurityContext is not same" )
200+ matchContainerSecurityContext (actual .SecurityContext , expected .SecurityContext , "User Container SecurityContext is not same" )
201201 gomega .Expect (actual .Env ).To (gomega .Equal (expected .Env ), "User Container Env is not same" )
202202 gomega .Expect (actual .EnvFrom ).To (gomega .Equal (expected .EnvFrom ), "User Container EnvFrom is not same" )
203203 gomega .Expect (actual .Command ).To (gomega .Equal (expected .Command ), "User Container Command is not same" )
@@ -266,3 +266,62 @@ func AreStringsSameWithoutOrder(s1, s2 string) bool {
266266 // Compare the sorted slices
267267 return reflect .DeepEqual (r1 , r2 )
268268}
269+
270+ func matchPodSecurityContext (actual * v1.PodSecurityContext , expected * v1.PodSecurityContext , msg string ) {
271+ if expected == nil {
272+ return
273+ }
274+ gomega .Expect (actual ).NotTo (gomega .BeNil (), msg )
275+ if expected .RunAsUser != nil {
276+ gomega .Expect (actual .RunAsUser ).To (gomega .Equal (expected .RunAsUser ), msg )
277+ }
278+ if expected .RunAsGroup != nil {
279+ gomega .Expect (actual .RunAsGroup ).To (gomega .Equal (expected .RunAsGroup ), msg )
280+ }
281+ if expected .FSGroup != nil {
282+ gomega .Expect (actual .FSGroup ).To (gomega .Equal (expected .FSGroup ), msg )
283+ }
284+ if expected .RunAsNonRoot != nil {
285+ gomega .Expect (actual .RunAsNonRoot ).To (gomega .Equal (expected .RunAsNonRoot ), msg )
286+ }
287+ if expected .SeccompProfile != nil {
288+ gomega .Expect (actual .SeccompProfile ).NotTo (gomega .BeNil (), msg )
289+ gomega .Expect (actual .SeccompProfile .Type ).To (gomega .Equal (expected .SeccompProfile .Type ), msg )
290+ gomega .Expect (actual .SeccompProfile .LocalhostProfile ).To (gomega .Equal (expected .SeccompProfile .LocalhostProfile ), msg )
291+ }
292+ }
293+
294+ func matchContainerSecurityContext (actual * v1.SecurityContext , expected * v1.SecurityContext , msg string ) {
295+ if expected == nil {
296+ return
297+ }
298+ gomega .Expect (actual ).NotTo (gomega .BeNil (), msg )
299+ if expected .AllowPrivilegeEscalation != nil {
300+ gomega .Expect (actual .AllowPrivilegeEscalation ).To (gomega .Equal (expected .AllowPrivilegeEscalation ), msg )
301+ }
302+ if expected .Privileged != nil {
303+ gomega .Expect (actual .Privileged ).To (gomega .Equal (expected .Privileged ), msg )
304+ }
305+ if expected .ReadOnlyRootFilesystem != nil {
306+ gomega .Expect (actual .ReadOnlyRootFilesystem ).To (gomega .Equal (expected .ReadOnlyRootFilesystem ), msg )
307+ }
308+ if expected .RunAsNonRoot != nil {
309+ gomega .Expect (actual .RunAsNonRoot ).To (gomega .Equal (expected .RunAsNonRoot ), msg )
310+ }
311+ if expected .RunAsUser != nil {
312+ gomega .Expect (actual .RunAsUser ).To (gomega .Equal (expected .RunAsUser ), msg )
313+ }
314+ if expected .RunAsGroup != nil {
315+ gomega .Expect (actual .RunAsGroup ).To (gomega .Equal (expected .RunAsGroup ), msg )
316+ }
317+ if expected .Capabilities != nil {
318+ gomega .Expect (actual .Capabilities ).NotTo (gomega .BeNil (), msg )
319+ gomega .Expect (actual .Capabilities .Drop ).To (gomega .Equal (expected .Capabilities .Drop ), msg )
320+ gomega .Expect (actual .Capabilities .Add ).To (gomega .Equal (expected .Capabilities .Add ), msg )
321+ }
322+ if expected .SeccompProfile != nil {
323+ gomega .Expect (actual .SeccompProfile ).NotTo (gomega .BeNil (), msg )
324+ gomega .Expect (actual .SeccompProfile .Type ).To (gomega .Equal (expected .SeccompProfile .Type ), msg )
325+ gomega .Expect (actual .SeccompProfile .LocalhostProfile ).To (gomega .Equal (expected .SeccompProfile .LocalhostProfile ), msg )
326+ }
327+ }
0 commit comments