Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support semver ranges of versions to skip in the head of a channel #834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ codegen:
cp scripts/generate_internal_groups.sh vendor/k8s.io/code-generator/generate_internal_groups.sh
mkdir -p vendor/k8s.io/code-generator/hack
cp boilerplate.go.txt vendor/k8s.io/code-generator/hack/boilerplate.go.txt
go run vendor/k8s.io/kube-openapi/cmd/openapi-gen/openapi-gen.go --logtostderr -i ./vendor/k8s.io/apimachinery/pkg/runtime,./vendor/k8s.io/apimachinery/pkg/apis/meta/v1,./vendor/k8s.io/apimachinery/pkg/version,./pkg/package-server/apis/operators/v1,./pkg/package-server/apis/apps/v1alpha1,./pkg/api/apis/operators/v1alpha1 -p $(PKG)/pkg/package-server/apis/openapi -O zz_generated.openapi -h boilerplate.go.txt -r /dev/null
go run vendor/k8s.io/kube-openapi/cmd/openapi-gen/openapi-gen.go --logtostderr -i ./vendor/k8s.io/apimachinery/pkg/runtime,./vendor/k8s.io/apimachinery/pkg/apis/meta/v1,./vendor/k8s.io/apimachinery/pkg/version,./pkg/package-server/apis/operators/v1,./pkg/package-server/apis/apps/v1alpha1,./pkg/api/apis/operators/v1alpha1,./pkg/lib/version -p $(PKG)/pkg/package-server/apis/openapi -O zz_generated.openapi -h boilerplate.go.txt -r /dev/null
$(CODEGEN) all $(PKG)/pkg/api/client $(PKG)/pkg/api/apis "operators:v1alpha1,v1"
$(CODEGEN_INTERNAL) all $(PKG)/pkg/package-server/client $(PKG)/pkg/package-server/apis $(PKG)/pkg/package-server/apis "operators:v1 apps:v1alpha1"

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.12

require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/blang/semver v3.5.1+incompatible
github.com/coreos/etcd v3.3.12+incompatible // indirect
github.com/coreos/go-semver v0.2.0
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e // indirect
Expand Down Expand Up @@ -38,6 +39,7 @@ require (
github.com/sirupsen/logrus v1.4.1
github.com/spf13/cobra v0.0.3
github.com/stretchr/testify v1.2.2
go.uber.org/zap v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5 // indirect
golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzs
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
Expand Down Expand Up @@ -266,6 +268,8 @@ go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181015023909-0c41d7ab0a0e/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"fmt"
"sort"

"github.com/coreos/go-semver/semver"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/version"
)

