Skip to content

Commit 96868b8

Browse files
committed
feat(resolver): allow skipping a set of updates if the channel head
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
1 parent 71699e3 commit 96868b8

33 files changed

+826
-89
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ codegen:
130130
cp scripts/generate_internal_groups.sh vendor/k8s.io/code-generator/generate_internal_groups.sh
131131
mkdir -p vendor/k8s.io/code-generator/hack
132132
cp boilerplate.go.txt vendor/k8s.io/code-generator/hack/boilerplate.go.txt
133-
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
133+
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
134134
$(CODEGEN) all $(PKG)/pkg/api/client $(PKG)/pkg/api/apis "operators:v1alpha1,v1"
135135
$(CODEGEN_INTERNAL) all $(PKG)/pkg/package-server/client $(PKG)/pkg/package-server/apis $(PKG)/pkg/package-server/apis "operators:v1 apps:v1alpha1"
136136

pkg/api/apis/operators/v1alpha1/clusterserviceversion_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
"fmt"
88
"sort"
99

10-
"github.com/blang/semver"
1110
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
12+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/version"
1213
)
1314

1415
const (
@@ -136,7 +137,7 @@ type APIServiceDefinitions struct {
136137
// that can manage apps for a given version.
137138
type ClusterServiceVersionSpec struct {
138139
InstallStrategy NamedInstallStrategy `json:"install"`
139-
Version semver.Version `json:"version,omitempty"`
140+
Version version.OperatorVersion `json:"version,omitempty"`
140141
Maturity string `json:"maturity,omitempty"`
141142
CustomResourceDefinitions CustomResourceDefinitions `json:"customresourcedefinitions,omitempty"`
142143
APIServiceDefinitions APIServiceDefinitions `json:"apiservicedefinitions,omitempty"`

pkg/api/apis/operators/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/operators/catalog/operator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha
779779
return sub, false, nil
780780
}
781781

782-
_, err := o.client.OperatorsV1alpha1().ClusterServiceVersions(sub.GetNamespace()).Get(sub.Status.CurrentCSV, metav1.GetOptions{})
782+
csv, err := o.client.OperatorsV1alpha1().ClusterServiceVersions(sub.GetNamespace()).Get(sub.Status.CurrentCSV, metav1.GetOptions{})
783783
out := sub.DeepCopy()
784784
if err != nil {
785785
logger.WithError(err).WithField("currentCSV", sub.Status.CurrentCSV).Debug("error fetching csv listed in subscription status")
@@ -789,7 +789,7 @@ func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha
789789
if err := querier.Queryable(); err != nil {
790790
return nil, false, err
791791
}
792-
bundle, _, _ := querier.FindReplacement(sub.Status.CurrentCSV, sub.Spec.Package, sub.Spec.Channel, resolver.CatalogKey{sub.Spec.CatalogSource, sub.Spec.CatalogSourceNamespace})
792+
bundle, _, _ := querier.FindReplacement(&csv.Spec.Version.Version, sub.Status.CurrentCSV, sub.Spec.Package, sub.Spec.Channel, resolver.CatalogKey{sub.Spec.CatalogSource, sub.Spec.CatalogSourceNamespace})
793793
if bundle != nil {
794794
out.Status.State = v1alpha1.SubscriptionStateUpgradeAvailable
795795
} else {

pkg/controller/operators/olm/operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
752752
return
753753
}
754754

755-
operatorSurface, err := resolver.NewOperatorFromCSV(out)
755+
operatorSurface, err := resolver.NewOperatorFromV1Alpha1CSV(out)
756756
if err != nil {
757757
// TODO: Add failure status to CSV
758758
syncError = err

pkg/controller/operators/olm/operatorgroup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (a *Operator) providedAPIsFromCSVs(group *v1.OperatorGroup, logger *logrus.
171171
// TODO: Throw out CSVs that aren't members of the group due to group related failures?
172172

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

766-
operatorSurface, err := resolver.NewOperatorFromCSV(csv)
766+
operatorSurface, err := resolver.NewOperatorFromV1Alpha1CSV(csv)
767767
if err != nil {
768768
continue
769769
}

pkg/controller/registry/resolver/evolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (e *NamespaceGenerationEvolver) checkForUpdates() error {
5757
continue
5858
}
5959

60-
bundle, key, err := e.querier.FindReplacement(op.Identifier(), op.SourceInfo().Package, op.SourceInfo().Channel, op.SourceInfo().Catalog)
60+
bundle, key, err := e.querier.FindReplacement(op.Version(), op.Identifier(), op.SourceInfo().Package, op.SourceInfo().Channel, op.SourceInfo().Catalog)
6161
if err != nil || bundle == nil {
6262
continue
6363
}

pkg/controller/registry/resolver/generation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewGenerationFromCluster(csvs []*v1alpha1.ClusterServiceVersion, subs []*v1
4747
}
4848
}
4949
for _, csv := range csvs {
50-
op, err := NewOperatorFromCSV(csv)
50+
op, err := NewOperatorFromV1Alpha1CSV(csv)
5151
if err != nil {
5252
return nil, err
5353
}

pkg/controller/registry/resolver/generation_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/blang/semver"
78
"github.com/operator-framework/operator-registry/pkg/registry"
89
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
910
"github.com/stretchr/testify/require"
@@ -12,6 +13,8 @@ import (
1213
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
1314
)
1415

16+
var NoVersion = semver.MustParse("0.0.0")
17+
1518
func TestNewGenerationFromCSVs(t *testing.T) {
1619
type args struct {
1720
csvs []*v1alpha1.ClusterServiceVersion
@@ -82,6 +85,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
8285
},
8386
requiredAPIs: EmptyAPISet(),
8487
sourceInfo: &ExistingOperator,
88+
version: &NoVersion,
8589
},
8690
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: &Operator{
8791
name: "operator.v1",
@@ -91,6 +95,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
9195
},
9296
requiredAPIs: EmptyAPISet(),
9397
sourceInfo: &ExistingOperator,
98+
version: &NoVersion,
9499
},
95100
},
96101
requiredAPIs: EmptyAPIMultiOwnerSet(),
@@ -142,6 +147,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
142147
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: {},
143148
},
144149
sourceInfo: &ExistingOperator,
150+
version: &NoVersion,
145151
},
146152
},
147153
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: map[string]OperatorSurface{
@@ -153,6 +159,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
153159
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: {},
154160
},
155161
sourceInfo: &ExistingOperator,
162+
version: &NoVersion,
156163
},
157164
},
158165
},
@@ -170,6 +177,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
170177
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: {},
171178
},
172179
sourceInfo: &ExistingOperator,
180+
version: &NoVersion,
173181
},
174182
},
175183
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: map[string]OperatorSurface{
@@ -181,6 +189,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
181189
{Group: "g", Version: "v1", Kind: "CRDKind", Plural: "crdkinds"}: {},
182190
},
183191
sourceInfo: &ExistingOperator,
192+
version: &NoVersion,
184193
},
185194
},
186195
},
@@ -246,6 +255,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
246255
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
247256
},
248257
sourceInfo: &ExistingOperator,
258+
version: &NoVersion,
249259
},
250260
{Group: "g", Version: "v1", Kind: "CRDOwnedKind", Plural: "crdownedkinds"}: &Operator{
251261
name: "operator.v1",
@@ -258,6 +268,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
258268
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
259269
},
260270
sourceInfo: &ExistingOperator,
271+
version: &NoVersion,
261272
},
262273
},
263274
requiredAPIs: map[opregistry.APIKey]OperatorSet{
@@ -273,6 +284,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
273284
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
274285
},
275286
sourceInfo: &ExistingOperator,
287+
version: &NoVersion,
276288
},
277289
},
278290
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: map[string]OperatorSurface{
@@ -287,6 +299,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
287299
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
288300
},
289301
sourceInfo: &ExistingOperator,
302+
version: &NoVersion,
290303
},
291304
},
292305
},
@@ -307,6 +320,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
307320
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
308321
},
309322
sourceInfo: &ExistingOperator,
323+
version: &NoVersion,
310324
},
311325
},
312326
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: map[string]OperatorSurface{
@@ -321,6 +335,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
321335
{Group: "g2", Version: "v1", Kind: "CRDReqKind", Plural: "crdreqkinds"}: {},
322336
},
323337
sourceInfo: &ExistingOperator,
338+
version: &NoVersion,
324339
},
325340
},
326341
},
@@ -334,7 +349,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
334349
operatorSet := EmptyOperatorSet()
335350
for _, csv := range tt.args.csvs {
336351
// there's a separate unit test for this constructor
337-
op, err := NewOperatorFromCSV(csv)
352+
op, err := NewOperatorFromV1Alpha1CSV(csv)
338353
require.NoError(t, err)
339354
operatorSet[op.Identifier()] = op
340355
}

