Skip to content

Commit

Permalink
refactoring schema errors
Browse files Browse the repository at this point in the history
Signed-off-by: Jaydip Gabani <[email protected]>
  • Loading branch information
JaydipGabani committed Jul 2, 2024
1 parent e11e1b0 commit edcb5a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 4 additions & 0 deletions constraint/pkg/client/drivers/k8scel/schema/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ var (
ErrBadMatchCondition = errors.New("invalid match condition")
ErrBadVariable = errors.New("invalid variable definition")
ErrBadFailurePolicy = errors.New("invalid failure policy")
ErrCodeNotDefined = errors.New("K8sNativeValidation code not defined")
ErrOneTargetAllowed = errors.New("wrong number of targets defined, only 1 target allowed")
ErrBadType = errors.New("Could not recognize the type")
ErrMissingField = errors.New("K8sNativeValidation source missing required field")
)
10 changes: 2 additions & 8 deletions constraint/pkg/client/drivers/k8scel/schema/schema.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package schema

import (
"errors"
"fmt"
"strings"

Expand All @@ -26,11 +25,6 @@ const (
ObjectName = "anyObject"
)

var (
ErrBadType = errors.New("Could not recognize the type")
ErrMissingField = errors.New("K8sNativeValidation source missing required field")
)

type Validation struct {
// A CEL expression. Maps to ValidationAdmissionPolicy's `spec.validations`.
Expression string `json:"expression,omitempty"`
Expand Down Expand Up @@ -278,7 +272,7 @@ func GetSource(code templates.Code) (*Source, error) {

func GetSourceFromTemplate(ct *templates.ConstraintTemplate) (*Source, error) {
if len(ct.Spec.Targets) != 1 {
return nil, errors.New("wrong number of targets defined, only 1 target allowed")
return nil, ErrOneTargetAllowed
}

var source *Source
Expand All @@ -294,7 +288,7 @@ func GetSourceFromTemplate(ct *templates.ConstraintTemplate) (*Source, error) {
break
}
if source == nil {
return nil, errors.New("K8sNativeValidation code not defined")
return nil, ErrCodeNotDefined
}
return source, nil
}

0 comments on commit edcb5a3

Please sign in to comment.