const (
Expand Down Expand Up @@ -136,7 +137,7 @@ type APIServiceDefinitions struct {
// that can manage apps for a given version.
type ClusterServiceVersionSpec struct {
InstallStrategy NamedInstallStrategy `json:"install"`
Version semver.Version `json:"version,omitempty"`
Version version.OperatorVersion `json:"version,omitempty"`
Maturity string `json:"maturity,omitempty"`
CustomResourceDefinitions CustomResourceDefinitions `json:"customresourcedefinitions,omitempty"`
APIServiceDefinitions APIServiceDefinitions `json:"apiservicedefinitions,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/apis/operators/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha
return sub, false, nil
}

_, err := o.client.OperatorsV1alpha1().ClusterServiceVersions(sub.GetNamespace()).Get(sub.Status.CurrentCSV, metav1.GetOptions{})
csv, err := o.client.OperatorsV1alpha1().ClusterServiceVersions(sub.GetNamespace()).Get(sub.Status.CurrentCSV, metav1.GetOptions{})
out := sub.DeepCopy()
if err != nil {
logger.WithError(err).WithField("currentCSV", sub.Status.CurrentCSV).Debug("error fetching csv listed in subscription status")
Expand All @@ -789,7 +789,7 @@ func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha
if err := querier.Queryable(); err != nil {
return nil, false, err
}
bundle, _, _ := querier.FindReplacement(sub.Status.CurrentCSV, sub.Spec.Package, sub.Spec.Channel, resolver.CatalogKey{sub.Spec.CatalogSource, sub.Spec.CatalogSourceNamespace})
bundle, _, _ := querier.FindReplacement(&csv.Spec.Version.Version, sub.Status.CurrentCSV, sub.Spec.Package, sub.Spec.Channel, resolver.CatalogKey{sub.Spec.CatalogSource, sub.Spec.CatalogSourceNamespace})
if bundle != nil {
out.Status.State = v1alpha1.SubscriptionStateUpgradeAvailable
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
return
}

operatorSurface, err := resolver.NewOperatorFromCSV(out)
operatorSurface, err := resolver.NewOperatorFromV1Alpha1CSV(out)
if err != nil {
// TODO: Add failure status to CSV
syncError = err
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/operators/olm/operatorgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (a *Operator) providedAPIsFromCSVs(group *v1.OperatorGroup, logger *logrus.
// TODO: Throw out CSVs that aren't members of the group due to group related failures?

// Union the providedAPIsFromCSVs from existing members of the group
operatorSurface, err := resolver.NewOperatorFromCSV(csv)
operatorSurface, err := resolver.NewOperatorFromV1Alpha1CSV(csv)
if err != nil {
logger.WithError(err).Warn("could not create OperatorSurface from csv")
continue
Expand Down Expand Up @@ -763,7 +763,7 @@ func (a *Operator) findCSVsThatProvideAnyOf(provide resolver.APISet) ([]*v1alpha
continue
}

operatorSurface, err := resolver.NewOperatorFromCSV(csv)
operatorSurface, err := resolver.NewOperatorFromV1Alpha1CSV(csv)
if err != nil {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/registry/resolver/evolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (e *NamespaceGenerationEvolver) checkForUpdates() error {
continue
}

bundle, key, err := e.querier.FindReplacement(op.Identifier(), op.SourceInfo().Package, op.SourceInfo().Channel, op.SourceInfo().Catalog)
bundle, key, err := e.querier.FindReplacement(op.Version(), op.Identifier(), op.SourceInfo().Package, op.SourceInfo().Channel, op.SourceInfo().Catalog)
if err != nil || bundle == nil {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/registry/resolver/generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewGenerationFromCluster(csvs []*v1alpha1.ClusterServiceVersion, subs []*v1
}
}
for _, csv := range csvs {
op, err := NewOperatorFromCSV(csv)
op, err := NewOperatorFromV1Alpha1CSV(csv)
if err != nil {
return nil, err
}
Expand Down
17 changes: 16 additions & 1 deletion pkg/controller/registry/resolver/generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

"github.com/blang/semver"
"github.com/operator-framework/operator-registry/pkg/registry"
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
"github.com/stretchr/testify/require"
Expand All @@ -12,6 +13,8 @@ import (
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
)

var NoVersion = semver.MustParse("0.0.0")

func TestNewGenerationFromCSVs(t *testing.T) {
type args struct {
csvs []*v1alpha1.ClusterServiceVersion
Expand Down Expand Up @@ -82,6 +85,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
},
requiredAPIs: EmptyAPISet(),
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: &Operator{
name: "operator.v1",
Expand All @@ -91,6 +95,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
},
requiredAPIs: EmptyAPISet(),
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
},
requiredAPIs: EmptyAPIMultiOwnerSet(),
Expand Down Expand Up @@ -142,6 +147,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: {},
},
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
},
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: map[string]OperatorSurface{
Expand All @@ -153,6 +159,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: {},
},
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
},
},
Expand All @@ -170,6 +177,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: {},
},
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
},
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: map[string]OperatorSurface{
Expand All @@ -181,6 +189,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: {},
},
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
},
},
Expand Down Expand Up @@ -246,6 +255,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
},
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
{Group: "g", Version: "v1", Kind: "CRDOwnedKind", Plural: "crdownedkinds"}: &Operator{
name: "operator.v1",
Expand All @@ -258,6 +268,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
},
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
},
requiredAPIs: map[opregistry.APIKey]OperatorSet{
Expand All @@ -273,6 +284,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
},
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
},
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: map[string]OperatorSurface{
Expand All @@ -287,6 +299,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
},
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
},
},
Expand All @@ -307,6 +320,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
},
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
},
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: map[string]OperatorSurface{
Expand All @@ -321,6 +335,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
},
sourceInfo: &ExistingOperator,
version: &NoVersion,
},
},
},
Expand All @@ -334,7 +349,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
operatorSet := EmptyOperatorSet()
for _, csv := range tt.args.csvs {
// there's a separate unit test for this constructor
op, err := NewOperatorFromCSV(csv)
op, err := NewOperatorFromV1Alpha1CSV(csv)
require.NoError(t, err)
operatorSet[op.Identifier()] = op
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/controller/registry/resolver/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"sort"
"strings"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/blang/semver"
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
)

type CatalogKey struct {
Expand Down Expand Up @@ -215,6 +217,7 @@ type OperatorSurface interface {
RequiredAPIs() APISet
Identifier() string
Replaces() string
Version() *semver.Version
SourceInfo() *OperatorSourceInfo
Bundle() *opregistry.Bundle
}
Expand All @@ -224,6 +227,7 @@ type Operator struct {
replaces string
providedAPIs APISet
requiredAPIs APISet
version *semver.Version
bundle *opregistry.Bundle
sourceInfo *OperatorSourceInfo
}
Expand All @@ -246,6 +250,7 @@ func NewOperatorFromBundle(bundle *opregistry.Bundle, startingCSV string, source
return &Operator{
name: csv.GetName(),
replaces: csv.Spec.Replaces,
version: &csv.Spec.Version.Version,
providedAPIs: providedAPIs,
requiredAPIs: requiredAPIs,
bundle: bundle,
Expand All @@ -258,7 +263,7 @@ func NewOperatorFromBundle(bundle *opregistry.Bundle, startingCSV string, source
}, nil
}

func NewOperatorFromCSV(csv *v1alpha1.ClusterServiceVersion) (*Operator, error) {
func NewOperatorFromV1Alpha1CSV(csv *v1alpha1.ClusterServiceVersion) (*Operator, error) {
providedAPIs := EmptyAPISet()
for _, crdDef := range csv.Spec.CustomResourceDefinitions.Owned {
parts := strings.SplitN(crdDef.Name, ".", 2)
Expand All @@ -285,6 +290,7 @@ func NewOperatorFromCSV(csv *v1alpha1.ClusterServiceVersion) (*Operator, error)

return &Operator{
name: csv.GetName(),
version: &csv.Spec.Version.Version,
replaces: csv.Spec.Replaces,
providedAPIs: providedAPIs,
requiredAPIs: requiredAPIs,
Expand Down Expand Up @@ -319,3 +325,7 @@ func (o *Operator) SourceInfo() *OperatorSourceInfo {
func (o *Operator) Bundle() *opregistry.Bundle {
return o.bundle
}

func (o *Operator) Version() *semver.Version {
return o.version
}
Loading