...
1
16
17 package validation
18
19 import (
20 "errors"
21 "path/filepath"
22 "strings"
23
24 "k8s.io/apimachinery/pkg/util/validation/field"
25 api "k8s.io/kubernetes/pkg/apis/core"
26 )
27
28
29
30 func ValidatePersistentVolume(pv *api.PersistentVolume) field.ErrorList {
31 return checkMountOption(pv)
32 }
33
34 func checkMountOption(pv *api.PersistentVolume) field.ErrorList {
35 allErrs := field.ErrorList{}
36
37
38 if pv.Spec.GCEPersistentDisk != nil ||
39 pv.Spec.AWSElasticBlockStore != nil ||
40 pv.Spec.Glusterfs != nil ||
41 pv.Spec.NFS != nil ||
42 pv.Spec.RBD != nil ||
43 pv.Spec.Quobyte != nil ||
44 pv.Spec.ISCSI != nil ||
45 pv.Spec.Cinder != nil ||
46 pv.Spec.CephFS != nil ||
47 pv.Spec.AzureFile != nil ||
48 pv.Spec.VsphereVolume != nil ||
49 pv.Spec.AzureDisk != nil ||
50 pv.Spec.PhotonPersistentDisk != nil {
51 return allErrs
52 }
53
54 if _, ok := pv.Annotations[api.MountOptionAnnotation]; ok {
55 metaField := field.NewPath("metadata")
56 allErrs = append(allErrs, field.Forbidden(metaField.Child("annotations", api.MountOptionAnnotation), "may not specify mount options for this volume type"))
57 }
58 return allErrs
59 }
60
61
62 func ValidatePathNoBacksteps(targetPath string) error {
63 parts := strings.Split(filepath.ToSlash(targetPath), "/")
64 for _, item := range parts {
65 if item == ".." {
66 return errors.New("must not contain '..'")
67 }
68 }
69
70 return nil
71 }
72
View as plain text