Skip to content

Commit

Permalink
feat(resolver): rely on info from catalog to determine updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ecordell committed Nov 1, 2019
1 parent a6e1e93 commit 3767ae1
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 112 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ require (
)

replace (

github.com/openshift/api => github.com/openshift/api v3.9.1-0.20190924102528-32369d4db2ad+incompatible
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20190923180330-3b6373338c9b
github.com/operator-framework/operator-registry => ../operator-registry

// Pin to kube 1.16
k8s.io/api => k8s.io/api v0.0.0-20190918155943-95b840bb6a1f
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/registry/resolver/evolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ func (e *NamespaceGenerationEvolver) checkForUpdates() error {
continue
}

o, err := NewOperatorFromBundle(bundle, op.Identifier(), op.SourceInfo().StartingCSV, *key)
o, err := NewOperatorFromBundle(bundle, op.SourceInfo().StartingCSV, *key)
if err != nil {
return errors.Wrap(err, "error parsing bundle")
}
o.SetReplaces(op.Identifier())
if err := e.gen.AddOperator(o); err != nil {
return errors.Wrap(err, "error calculating generation changes due to new bundle")
}
Expand All @@ -90,7 +91,7 @@ func (e *NamespaceGenerationEvolver) addNewOperators(add map[OperatorSourceInfo]
return errors.Wrapf(err, "%s not found", s)
}

o, err := NewOperatorFromBundle(bundle, "", s.StartingCSV, *key)
o, err := NewOperatorFromBundle(bundle, s.StartingCSV, *key)
if err != nil {
return errors.Wrap(err, "error parsing bundle")
}
Expand Down Expand Up @@ -123,7 +124,7 @@ func (e *NamespaceGenerationEvolver) queryForRequiredAPIs() error {
// attempt to find a bundle that provides that api
if bundle, key, err := e.querier.FindProvider(*api, initialSource); err == nil {
// add a bundle that provides the api to the generation
o, err := NewOperatorFromBundle(bundle, "", "", *key)
o, err := NewOperatorFromBundle(bundle, "", *key)
if err != nil {
return errors.Wrap(err, "error parsing bundle")
}
Expand Down
12 changes: 5 additions & 7 deletions pkg/controller/registry/resolver/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,14 @@ type Operator struct {

var _ OperatorSurface = &Operator{}

func NewOperatorFromBundle(bundle *api.Bundle, replaces string, startingCSV string, sourceKey CatalogKey) (*Operator, error) {
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
}
r := replaces
if r == "" {
r, _ = csv.GetReplaces()
}

version, _ := csv.GetVersion()
parsedVersion, err := semver.ParseTolerant(version)
Expand All @@ -269,7 +265,6 @@ func NewOperatorFromBundle(bundle *api.Bundle, replaces string, startingCSV stri

return &Operator{
name: csv.GetName(),
replaces: r,
version: v,
providedAPIs: provided,
requiredAPIs: required,
Expand Down Expand Up @@ -311,7 +306,6 @@ func NewOperatorFromV1Alpha1CSV(csv *v1alpha1.ClusterServiceVersion) (*Operator,
return &Operator{
name: csv.GetName(),
version: &csv.Spec.Version.Version,
replaces: csv.Spec.Replaces,
providedAPIs: providedAPIs,
requiredAPIs: requiredAPIs,
sourceInfo: &ExistingOperator,
Expand All @@ -334,6 +328,10 @@ func (o *Operator) Replaces() string {
return o.replaces
}

func (o *Operator) SetReplaces(replacing string) {
o.replaces = replacing
}

func (o *Operator) Package() string {
return o.bundle.PackageName
}
Expand Down
9 changes: 3 additions & 6 deletions pkg/controller/registry/resolver/operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,6 @@ func TestNewOperatorFromBundle(t *testing.T) {
want: &Operator{
name: "testCSV",
version: &version.Version,
replaces: "v1",
providedAPIs: EmptyAPISet(),
requiredAPIs: EmptyAPISet(),
bundle: bundleNoAPIs,
Expand All @@ -1059,9 +1058,8 @@ func TestNewOperatorFromBundle(t *testing.T) {
replaces: "",
},
want: &Operator{
name: "testCSV",
version: &version.Version,
replaces: "v1",
name: "testCSV",
version: &version.Version,
providedAPIs: APISet{
opregistry.APIKey{
Group: "crd.group.com",
Expand Down Expand Up @@ -1110,7 +1108,6 @@ func TestNewOperatorFromBundle(t *testing.T) {
providedAPIs: EmptyAPISet(),
requiredAPIs: EmptyAPISet(),
bundle: bundleNoAPIs,
replaces: "replaced",
version: &version.Version,
sourceInfo: &OperatorSourceInfo{
Package: "testPackage",
Expand All @@ -1122,7 +1119,7 @@ func TestNewOperatorFromBundle(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewOperatorFromBundle(tt.args.bundle, tt.args.replaces, "", tt.args.sourceKey)
got, err := NewOperatorFromBundle(tt.args.bundle, "", tt.args.sourceKey)
require.Equal(t, tt.wantErr, err)
require.Equal(t, tt.want, got)
})
Expand Down
18 changes: 2 additions & 16 deletions pkg/controller/registry/resolver/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ package resolver
import (
"context"
"fmt"
"strings"

"github.com/blang/semver"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/yaml"

"github.com/operator-framework/operator-registry/pkg/api"
"github.com/operator-framework/operator-registry/pkg/client"
Expand Down Expand Up @@ -180,22 +177,11 @@ func (q *NamespaceSourceQuerier) findChannelHead(currentVersion *semver.Version,
return nil, err
}

if latest.CsvJson == "" {
if latest.SkipRange == "" {
return nil, nil
}

dec := yaml.NewYAMLOrJSONDecoder(strings.NewReader(latest.CsvJson), 10)
unst := &unstructured.Unstructured{}
if err := dec.Decode(unst); err != nil {
return nil, err
}

skipRange, ok := unst.GetAnnotations()[SkipPackageAnnotationKey]
if !ok {
return nil, nil
}

r, err := semver.ParseRange(skipRange)
r, err := semver.ParseRange(latest.SkipRange)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/registry/resolver/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func TestNamespaceSourceQuerier_FindReplacement(t *testing.T) {
require.NoError(t, err)

nextBundle := &api.Bundle{CsvName: "test.v1", PackageName: "testPkg", ChannelName: "testChannel"}
latestBundle := &api.Bundle{CsvName: "latest", PackageName: "testPkg", ChannelName: "testChannel", CsvJson: string(csvJson), Object: []string{string(csvJson)}}
latestBundle := &api.Bundle{CsvName: "latest", PackageName: "testPkg", ChannelName: "testChannel", CsvJson: string(csvJson), Object: []string{string(csvJson)}, SkipRange: ">= 1.0.0-0 < 1.0.0-1556661308", Version: latestVersion.String()}

csv.SetAnnotations(map[string]string{})
csvUnstNoAnnotationJson, err := json.Marshal(csv)
Expand Down Expand Up @@ -491,7 +491,7 @@ func TestNamespaceSourceQuerier_FindReplacement(t *testing.T) {
if err != nil {
t.Log(err.Error())
}
require.Equal(t, tt.out.err, err)
require.Equal(t, tt.out.err, err, "%v", err)
require.Equal(t, tt.out.bundle, got)
require.Equal(t, tt.out.key, key)
})
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3767ae1

Please sign in to comment.