Skip to content

Commit

Permalink
Merge pull request #63 from gallettilance/validation
Browse files Browse the repository at this point in the history
Bug 1879640: (fix) csv name should not be constrained
  • Loading branch information
gallettilance authored Sep 16, 2020
2 parents e29d40c + ac17712 commit 329d62c
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions pkg/validation/internal/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/operator-framework/api/pkg/validation/errors"
interfaces "github.com/operator-framework/api/pkg/validation/interfaces"

"github.com/blang/semver"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -33,11 +32,11 @@ func validateCSVs(objs ...interface{}) (results []errors.ManifestResult) {
func validateCSV(csv *v1alpha1.ClusterServiceVersion) errors.ManifestResult {
result := errors.ManifestResult{Name: csv.GetName()}
// Ensure CSV names are of the correct format.
if _, _, err := parseCSVNameFormat(csv.GetName()); err != (errors.Error{}) {
if err := parseCSVNameFormat(csv.GetName()); err != (errors.Error{}) {
result.Add(errors.ErrInvalidCSV(fmt.Sprintf("metadata.name %s", err), csv.GetName()))
}
if replaces := csv.Spec.Replaces; replaces != "" {
if _, _, err := parseCSVNameFormat(replaces); err != (errors.Error{}) {
if err := parseCSVNameFormat(replaces); err != (errors.Error{}) {
result.Add(errors.ErrInvalidCSV(fmt.Sprintf("spec.replaces %s", err), csv.GetName()))
}
}
Expand All @@ -50,20 +49,11 @@ func validateCSV(csv *v1alpha1.ClusterServiceVersion) errors.ManifestResult {
return result
}

func parseCSVNameFormat(name string) (string, semver.Version, error) {
func parseCSVNameFormat(name string) error {
if violations := k8svalidation.IsDNS1123Subdomain(name); len(violations) != 0 {
return "", semver.Version{}, fmt.Errorf("%q is invalid:\n%s", name, violations)
return fmt.Errorf("%q is invalid:\n%s", name, violations)
}
splitName := strings.SplitN(name, ".", 2)
if len(splitName) != 2 {
return "", semver.Version{}, fmt.Errorf("%q must have format: {operator name}.(v)X.Y.Z", name)
}
verStr := strings.TrimLeft(splitName[1], "v")
nameVer, err := semver.Parse(verStr)
if err != nil {
return "", semver.Version{}, fmt.Errorf("%q contains an invalid semver %q", name, splitName[1])
}
return splitName[0], nameVer, errors.Error{}
return errors.Error{}
}

// checkFields runs checkEmptyFields and returns its errors.
Expand Down

0 comments on commit 329d62c

Please sign in to comment.