Skip to content

Commit

Permalink
Merge pull request kubernetes#2560 from ddysher/fix-git-volume
Browse files Browse the repository at this point in the history
gitrepo validation
  • Loading branch information
brendandburns committed Nov 24, 2014
2 parents 518115c + b5fce50 commit e82b88f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 16 additions & 4 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ func validateSource(source *api.VolumeSource) errs.ValidationErrorList {
}
if source.EmptyDir != nil {
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 {
numVolumes++
Expand All @@ -92,22 +96,30 @@ func validateHostDir(hostDir *api.HostDir) errs.ValidationErrorList {
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 {
allErrs := errs.ValidationErrorList{}
if PD.PDName == "" {
allErrs = append(allErrs, errs.NewFieldInvalid("PD.PDName", PD.PDName))
allErrs = append(allErrs, errs.NewFieldRequired("PD.PDName", PD.PDName))
}
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 {
allErrs = append(allErrs, errs.NewFieldInvalid("PD.Partition", PD.Partition))
}
return allErrs
}

var supportedPortProtocols = util.NewStringSet(string(api.ProtocolTCP), string(api.ProtocolUDP))

func validatePorts(ports []api.Port) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}

Expand Down
3 changes: 2 additions & 1 deletion pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ func TestValidateVolumes(t *testing.T) {
{Name: "abc-123", Source: &api.VolumeSource{HostDir: &api.HostDir{"/mnt/path3"}}},
{Name: "empty", Source: &api.VolumeSource{EmptyDir: &api.EmptyDir{}}},
{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)
if len(errs) != 0 {
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)
}

Expand Down

0 comments on commit e82b88f

Please sign in to comment.