Skip to content

Commit

Permalink
Merge branch 'master' into catsrc_weighting
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhxuanvu authored Aug 5, 2020
2 parents b029c95 + 163608d commit d0b2fe9
Show file tree
Hide file tree
Showing 17 changed files with 664 additions and 204 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/openshift/api v0.0.0-20200331152225-585af27e34fd
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0
github.com/operator-framework/api v0.3.11
github.com/operator-framework/operator-registry v1.13.3
github.com/operator-framework/operator-registry v1.13.6
github.com/otiai10/copy v1.2.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJ
github.com/operator-framework/api v0.3.7-0.20200602203552-431198de9fc2/go.mod h1:Xbje9x0SHmh0nihE21kpesB38vk3cyxnE6JdDS8Jo1Q=
github.com/operator-framework/api v0.3.11 h1:+fyck2pcr+vVGnVxM4UNoi7qOSMVCTQOWW2xsJtLSq0=
github.com/operator-framework/api v0.3.11/go.mod h1:Xbje9x0SHmh0nihE21kpesB38vk3cyxnE6JdDS8Jo1Q=
github.com/operator-framework/operator-registry v1.13.3 h1:SaZ1IKLKGizVgTtT8AlDgaMXFYOiIPxRf8KLve0/DXM=
github.com/operator-framework/operator-registry v1.13.3/go.mod h1:YhnIzOVjRU2ZwZtzt+fjcjW8ujJaSFynBEu7QVKaSdU=
github.com/operator-framework/operator-registry v1.13.6 h1:h/dIjQQS7uneQNRifrSz7h0xg4Xyjg6C9f6XZofbMPg=
github.com/operator-framework/operator-registry v1.13.6/go.mod h1:YhnIzOVjRU2ZwZtzt+fjcjW8ujJaSFynBEu7QVKaSdU=
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
Expand Down
33 changes: 33 additions & 0 deletions pkg/controller/registry/resolver/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ type OperatorPredicate func(*Operator) bool
func (s *CatalogSnapshot) Find(p ...OperatorPredicate) []*Operator {
s.m.RLock()
defer s.m.RUnlock()
if len(p) > 0 {
p = append(p, WithoutDeprecatedProperty())
}
return Filter(s.operators, p...)
}

Expand Down Expand Up @@ -437,12 +440,42 @@ func WithPackage(pkg string) OperatorPredicate {
}
}

func WithoutDeprecatedProperty() OperatorPredicate {
return func(o *Operator) bool {
for _, p := range o.bundle.GetProperties() {
if p.GetType() == string(opregistry.DeprecatedType) {
return false
}
}
return true
}
}

func WithVersionInRange(r semver.Range) OperatorPredicate {
return func(o *Operator) bool {
return o.version != nil && r(*o.version)
}
}

func WithLabel(label string) OperatorPredicate {
return func(o *Operator) bool {
for _, p := range o.Properties() {
if p.Type != opregistry.LabelType {
continue
}
var prop opregistry.LabelProperty
err := json.Unmarshal([]byte(p.Value), &prop)
if err != nil {
continue
}
if prop.Label == label {
return true
}
}
return false
}
}

func ProvidingAPI(api opregistry.APIKey) OperatorPredicate {
return func(o *Operator) bool {
for _, p := range o.Properties() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/registry/resolver/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func TestStripPluralRequiredAndProvidedAPIKeys(t *testing.T) {
Kind: "K",
Plural: "ks",
}: {},
}, nil),
}, nil, false),
Dependencies: apiSetToDependencies(map[opregistry.APIKey]struct{}{
{
Group: "g2",
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/registry/resolver/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ func PredicateForDependency(dependency *api.Dependency) (OperatorPredicate, erro
var predicates = map[string]func(string) (OperatorPredicate, error){
opregistry.GVKType: predicateForGVKDependency,
opregistry.PackageType: predicateForPackageDependency,
opregistry.LabelType: predicateForLabelDependency,
}

func predicateForGVKDependency(value string) (OperatorPredicate, error) {
Expand Down Expand Up @@ -470,6 +471,15 @@ func predicateForPackageDependency(value string) (OperatorPredicate, error) {
return And(WithPackage(pkg.PackageName), WithVersionInRange(ver)), nil
}

func predicateForLabelDependency(value string) (OperatorPredicate, error) {
var label opregistry.LabelDependency
if err := json.Unmarshal([]byte(value), &label); err != nil {
return nil, err
}

return WithLabel(label.Label), nil
}

func apisToDependencies(apis APISet) (out []*api.Dependency, err error) {
if len(apis) == 0 {
return
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/registry/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func (r *SatResolver) getBundleInstallables(catalog registry.CatalogKey, predica
errs = append(errs, err)
continue
}

for _, d := range dependencyPredicates {
// errors ignored; this will build an empty/unsatisfiable dependency if no candidates are found
candidateBundles, _ := AtLeast(1, namespacedCache.FindPreferred(&bundle.sourceInfo.Catalog, d))
Expand Down
414 changes: 285 additions & 129 deletions pkg/controller/registry/resolver/resolver_test.go

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions pkg/controller/registry/resolver/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func apiSetToDependencies(crds, apis APISet) (out []*api.Dependency) {
return
}

func apiSetToProperties(crds, apis APISet) (out []*api.Property) {
func apiSetToProperties(crds, apis APISet, deprecated bool) (out []*api.Property) {
out = make([]*api.Property, 0)
for a := range crds {
val, err := json.Marshal(opregistry.GVKProperty{
Expand Down Expand Up @@ -245,6 +245,16 @@ func apiSetToProperties(crds, apis APISet) (out []*api.Property) {
Value: string(val),
})
}
if deprecated {
val, err := json.Marshal(opregistry.DeprecatedProperty{})
if err != nil {
panic(err)
}
out = append(out, &api.Property{
Type: opregistry.DeprecatedType,
Value: string(val),
})
}
if len(out) == 0 {
return nil
}
Expand Down Expand Up @@ -297,7 +307,7 @@ func bundle(name, pkg, channel, replaces string, providedCRDs, requiredCRDs, pro
RequiredApis: apiSetToGVK(requiredCRDs, requiredAPIServices),
Replaces: replaces,
Dependencies: apiSetToDependencies(requiredCRDs, requiredAPIServices),
Properties: apiSetToProperties(providedCRDs, providedAPIServices),
Properties: apiSetToProperties(providedCRDs, providedAPIServices, false),
}
for _, f := range opts {
f(b)
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/installplan_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"errors"
"fmt"
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
"strings"
"sync"
"time"

"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"

"github.com/blang/semver"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
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.

Loading

0 comments on commit d0b2fe9

Please sign in to comment.