Skip to content

Commit

Permalink
Do not use semver library for repo index (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
alenkacz authored and kensipe committed Jul 9, 2019
1 parent ebadcd4 commit 4cf6a31
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
31 changes: 4 additions & 27 deletions pkg/kudoctl/util/repo/repo_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,41 +78,18 @@ func parseIndexFile(data []byte) (*IndexFile, error) {
return i, nil
}

// GetByName returns operator of given name.
func (i IndexFile) GetByName(name string) (*BundleVersion, error) {
constraint, err := semver.NewConstraint("*")
if err != nil {
return nil, err
}

return i.getOperator(name, constraint)
}

// GetByNameAndVersion returns the operator of given name and version.
// When no specific version required, submit version as empty string - ""
func (i IndexFile) GetByNameAndVersion(name, version string) (*BundleVersion, error) {
constraint, err := semver.NewConstraint(version)
if err != nil {
return nil, err
}

return i.getOperator(name, constraint)
}

func (i IndexFile) getOperator(name string, versionConstraint *semver.Constraints) (*BundleVersion, error) {
vs, ok := i.Entries[name]
if !ok || len(vs) == 0 {
return nil, fmt.Errorf("no operator of given name %s and version %v found", name, versionConstraint)
return nil, fmt.Errorf("no operator of given name %s", name)
}

for _, ver := range vs {
test, err := semver.NewVersion(ver.Version)
if err != nil {
continue
}

if versionConstraint.Check(test) {
if ver.Version == version || version == "" {
return ver, nil
}
}
return nil, fmt.Errorf("no operator version found for %s-%v", name, versionConstraint)
return nil, fmt.Errorf("no operator version found for %s-%v", name, version)
}
2 changes: 1 addition & 1 deletion pkg/kudoctl/util/repo/repo_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (r *OperatorRepository) GetPackageReader(name string, version string) (io.R
var bundleVersion *BundleVersion

if version == "" {
bv, err := indexFile.GetByName(name)
bv, err := indexFile.GetByNameAndVersion(name, "")
if err != nil {
return nil, errors.Wrapf(err, "getting %s in index file", name)
}
Expand Down

0 comments on commit 4cf6a31

Please sign in to comment.