@ -476,36 +476,26 @@ func (b *APIBuilder) Validate(ctx context.Context, a admission.Attributes, o adm
}
}
targetError := b . verifyAgaintsExistingRepositories ( cfg )
if targetError != nil {
list = append ( list , targetError )
// Early exit to avoid more expensive checks if we have already found errors
if len ( list ) > 0 {
return invalidRepositoryError ( a . GetName ( ) , list )
}
// For *create* we do a synchronous test... this can be expensive!
// it is the same as a full healthcheck, so should not be run on every update
if len ( list ) == 0 && a . GetOperation ( ) == admission . Create {
testResults , err := repository . TestRepository ( ctx , repo )
if err != nil {
list = append ( list , field . Invalid ( field . NewPath ( "spec" ) ,
"Repository test failed" , "Unable to verify repository: " + err . Error ( ) ) )
}
if ! testResults . Success {
for _ , err := range testResults . Errors {
list = append ( list , field . Invalid ( field . NewPath ( "spec" ) ,
"Repository test failed" , err ) )
}
}
// Exit early if we have already found errors
targetError := b . verifyAgaintsExistingRepositories ( cfg )
if targetError != nil {
return invalidRepositoryError ( a . GetName ( ) , field . ErrorList { targetError } )
}
if len ( list ) > 0 {
return apierrors . NewInvalid (
provisioning . RepositoryResourceInfo . GroupVersionKind ( ) . GroupKind ( ) ,
a . GetName ( ) , list )
}
return nil
}
func invalidRepositoryError ( name string , list field . ErrorList ) error {
return apierrors . NewInvalid (
provisioning . RepositoryResourceInfo . GroupVersionKind ( ) . GroupKind ( ) ,
name , list )
}
// TODO: move this to a more appropriate place. Probably controller/validation.go
func ( b * APIBuilder ) verifyAgaintsExistingRepositories ( cfg * provisioning . Repository ) * field . Error {
all , err := b . repositoryLister . Repositories ( cfg . Namespace ) . List ( labels . Everything ( ) )