From 78f81921fc6f8943e925664ab52227d1a70f8dd7 Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Sat, 2 Nov 2019 12:51:01 -0400 Subject: [PATCH] feat(operator): remove another location that parses csvs --- pkg/controller/registry/resolver/operators.go | 20 +++++-------------- .../registry/resolver/operators_test.go | 8 +++++--- pkg/controller/registry/resolver/util_test.go | 1 + 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/pkg/controller/registry/resolver/operators.go b/pkg/controller/registry/resolver/operators.go index 203b8043c18..aa76b7ddfc5 100644 --- a/pkg/controller/registry/resolver/operators.go +++ b/pkg/controller/registry/resolver/operators.go @@ -1,7 +1,6 @@ package resolver import ( - "encoding/json" "fmt" "hash/fnv" "sort" @@ -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 := ®istry.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{} @@ -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, diff --git a/pkg/controller/registry/resolver/operators_test.go b/pkg/controller/registry/resolver/operators_test.go index c0adf29174e..23dd5175d5f 100644 --- a/pkg/controller/registry/resolver/operators_test.go +++ b/pkg/controller/registry/resolver/operators_test.go @@ -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)}, } @@ -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{ @@ -1038,7 +1040,7 @@ func TestNewOperatorFromBundle(t *testing.T) { replaces: "", }, want: &Operator{ - name: "testCSV", + name: "testBundle", version: &version.Version, providedAPIs: EmptyAPISet(), requiredAPIs: EmptyAPISet(), @@ -1058,7 +1060,7 @@ func TestNewOperatorFromBundle(t *testing.T) { replaces: "", }, want: &Operator{ - name: "testCSV", + name: "testBundle", version: &version.Version, providedAPIs: APISet{ opregistry.APIKey{ @@ -1104,7 +1106,7 @@ func TestNewOperatorFromBundle(t *testing.T) { replaces: "replaced", }, want: &Operator{ - name: "testCSV", + name: "testBundle", providedAPIs: EmptyAPISet(), requiredAPIs: EmptyAPISet(), bundle: bundleNoAPIs, diff --git a/pkg/controller/registry/resolver/util_test.go b/pkg/controller/registry/resolver/util_test.go index aa6b3569d35..1ce57ae92d1 100644 --- a/pkg/controller/registry/resolver/util_test.go +++ b/pkg/controller/registry/resolver/util_test.go @@ -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), }