Skip to content

Commit

Permalink
Add validation for empty pipeline steps (#607)
Browse files Browse the repository at this point in the history
* Add error type for pipelines without steps defined

* Add pipeline validation for empty steps in scheduler

* Fix typo referencing wrong data in error
  • Loading branch information
agrski authored Nov 22, 2022
1 parent 2ad5765 commit f5bd3f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scheduler/pkg/store/pipeline/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ func (pvm *PipelineVersionUidMismatchErr) Error() string {
return fmt.Sprintf("pipeline version uid mismatch %s:%d expected %s found %s", pvm.pipeline, pvm.version, pvm.uidExpected, pvm.uidActual)
}

type PipelineStepsEmptyErr struct {
pipeline string
}

func (psee *PipelineStepsEmptyErr) Error() string {
return fmt.Sprintf("pipeline %s has no steps defined", psee.pipeline)
}

type PipelineStepNotFoundErr struct {
pipeline string
step string
Expand Down
10 changes: 10 additions & 0 deletions scheduler/pkg/store/pipeline/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (
)

func validate(pv *PipelineVersion) error {
if err := checkStepsExist(pv); err != nil {
return err
}
if err := checkStepNameNotPipelineName(pv); err != nil {
return err
}
Expand All @@ -57,6 +60,13 @@ func validate(pv *PipelineVersion) error {
return nil
}

func checkStepsExist(pv *PipelineVersion) error {
if len(pv.Steps) == 0 {
return &PipelineStepsEmptyErr{pipeline: pv.Name}
}
return nil
}

func checkStepNameNotPipelineName(pv *PipelineVersion) error {
for _, v := range pv.Steps {
if v.Name == pv.Name {
Expand Down

0 comments on commit f5bd3f9

Please sign in to comment.