Skip to content

Commit

Permalink
feat(operator): remove another location that parses csvs
Browse files Browse the repository at this point in the history
  • Loading branch information
ecordell committed Nov 6, 2019
1 parent c159d94 commit 78f8192
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
20 changes: 5 additions & 15 deletions pkg/controller/registry/resolver/operators.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package resolver

import (
"encoding/json"
"fmt"
"hash/fnv"
"sort"
Expand Down Expand Up @@ -239,19 +238,10 @@ type Operator struct {
var _ OperatorSurface = &Operator{}

func NewOperatorFromBundle(bundle *api.Bundle, startingCSV string, sourceKey CatalogKey) (*Operator, error) {
if bundle.CsvJson == "" {
return nil, fmt.Errorf("no csv json found")
}
csv := &registry.ClusterServiceVersion{}
if err := json.Unmarshal([]byte(bundle.CsvJson), csv); err != nil {
return nil, err
}

version, _ := csv.GetVersion()
parsedVersion, err := semver.ParseTolerant(version)
v := &parsedVersion
parsedVersion, err := semver.ParseTolerant(bundle.Version)
version := &parsedVersion
if err != nil {
v = nil
version = nil
}

provided := APISet{}
Expand All @@ -264,8 +254,8 @@ func NewOperatorFromBundle(bundle *api.Bundle, startingCSV string, sourceKey Cat
}

return &Operator{
name: csv.GetName(),
version: v,
name: bundle.CsvName,
version: version,
providedAPIs: provided,
requiredAPIs: required,
bundle: bundle,
Expand Down
8 changes: 5 additions & 3 deletions pkg/controller/registry/resolver/operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ func TestNewOperatorFromBundle(t *testing.T) {
CsvName: "testBundle",
PackageName: "testPackage",
ChannelName: "testChannel",
Version: version.String(),
CsvJson: string(csvJson),
Object: []string{string(csvJson)},
}
Expand Down Expand Up @@ -987,6 +988,7 @@ func TestNewOperatorFromBundle(t *testing.T) {
CsvName: "testBundle",
PackageName: "testPackage",
ChannelName: "testChannel",
Version: version.String(),
CsvJson: string(csvJsonWithApis),
Object: []string{string(csvJsonWithApis), string(crdJson)},
ProvidedApis: []*api.GroupVersionKind{
Expand Down Expand Up @@ -1038,7 +1040,7 @@ func TestNewOperatorFromBundle(t *testing.T) {
replaces: "",
},
want: &Operator{
name: "testCSV",
name: "testBundle",
version: &version.Version,
providedAPIs: EmptyAPISet(),
requiredAPIs: EmptyAPISet(),
Expand All @@ -1058,7 +1060,7 @@ func TestNewOperatorFromBundle(t *testing.T) {
replaces: "",
},
want: &Operator{
name: "testCSV",
name: "testBundle",
version: &version.Version,
providedAPIs: APISet{
opregistry.APIKey{
Expand Down Expand Up @@ -1104,7 +1106,7 @@ func TestNewOperatorFromBundle(t *testing.T) {
replaces: "replaced",
},
want: &Operator{
name: "testCSV",
name: "testBundle",
providedAPIs: EmptyAPISet(),
requiredAPIs: EmptyAPISet(),
bundle: bundleNoAPIs,
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/registry/resolver/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func bundle(name, pkg, channel, replaces string, providedCRDs, requiredCRDs, pro
ChannelName: channel,
CsvJson: string(csvJson),
Object: objs,
Version: "0.0.0",
ProvidedApis: apiSetToGVk(providedCRDs, providedAPIServices),
RequiredApis: apiSetToGVk(requiredCRDs, requiredAPIServices),
}
Expand Down

0 comments on commit 78f8192

Please sign in to comment.