@@ -28,41 +28,33 @@ func NewMustRunAs(options *securityapi.SELinuxContextStrategyOptions) (SELinuxSe
28
28
}
29
29
30
30
// Generate creates the SELinuxOptions based on constraint rules.
31
- func (s * mustRunAs ) Generate (pod * api.Pod , container * api.Container ) (* api.SELinuxOptions , error ) {
31
+ func (s * mustRunAs ) Generate (_ * api.Pod , _ * api.Container ) (* api.SELinuxOptions , error ) {
32
32
return s .opts .SELinuxOptions , nil
33
33
}
34
34
35
35
// Validate ensures that the specified values fall within the range of the strategy.
36
- func (s * mustRunAs ) Validate (pod * api.Pod , container * api.Container ) field.ErrorList {
36
+ func (s * mustRunAs ) Validate (fldPath * field. Path , _ * api.Pod , _ * api.Container , seLinux * api. SELinuxOptions ) field.ErrorList {
37
37
allErrs := field.ErrorList {}
38
38
39
- if container .SecurityContext == nil {
40
- detail := fmt .Sprintf ("unable to validate nil security context for %s" , container .Name )
41
- allErrs = append (allErrs , field .Invalid (field .NewPath ("securityContext" ), container .SecurityContext , detail ))
39
+ if seLinux == nil {
40
+ allErrs = append (allErrs , field .Required (fldPath , "" ))
42
41
return allErrs
43
42
}
44
- if container .SecurityContext .SELinuxOptions == nil {
45
- detail := fmt .Sprintf ("unable to validate nil seLinuxOptions for %s" , container .Name )
46
- allErrs = append (allErrs , field .Invalid (field .NewPath ("seLinuxOptions" ), container .SecurityContext .SELinuxOptions , detail ))
47
- return allErrs
48
- }
49
- seLinuxOptionsPath := field .NewPath ("seLinuxOptions" )
50
- seLinux := container .SecurityContext .SELinuxOptions
51
43
if seLinux .Level != s .opts .SELinuxOptions .Level {
52
- detail := fmt .Sprintf ("seLinuxOptions.level on %s does not match required level. Found %s, wanted %s" , container . Name , seLinux . Level , s .opts .SELinuxOptions .Level )
53
- allErrs = append (allErrs , field .Invalid (seLinuxOptionsPath .Child ("level" ), seLinux .Level , detail ))
44
+ detail := fmt .Sprintf ("must be %s" , s .opts .SELinuxOptions .Level )
45
+ allErrs = append (allErrs , field .Invalid (fldPath .Child ("level" ), seLinux .Level , detail ))
54
46
}
55
47
if seLinux .Role != s .opts .SELinuxOptions .Role {
56
- detail := fmt .Sprintf ("seLinuxOptions.role on %s does not match required role. Found %s, wanted %s" , container . Name , seLinux . Role , s .opts .SELinuxOptions .Role )
57
- allErrs = append (allErrs , field .Invalid (seLinuxOptionsPath .Child ("role" ), seLinux .Role , detail ))
48
+ detail := fmt .Sprintf ("must be %s" , s .opts .SELinuxOptions .Role )
49
+ allErrs = append (allErrs , field .Invalid (fldPath .Child ("role" ), seLinux .Role , detail ))
58
50
}
59
51
if seLinux .Type != s .opts .SELinuxOptions .Type {
60
- detail := fmt .Sprintf ("seLinuxOptions.type on %s does not match required type. Found %s, wanted %s" , container . Name , seLinux . Type , s .opts .SELinuxOptions .Type )
61
- allErrs = append (allErrs , field .Invalid (seLinuxOptionsPath .Child ("type" ), seLinux .Type , detail ))
52
+ detail := fmt .Sprintf ("must be %s" , s .opts .SELinuxOptions .Type )
53
+ allErrs = append (allErrs , field .Invalid (fldPath .Child ("type" ), seLinux .Type , detail ))
62
54
}
63
55
if seLinux .User != s .opts .SELinuxOptions .User {
64
- detail := fmt .Sprintf ("seLinuxOptions.user on %s does not match required user. Found %s, wanted %s" , container . Name , seLinux . User , s .opts .SELinuxOptions .User )
65
- allErrs = append (allErrs , field .Invalid (seLinuxOptionsPath .Child ("user" ), seLinux .User , detail ))
56
+ detail := fmt .Sprintf ("must be %s" , s .opts .SELinuxOptions .User )
57
+ allErrs = append (allErrs , field .Invalid (fldPath .Child ("user" ), seLinux .User , detail ))
66
58
}
67
59
68
60
return allErrs
0 commit comments