pkg/controller/registry/resolver/operators.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"sort"
77
"strings"
88

9-
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
9+
"github.com/blang/semver"
1010
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
1111
"k8s.io/apimachinery/pkg/runtime/schema"
12+
13+
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
1214
)
1315

1416
type CatalogKey struct {
@@ -215,6 +217,7 @@ type OperatorSurface interface {
215217
RequiredAPIs() APISet
216218
Identifier() string
217219
Replaces() string
220+
Version() *semver.Version
218221
SourceInfo() *OperatorSourceInfo
219222
Bundle() *opregistry.Bundle
220223
}
@@ -224,6 +227,7 @@ type Operator struct {
224227
replaces string
225228
providedAPIs APISet
226229
requiredAPIs APISet
230+
version *semver.Version
227231
bundle *opregistry.Bundle
228232
sourceInfo *OperatorSourceInfo
229233
}
@@ -246,6 +250,7 @@ func NewOperatorFromBundle(bundle *opregistry.Bundle, startingCSV string, source
246250
return &Operator{
247251
name: csv.GetName(),
248252
replaces: csv.Spec.Replaces,
253+
version: &csv.Spec.Version.Version,
249254
providedAPIs: providedAPIs,
250255
requiredAPIs: requiredAPIs,
251256
bundle: bundle,
@@ -258,7 +263,7 @@ func NewOperatorFromBundle(bundle *opregistry.Bundle, startingCSV string, source
258263
}, nil
259264
}
260265

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

286291
return &Operator{
287292
name: csv.GetName(),
293+
version: &csv.Spec.Version.Version,
288294
replaces: csv.Spec.Replaces,
289295
providedAPIs: providedAPIs,
290296
requiredAPIs: requiredAPIs,
@@ -319,3 +325,7 @@ func (o *Operator) SourceInfo() *OperatorSourceInfo {
319325
func (o *Operator) Bundle() *opregistry.Bundle {
320326
return o.bundle
321327
}
328+
329+
func (o *Operator) Version() *semver.Version {
330+
return o.version
331+
}

0 commit comments

Comments
 (0)