mirror of https://github.com/k3s-io/k3s
gitrepo validation
parent
162e4983b9
commit
b5fce5021f
|
@ -72,7 +72,11 @@ func validateSource(source *api.VolumeSource) errs.ValidationErrorList {
|
||||||
}
|
}
|
||||||
if source.EmptyDir != nil {
|
if source.EmptyDir != nil {
|
||||||
numVolumes++
|
numVolumes++
|
||||||
//EmptyDirs have nothing to validate
|
// EmptyDirs have nothing to validate
|
||||||
|
}
|
||||||
|
if source.GitRepo != nil {
|
||||||
|
numVolumes++
|
||||||
|
allErrs = append(allErrs, validateGitRepo(source.GitRepo)...)
|
||||||
}
|
}
|
||||||
if source.GCEPersistentDisk != nil {
|
if source.GCEPersistentDisk != nil {
|
||||||
numVolumes++
|
numVolumes++
|
||||||
|
@ -92,15 +96,21 @@ func validateHostDir(hostDir *api.HostDir) errs.ValidationErrorList {
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
var supportedPortProtocols = util.NewStringSet(string(api.ProtocolTCP), string(api.ProtocolUDP))
|
func validateGitRepo(gitRepo *api.GitRepo) errs.ValidationErrorList {
|
||||||
|
allErrs := errs.ValidationErrorList{}
|
||||||
|
if gitRepo.Repository == "" {
|
||||||
|
allErrs = append(allErrs, errs.NewFieldRequired("gitRepo.Repository", gitRepo.Repository))
|
||||||
|
}
|
||||||
|
return allErrs
|
||||||
|
}
|
||||||
|
|
||||||
func validateGCEPersistentDisk(PD *api.GCEPersistentDisk) errs.ValidationErrorList {
|
func validateGCEPersistentDisk(PD *api.GCEPersistentDisk) errs.ValidationErrorList {
|
||||||
allErrs := errs.ValidationErrorList{}
|
allErrs := errs.ValidationErrorList{}
|
||||||
if PD.PDName == "" {
|
if PD.PDName == "" {
|
||||||
allErrs = append(allErrs, errs.NewFieldInvalid("PD.PDName", PD.PDName))
|
allErrs = append(allErrs, errs.NewFieldRequired("PD.PDName", PD.PDName))
|
||||||
}
|
}
|
||||||
if PD.FSType == "" {
|
if PD.FSType == "" {
|
||||||
allErrs = append(allErrs, errs.NewFieldInvalid("PD.FSType", PD.FSType))
|
allErrs = append(allErrs, errs.NewFieldRequired("PD.FSType", PD.FSType))
|
||||||
}
|
}
|
||||||
if PD.Partition < 0 || PD.Partition > 255 {
|
if PD.Partition < 0 || PD.Partition > 255 {
|
||||||
allErrs = append(allErrs, errs.NewFieldInvalid("PD.Partition", PD.Partition))
|
allErrs = append(allErrs, errs.NewFieldInvalid("PD.Partition", PD.Partition))
|
||||||
|
@ -108,6 +118,8 @@ func validateGCEPersistentDisk(PD *api.GCEPersistentDisk) errs.ValidationErrorLi
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var supportedPortProtocols = util.NewStringSet(string(api.ProtocolTCP), string(api.ProtocolUDP))
|
||||||
|
|
||||||
func validatePorts(ports []api.Port) errs.ValidationErrorList {
|
func validatePorts(ports []api.Port) errs.ValidationErrorList {
|
||||||
allErrs := errs.ValidationErrorList{}
|
allErrs := errs.ValidationErrorList{}
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,13 @@ func TestValidateVolumes(t *testing.T) {
|
||||||
{Name: "abc-123", Source: &api.VolumeSource{HostDir: &api.HostDir{"/mnt/path3"}}},
|
{Name: "abc-123", Source: &api.VolumeSource{HostDir: &api.HostDir{"/mnt/path3"}}},
|
||||||
{Name: "empty", Source: &api.VolumeSource{EmptyDir: &api.EmptyDir{}}},
|
{Name: "empty", Source: &api.VolumeSource{EmptyDir: &api.EmptyDir{}}},
|
||||||
{Name: "gcepd", Source: &api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDisk{"my-PD", "ext4", 1, false}}},
|
{Name: "gcepd", Source: &api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDisk{"my-PD", "ext4", 1, false}}},
|
||||||
|
{Name: "gitrepo", Source: &api.VolumeSource{GitRepo: &api.GitRepo{"my-repo", "hashstring"}}},
|
||||||
}
|
}
|
||||||
names, errs := validateVolumes(successCase)
|
names, errs := validateVolumes(successCase)
|
||||||
if len(errs) != 0 {
|
if len(errs) != 0 {
|
||||||
t.Errorf("expected success: %v", errs)
|
t.Errorf("expected success: %v", errs)
|
||||||
}
|
}
|
||||||
if len(names) != 5 || !names.HasAll("abc", "123", "abc-123", "empty", "gcepd") {
|
if len(names) != 6 || !names.HasAll("abc", "123", "abc-123", "empty", "gcepd", "gitrepo") {
|
||||||
t.Errorf("wrong names result: %v", names)
|
t.Errorf("wrong names result: %v", names)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue