@@ -66,17 +66,10 @@ func (s *defaultCapabilities) Generate(pod *api.Pod, container *api.Container) (
66
66
}
67
67
68
68
// Validate ensures that the specified values fall within the range of the strategy.
69
- func (s * defaultCapabilities ) Validate (pod * api.Pod , container * api.Container ) field.ErrorList {
69
+ func (s * defaultCapabilities ) Validate (pod * api.Pod , container * api.Container , capabilities * api. Capabilities ) field.ErrorList {
70
70
allErrs := field.ErrorList {}
71
71
72
- // if the security context isn't set then we haven't generated correctly. Shouldn't get here
73
- // if using the provider correctly
74
- if container .SecurityContext == nil {
75
- allErrs = append (allErrs , field .Invalid (field .NewPath ("securityContext" ), container .SecurityContext , "no security context is set" ))
76
- return allErrs
77
- }
78
-
79
- if container .SecurityContext .Capabilities == nil {
72
+ if capabilities == nil {
80
73
// if container.SC.Caps is nil then nothing was defaulted by the strat or requested by the pod author
81
74
// if there are no required caps on the strategy and nothing is requested on the pod
82
75
// then we can safely return here without further validation.
@@ -86,7 +79,7 @@ func (s *defaultCapabilities) Validate(pod *api.Pod, container *api.Container) f
86
79
87
80
// container has no requested caps but we have required caps. We should have something in
88
81
// at least the drops on the container.
89
- allErrs = append (allErrs , field .Invalid (field .NewPath ("capabilities" ), container . SecurityContext . Capabilities ,
82
+ allErrs = append (allErrs , field .Invalid (field .NewPath ("capabilities" ), capabilities ,
90
83
"required capabilities are not set on the securityContext" ))
91
84
return allErrs
92
85
}
@@ -101,20 +94,20 @@ func (s *defaultCapabilities) Validate(pod *api.Pod, container *api.Container) f
101
94
// validate that anything being added is in the default or allowed sets
102
95
defaultAdd := makeCapSet (s .defaultAddCapabilities )
103
96
104
- for _ , cap := range container . SecurityContext . Capabilities .Add {
97
+ for _ , cap := range capabilities .Add {
105
98
sCap := string (cap )
106
99
if ! defaultAdd .Has (sCap ) && ! allowedAdd .Has (sCap ) {
107
100
allErrs = append (allErrs , field .Invalid (field .NewPath ("capabilities" , "add" ), sCap , "capability may not be added" ))
108
101
}
109
102
}
110
103
111
104
// validate that anything that is required to be dropped is in the drop set
112
- containerDrops := makeCapSet (container . SecurityContext . Capabilities .Drop )
105
+ containerDrops := makeCapSet (capabilities .Drop )
113
106
114
107
for _ , requiredDrop := range s .requiredDropCapabilities {
115
108
sDrop := string (requiredDrop )
116
109
if ! containerDrops .Has (sDrop ) {
117
- allErrs = append (allErrs , field .Invalid (field .NewPath ("capabilities" , "drop" ), container . SecurityContext . Capabilities .Drop ,
110
+ allErrs = append (allErrs , field .Invalid (field .NewPath ("capabilities" , "drop" ), capabilities .Drop ,
118
111
fmt .Sprintf ("%s is required to be dropped but was not found" , sDrop )))
119
112
}
120
113
}
0 commit comments