@@ -18,6 +18,7 @@ package validation
18
18
19
19
import (
20
20
"fmt"
21
+ utilvalidation "k8s.io/apimachinery/pkg/util/validation"
21
22
"net/url"
22
23
"os"
23
24
"path/filepath"
@@ -28,7 +29,6 @@ import (
28
29
"k8s.io/api/authorization/v1beta1"
29
30
"k8s.io/apimachinery/pkg/runtime"
30
31
"k8s.io/apimachinery/pkg/util/sets"
31
- utilvalidation "k8s.io/apimachinery/pkg/util/validation"
32
32
"k8s.io/apimachinery/pkg/util/validation/field"
33
33
api "k8s.io/apiserver/pkg/apis/apiserver"
34
34
"k8s.io/client-go/util/cert"
@@ -220,7 +220,7 @@ func ValidateAuthorizationConfiguration(fldPath *field.Path, c *api.Authorizatio
220
220
}
221
221
222
222
seenAuthorizerTypes := sets .NewString ()
223
- seenWebhookNames := sets .NewString ()
223
+ seenAuthorizerNames := sets .NewString ()
224
224
for i , a := range c .Authorizers {
225
225
fldPath := fldPath .Child ("authorizers" ).Index (i )
226
226
aType := string (a .Type )
@@ -238,13 +238,22 @@ func ValidateAuthorizationConfiguration(fldPath *field.Path, c *api.Authorizatio
238
238
}
239
239
seenAuthorizerTypes .Insert (aType )
240
240
241
+ if len (a .Name ) == 0 {
242
+ allErrs = append (allErrs , field .Required (fldPath .Child ("name" ), "" ))
243
+ } else if seenAuthorizerNames .Has (a .Name ) {
244
+ allErrs = append (allErrs , field .Duplicate (fldPath .Child ("name" ), a .Name ))
245
+ } else if errs := utilvalidation .IsDNS1123Subdomain (a .Name ); len (errs ) != 0 {
246
+ allErrs = append (allErrs , field .Invalid (fldPath .Child ("name" ), a .Name , fmt .Sprintf ("authorizer name is invalid: %s" , strings .Join (errs , ", " ))))
247
+ }
248
+ seenAuthorizerNames .Insert (a .Name )
249
+
241
250
switch a .Type {
242
251
case api .TypeWebhook :
243
252
if a .Webhook == nil {
244
253
allErrs = append (allErrs , field .Required (fldPath .Child ("webhook" ), "required when type=Webhook" ))
245
254
continue
246
255
}
247
- allErrs = append (allErrs , ValidateWebhookConfiguration (fldPath , a .Webhook , seenWebhookNames )... )
256
+ allErrs = append (allErrs , ValidateWebhookConfiguration (fldPath , a .Webhook )... )
248
257
default :
249
258
if a .Webhook != nil {
250
259
allErrs = append (allErrs , field .Invalid (fldPath .Child ("webhook" ), "non-null" , "may only be specified when type=Webhook" ))
@@ -255,16 +264,8 @@ func ValidateAuthorizationConfiguration(fldPath *field.Path, c *api.Authorizatio
255
264
return allErrs
256
265
}
257
266
258
- func ValidateWebhookConfiguration (fldPath * field.Path , c * api.WebhookConfiguration , seenNames sets. String ) field.ErrorList {
267
+ func ValidateWebhookConfiguration (fldPath * field.Path , c * api.WebhookConfiguration ) field.ErrorList {
259
268
allErrs := field.ErrorList {}
260
- if len (c .Name ) == 0 {
261
- allErrs = append (allErrs , field .Required (fldPath .Child ("name" ), "" ))
262
- } else if seenNames .Has (c .Name ) {
263
- allErrs = append (allErrs , field .Duplicate (fldPath .Child ("name" ), c .Name ))
264
- } else if errs := utilvalidation .IsDNS1123Subdomain (c .Name ); len (errs ) != 0 {
265
- allErrs = append (allErrs , field .Invalid (fldPath .Child ("name" ), c .Name , fmt .Sprintf ("webhook name is invalid: %s" , strings .Join (errs , ", " ))))
266
- }
267
- seenNames .Insert (c .Name )
268
269
269
270
if c .Timeout .Duration == 0 {
270
271
allErrs = append (allErrs , field .Required (fldPath .Child ("timeout" ), "" ))
0 commit comments