Skip to content

Commit

Permalink
feat(resolver): allow skipping a set of updates if the channel head
Browse files Browse the repository at this point in the history
explicitly states that a range of existing operators can update directly

this is to support z-stream releases for operators, where there is a
reasonable degree of confidence that it's safe to skip updates, and
where it is difficult to generate the graph ahead of time
  • Loading branch information
ecordell committed May 1, 2019
1 parent 71699e3 commit 96868b8
Show file tree
Hide file tree
Showing 33 changed files with 826 additions and 89 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"fmt"
"sort"

"github.com/blang/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

0 comments on commit 96868b8

Please sign in to comment.