github.com/openshift/installer@v1.4.17/pkg/asset/installconfig/vsphere/folder.go (about) 1 package vsphere 2 3 import ( 4 "context" 5 "errors" 6 "time" 7 8 "github.com/vmware/govmomi/find" 9 "k8s.io/apimachinery/pkg/util/validation/field" 10 ) 11 12 // folderExists returns an error if a folder is specified in the vSphere platform but a folder with that name is not found in the datacenter. 13 func folderExists(validationCtx *validationContext, folderPath string, fldPath *field.Path) field.ErrorList { 14 var notFoundError *find.NotFoundError 15 allErrs := field.ErrorList{} 16 finder := validationCtx.Finder 17 // If no folder is specified, skip this check as the folder will be created. 18 if folderPath == "" { 19 return allErrs 20 } 21 22 ctx, cancel := context.WithTimeout(context.TODO(), 60*time.Second) 23 defer cancel() 24 25 folder, err := finder.Folder(ctx, folderPath) 26 if err != nil && !errors.As(err, ¬FoundError) { 27 return append(allErrs, field.Invalid(fldPath, folderPath, err.Error())) 28 } 29 30 // folder was not found so no privilege check can be performed 31 if folder == nil { 32 return allErrs 33 } 34 permissionGroup := permissions[permissionFolder] 35 36 err = comparePrivileges(ctx, validationCtx, folder.Reference(), permissionGroup) 37 if err != nil { 38 return append(allErrs, field.InternalError(fldPath, err)) 39 } 40 return allErrs 41 }