diff --git a/go.mod b/go.mod index 68407085532..17fdf8959a3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/pkg/controller/registry/resolver/evolver.go b/pkg/controller/registry/resolver/evolver.go index f82487225b0..8d630e4ddf4 100644 --- a/pkg/controller/registry/resolver/evolver.go +++ b/pkg/controller/registry/resolver/evolver.go @@ -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") } @@ -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") } @@ -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") } diff --git a/pkg/controller/registry/resolver/operators.go b/pkg/controller/registry/resolver/operators.go index 82b0c56b466..203b8043c18 100644 --- a/pkg/controller/registry/resolver/operators.go +++ b/pkg/controller/registry/resolver/operators.go @@ -238,7 +238,7 @@ 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") } @@ -246,10 +246,6 @@ func NewOperatorFromBundle(bundle *api.Bundle, replaces string, startingCSV stri 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) @@ -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, @@ -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, @@ -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 } diff --git a/pkg/controller/registry/resolver/operators_test.go b/pkg/controller/registry/resolver/operators_test.go index b2686a3f49c..c0adf29174e 100644 --- a/pkg/controller/registry/resolver/operators_test.go +++ b/pkg/controller/registry/resolver/operators_test.go @@ -1040,7 +1040,6 @@ func TestNewOperatorFromBundle(t *testing.T) { want: &Operator{ name: "testCSV", version: &version.Version, - replaces: "v1", providedAPIs: EmptyAPISet(), requiredAPIs: EmptyAPISet(), bundle: bundleNoAPIs, @@ -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", @@ -1110,7 +1108,6 @@ func TestNewOperatorFromBundle(t *testing.T) { providedAPIs: EmptyAPISet(), requiredAPIs: EmptyAPISet(), bundle: bundleNoAPIs, - replaces: "replaced", version: &version.Version, sourceInfo: &OperatorSourceInfo{ Package: "testPackage", @@ -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) }) diff --git a/pkg/controller/registry/resolver/querier.go b/pkg/controller/registry/resolver/querier.go index 93402334ea1..b85d29a4e37 100644 --- a/pkg/controller/registry/resolver/querier.go +++ b/pkg/controller/registry/resolver/querier.go @@ -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" @@ -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 } diff --git a/pkg/controller/registry/resolver/querier_test.go b/pkg/controller/registry/resolver/querier_test.go index 201579f4f0f..53afae5f487 100644 --- a/pkg/controller/registry/resolver/querier_test.go +++ b/pkg/controller/registry/resolver/querier_test.go @@ -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) @@ -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) }) diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/api/registry.pb.go b/vendor/github.com/operator-framework/operator-registry/pkg/api/registry.pb.go index 06a9a930959..4430ca95867 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/api/registry.pb.go +++ b/vendor/github.com/operator-framework/operator-registry/pkg/api/registry.pb.go @@ -168,6 +168,8 @@ type Bundle struct { BundlePath string `protobuf:"bytes,6,opt,name=bundlePath" json:"bundlePath,omitempty"` ProvidedApis []*GroupVersionKind `protobuf:"bytes,7,rep,name=providedApis" json:"providedApis,omitempty"` RequiredApis []*GroupVersionKind `protobuf:"bytes,8,rep,name=requiredApis" json:"requiredApis,omitempty"` + Version string `protobuf:"bytes,9,opt,name=version" json:"version,omitempty"` + SkipRange string `protobuf:"bytes,10,opt,name=skipRange" json:"skipRange,omitempty"` } func (m *Bundle) Reset() { *m = Bundle{} } @@ -231,6 +233,20 @@ func (m *Bundle) GetRequiredApis() []*GroupVersionKind { return nil } +func (m *Bundle) GetVersion() string { + if m != nil { + return m.Version + } + return "" +} + +func (m *Bundle) GetSkipRange() string { + if m != nil { + return m.SkipRange + } + return "" +} + type ChannelEntry struct { PackageName string `protobuf:"bytes,1,opt,name=packageName" json:"packageName,omitempty"` ChannelName string `protobuf:"bytes,2,opt,name=channelName" json:"channelName,omitempty"` @@ -985,48 +1001,49 @@ var _Registry_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("registry.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 680 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xc4, 0x56, 0x4f, 0x6f, 0xd3, 0x30, - 0x14, 0x5f, 0xda, 0xad, 0xed, 0x5e, 0x2b, 0xb4, 0x99, 0x6d, 0x84, 0x80, 0xa6, 0xe2, 0x0b, 0x3b, - 0x55, 0x30, 0x40, 0x88, 0x03, 0x87, 0x8d, 0x41, 0x05, 0x0c, 0x34, 0x45, 0xfc, 0x39, 0x70, 0xf2, - 0x12, 0xd3, 0x86, 0x65, 0x4e, 0x66, 0x3b, 0x9b, 0xf6, 0x25, 0xb8, 0xf0, 0x3d, 0xf8, 0x8c, 0x28, - 0xb6, 0x93, 0x3a, 0x69, 0xba, 0x21, 0x21, 0xe0, 0xd6, 0xf7, 0xfc, 0xfe, 0xfc, 0xde, 0xcb, 0xef, - 0x67, 0x17, 0x6e, 0x70, 0x3a, 0x89, 0x84, 0xe4, 0x97, 0xa3, 0x94, 0x27, 0x32, 0x41, 0x6d, 0x92, - 0x46, 0xf8, 0x29, 0x74, 0x5f, 0x4c, 0x09, 0x63, 0x34, 0x46, 0x08, 0x96, 0x19, 0x39, 0xa5, 0xae, - 0x33, 0x74, 0x76, 0x56, 0x7d, 0xf5, 0x1b, 0xb9, 0xd0, 0x0d, 0xc4, 0xf9, 0xfb, 0xdc, 0xdd, 0x52, - 0xee, 0xc2, 0xc4, 0xf7, 0xa0, 0x7f, 0x44, 0x82, 0x13, 0x32, 0xa1, 0xb9, 0xd9, 0x94, 0x8c, 0x2f, - 0xa0, 0x6b, 0x42, 0x1a, 0x6b, 0xef, 0x40, 0x2f, 0xd0, 0xad, 0x85, 0xdb, 0x1a, 0xb6, 0x77, 0xfa, - 0xbb, 0x83, 0x11, 0x49, 0xa3, 0x91, 0xc1, 0xe3, 0x97, 0xa7, 0x68, 0x04, 0x28, 0xa4, 0x5f, 0x49, - 0x16, 0x4b, 0x73, 0xa6, 0x00, 0xb5, 0x55, 0xad, 0x86, 0x13, 0xcc, 0x60, 0x6d, 0xcc, 0x93, 0x2c, - 0xfd, 0x44, 0xb9, 0x88, 0x12, 0xf6, 0x36, 0x62, 0x21, 0xda, 0x80, 0x95, 0x49, 0xee, 0x33, 0x10, - 0xb4, 0x91, 0xcf, 0x77, 0xae, 0x83, 0x8a, 0xf9, 0x8c, 0x99, 0x23, 0x3e, 0x89, 0x58, 0x68, 0xba, - 0xa8, 0xdf, 0x68, 0x0b, 0x3a, 0x69, 0x9c, 0x71, 0x12, 0xbb, 0xcb, 0xca, 0x6b, 0x2c, 0xfc, 0xb3, - 0x05, 0x9d, 0xfd, 0x8c, 0x85, 0x71, 0x65, 0x61, 0x4e, 0x65, 0x61, 0x68, 0x08, 0xfd, 0x74, 0xb6, - 0x30, 0xd3, 0xce, 0x76, 0xe5, 0x11, 0xc1, 0xdc, 0x7c, 0xb6, 0xcb, 0x54, 0x7f, 0x23, 0x12, 0x66, - 0x10, 0x14, 0x66, 0x0e, 0x2d, 0x39, 0xfe, 0x46, 0x03, 0xe9, 0xae, 0x0c, 0xdb, 0x39, 0x34, 0x6d, - 0xa1, 0x6d, 0x80, 0x63, 0x85, 0xec, 0x88, 0xc8, 0xa9, 0xdb, 0x51, 0x49, 0x96, 0x07, 0x3d, 0x83, - 0x41,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, 0x00, 0x00, 0x00, 0xff, 0xff, - 0xf7, 0x7c, 0x82, 0x4a, 0xca, 0x08, 0x00, 0x00, + // 701 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xc4, 0x56, 0x5d, 0x6f, 0xd3, 0x3c, + 0x14, 0x5e, 0xdb, 0xad, 0x1f, 0xa7, 0xd5, 0xab, 0xcd, 0xef, 0x36, 0x42, 0x99, 0xa6, 0xe2, 0x1b, + 0x76, 0x55, 0xc1, 0x00, 0x21, 0x2e, 0xb8, 0xd8, 0x18, 0x54, 0xc0, 0x40, 0x53, 0xc4, 0xc7, 0x05, + 0x57, 0x5e, 0x6b, 0x5a, 0xd3, 0xcc, 0xc9, 0x6c, 0x67, 0xd3, 0xfe, 0x04, 0x37, 0xfc, 0x47, 0x7e, + 0x07, 0x8a, 0xed, 0x24, 0x4e, 0x9a, 0x6e, 0x48, 0x08, 0xb8, 0xeb, 0x39, 0x3e, 0x1f, 0xcf, 0x79, + 0x72, 0x1e, 0xbb, 0xf0, 0x9f, 0xa0, 0x53, 0x26, 0x95, 0xb8, 0x1a, 0x46, 0x22, 0x54, 0x21, 0x6a, + 0x90, 0x88, 0xe1, 0x27, 0xd0, 0x7a, 0x3e, 0x23, 0x9c, 0xd3, 0x00, 0x21, 0x58, 0xe5, 0xe4, 0x8c, + 0x7a, 0xb5, 0x41, 0x6d, 0xaf, 0xe3, 0xeb, 0xdf, 0xc8, 0x83, 0xd6, 0x58, 0x5e, 0xbc, 0x4b, 0xdc, + 0x75, 0xed, 0x4e, 0x4d, 0x7c, 0x17, 0xba, 0x27, 0x64, 0x3c, 0x27, 0x53, 0x9a, 0x98, 0x55, 0xc9, + 0xf8, 0x12, 0x5a, 0x36, 0xa4, 0xb2, 0xf6, 0x1e, 0xb4, 0xc7, 0xa6, 0xb5, 0xf4, 0xea, 0x83, 0xc6, + 0x5e, 0x77, 0xbf, 0x37, 0x24, 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x89, 0x6e, 0xe9, 0xab, 0x61, 0x51, 0x2f, 0xfd, 0x75, 0x7d, 0xe0, 0x3c, 0x27, 0x78, 0xe5, + 0x7e, 0x0d, 0x3d, 0x02, 0xc8, 0x55, 0x84, 0xb6, 0xcd, 0xbd, 0x52, 0x96, 0x55, 0xbf, 0xe7, 0xe6, + 0xe2, 0x15, 0xf4, 0x00, 0x3a, 0xd9, 0xa2, 0xa3, 0xad, 0x34, 0xa9, 0x20, 0xb1, 0x7e, 0x57, 0xbb, + 0x8d, 0x0f, 0xaf, 0xa0, 0x23, 0xf8, 0x3f, 0x0b, 0x79, 0x19, 0x8a, 0xf4, 0x3d, 0xdc, 0x2d, 0x26, + 0x97, 0x55, 0x53, 0xae, 0xf2, 0x01, 0x76, 0x46, 0x54, 0x39, 0xb7, 0x13, 0xa3, 0xf2, 0xfd, 0x8c, + 0xa4, 0x3b, 0x9e, 0x97, 0xab, 0xd6, 0x4a, 0x7f, 0xc3, 0x7d, 0xfc, 0xf4, 0xed, 0xa6, 0x59, 0x38, + 0xd4, 0x42, 0x31, 0x5d, 0x9c, 0x72, 0x12, 0xf5, 0xd3, 0x7a, 0x8b, 0x22, 0x2a, 0x43, 0xf3, 0x97, + 0x40, 0xb3, 0x9b, 0x81, 0xee, 0x38, 0xd0, 0xca, 0x7b, 0xba, 0x0c, 0xd7, 0x67, 0xc0, 0xd9, 0x6e, + 0x2f, 0xaf, 0x9c, 0x0d, 0x5d, 0x2d, 0x82, 0x65, 0xc5, 0xdf, 0x6a, 0xc0, 0x76, 0x7f, 0xf3, 0xd9, + 0x6d, 0xba, 0xcc, 0xcb, 0x56, 0xaf, 0x78, 0x69, 0xfe, 0xd3, 0xa6, 0xfe, 0xc3, 0xf3, 0xf0, 0x67, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xe1, 0x3c, 0x83, 0x36, 0x02, 0x09, 0x00, 0x00, } diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/api/registry.proto b/vendor/github.com/operator-framework/operator-registry/pkg/api/registry.proto index 08ca7584193..84cf90e4410 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/api/registry.proto +++ b/vendor/github.com/operator-framework/operator-registry/pkg/api/registry.proto @@ -46,6 +46,8 @@ message Bundle{ string bundlePath = 6; repeated GroupVersionKind providedApis = 7; repeated GroupVersionKind requiredApis = 8; + string version = 9; + string skipRange = 10; } message ChannelEntry{ diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/000_init.go b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/000_init.go index 67df6476cb9..00986acae8e 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/000_init.go +++ b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/000_init.go @@ -7,6 +7,10 @@ import ( var InitMigrationKey = 0 +func init() { + registerMigration(InitMigrationKey, initMigration) +} + var initMigration = &Migration{ Id: InitMigrationKey, Up: func(ctx context.Context, tx *sql.Tx) error { @@ -72,7 +76,3 @@ var initMigration = &Migration{ return err }, } - -func init() { - migrations[InitMigrationKey] = initMigration -} diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/001_related_images.go b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/001_related_images.go index 392f7225267..3b3c8c36b98 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/001_related_images.go +++ b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/001_related_images.go @@ -14,7 +14,7 @@ import ( const RelatedImagesMigrationKey = 1 func init() { - migrations[RelatedImagesMigrationKey] = relatedImagesMigration + registerMigration(RelatedImagesMigrationKey, relatedImagesMigration) } // listBundles returns a list of operatorbundles as strings diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/002_bundle_path.go b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/002_bundle_path.go index 0ba0f09f069..b16c13d76bb 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/002_bundle_path.go +++ b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/002_bundle_path.go @@ -9,7 +9,7 @@ const BundlePathMigrationKey = 2 // Register this migration func init() { - migrations[BundlePathMigrationKey] = bundlePathMigration + registerMigration(BundlePathMigrationKey, bundlePathMigration) } var bundlePathMigration = &Migration{ @@ -23,13 +23,13 @@ var bundlePathMigration = &Migration{ return err }, Down: func(ctx context.Context, tx *sql.Tx) error { - foreingKeyOff := `PRAGMA foreign_keys = 0` + foreignKeyOff := `PRAGMA foreign_keys = 0` createTempTable := `CREATE TABLE operatorbundle_backup (name TEXT,csv TEXT,bundle TEXT)` backupTargetTable := `INSERT INTO operatorbundle_backup SELECT name,csv,bundle FROM operatorbundle` dropTargetTable := `DROP TABLE operatorbundle` renameBackUpTable := `ALTER TABLE operatorbundle_backup RENAME TO operatorbundle;` - foreingKeyOn := `PRAGMA foreign_keys = 1` - _, err := tx.ExecContext(ctx, foreingKeyOff) + foreignKeyOn := `PRAGMA foreign_keys = 1` + _, err := tx.ExecContext(ctx, foreignKeyOff) if err != nil { return err } @@ -49,7 +49,7 @@ var bundlePathMigration = &Migration{ if err != nil { return err } - _, err = tx.ExecContext(ctx, foreingKeyOn) + _, err = tx.ExecContext(ctx, foreignKeyOn) return err }, } diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/003_required_apis.go b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/003_required_apis.go index dc1b451d74a..08006a03001 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/003_required_apis.go +++ b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/003_required_apis.go @@ -13,7 +13,7 @@ const RequiredApiMigrationKey = 3 // Register this migration func init() { - migrations[RequiredApiMigrationKey] = requiredApiMigration + registerMigration(RequiredApiMigrationKey, requiredApiMigration) } var requiredApiMigration = &Migration{ diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/004_version_skiprange.go b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/004_version_skiprange.go new file mode 100644 index 00000000000..e2783cfdbe6 --- /dev/null +++ b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/004_version_skiprange.go @@ -0,0 +1,94 @@ +package migrations + +import ( + "context" + "database/sql" + + "github.com/sirupsen/logrus" +) + +const VersionSkipRangeMigrationKey = 4 +const SkipRangeAnnotationKey = "olm.skipRange" + +// Register this migration +func init() { + registerMigration(VersionSkipRangeMigrationKey, versionSkipRangeMigration) +} + +var versionSkipRangeMigration = &Migration{ + Id: VersionSkipRangeMigrationKey, + Up: func(ctx context.Context, tx *sql.Tx) error { + sql := ` + ALTER TABLE operatorbundle + ADD COLUMN skiprange TEXT; + + ALTER TABLE operatorbundle + ADD COLUMN version TEXT; + ` + _, err := tx.ExecContext(ctx, sql) + if err != nil { + return err + } + + bundles, err := listBundles(ctx, tx) + if err != nil { + return err + } + for _, bundle := range bundles { + if err := extractVersioning(ctx, tx, bundle); err != nil { + logrus.Warnf("error backfilling related images: %v", err) + continue + } + } + return err + }, + Down: func(ctx context.Context, tx *sql.Tx) error { + foreignKeyOff := `PRAGMA foreign_keys = 0` + createTempTable := `CREATE TABLE operatorbundle_backup (name TEXT, csv TEXT, bundle TEXT, bundlepath TEXT)` + backupTargetTable := `INSERT INTO operatorbundle_backup SELECT name, csv, bundle, bundlepath FROM operatorbundle` + dropTargetTable := `DROP TABLE operatorbundle` + renameBackUpTable := `ALTER TABLE operatorbundle_backup RENAME TO operatorbundle;` + foreignKeyOn := `PRAGMA foreign_keys = 1` + _, err := tx.ExecContext(ctx, foreignKeyOff) + if err != nil { + return err + } + _, err = tx.ExecContext(ctx, createTempTable) + if err != nil { + return err + } + _, err = tx.ExecContext(ctx, backupTargetTable) + if err != nil { + return err + } + _, err = tx.ExecContext(ctx, dropTargetTable) + if err != nil { + return err + } + _, err = tx.ExecContext(ctx, renameBackUpTable) + if err != nil { + return err + } + _, err = tx.ExecContext(ctx, foreignKeyOn) + return err + }, +} + +func extractVersioning(ctx context.Context, tx *sql.Tx, name string) error { + addSql := `insert into operatorbundle(version, skiprange) values(?,?)` + csv, err := getCSV(ctx, tx, name) + if err != nil { + logrus.Warnf("error backfilling versioning: %v", err) + return err + } + skiprange, ok := csv.Annotations[SkipRangeAnnotationKey] + if !ok { + skiprange = "" + } + version, err := csv.GetVersion() + if err != nil { + version = "" + } + _, err = tx.ExecContext(ctx, addSql, version, skiprange) + return err +} diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/migrations.go b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/migrations.go index d2802c2ee0f..b9bb60fbaf3 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/migrations.go +++ b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrations/migrations.go @@ -3,6 +3,7 @@ package migrations import ( "context" "database/sql" + "fmt" "sort" ) @@ -80,3 +81,13 @@ func Only(key int) Migrations { func All() MigrationSet { return migrations } + +func registerMigration(key int, m *Migration) { + if _, ok := migrations[key]; ok { + panic(fmt.Sprintf("already have a migration registered with id %d", key)) + } + if m.Id != key { + panic(fmt.Sprintf("migration has wrong id for key. key: %d, id: %d", key, m.Id)) + } + migrations[key] = m +} diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrator.go b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrator.go index f1c349200b3..da86bbc2022 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrator.go +++ b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/migrator.go @@ -69,9 +69,14 @@ func (m *SQLLiteMigrator) Up(ctx context.Context, migrations migrations.Migratio if err != nil { return err } + var commitErr error defer func() { + if commitErr == nil { + return + } + logrus.WithError(commitErr).Warningf("tx commit failed") if err := tx.Rollback(); err != nil { - logrus.WithError(err).Debugf("couldn't rollback - this is expected if the transaction committed") + logrus.WithError(err).Warningf("couldn't rollback after failed commit") } }() @@ -97,10 +102,8 @@ func (m *SQLLiteMigrator) Up(ctx context.Context, migrations migrations.Migratio return err } } - if err := tx.Commit(); err != nil { - return err - } - return nil + commitErr = tx.Commit() + return commitErr } func (m *SQLLiteMigrator) Down(ctx context.Context, migrations migrations.Migrations) error { @@ -108,9 +111,14 @@ func (m *SQLLiteMigrator) Down(ctx context.Context, migrations migrations.Migrat if err != nil { return err } + var commitErr error defer func() { + if commitErr == nil { + return + } + logrus.WithError(commitErr).Warningf("tx commit failed") if err := tx.Rollback(); err != nil { - logrus.WithError(err).Debugf("couldn't rollback - this is expected if the transaction committed") + logrus.WithError(err).Warningf("couldn't rollback after failed commit") } }() if err := m.ensureMigrationTable(ctx, tx); err != nil { @@ -135,10 +143,8 @@ func (m *SQLLiteMigrator) Down(ctx context.Context, migrations migrations.Migrat return err } } - if err := tx.Commit(); err != nil { - return err - } - return nil + commitErr = tx.Commit() + return commitErr } func (m *SQLLiteMigrator) ensureMigrationTable(ctx context.Context, tx *sql.Tx) error { diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/query.go b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/query.go index 54d3d95e53c..0ebc4f6954d 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/query.go +++ b/vendor/github.com/operator-framework/operator-registry/pkg/sqlite/query.go @@ -36,6 +36,8 @@ func (s *SQLQuerier) ListTables(ctx context.Context) ([]string, error) { if err != nil { return nil, err } + defer rows.Close() + tables := []string{} for rows.Next() { var tableName sql.NullString @@ -56,6 +58,8 @@ func (s *SQLQuerier) ListPackages(ctx context.Context) ([]string, error) { if err != nil { return nil, err } + defer rows.Close() + packages := []string{} for rows.Next() { var pkgName sql.NullString @@ -77,6 +81,7 @@ func (s *SQLQuerier) GetPackage(ctx context.Context, name string) (*registry.Pac if err != nil { return nil, err } + defer rows.Close() var pkgName sql.NullString var defaultChannel sql.NullString @@ -109,13 +114,14 @@ func (s *SQLQuerier) GetPackage(ctx context.Context, name string) (*registry.Pac } func (s *SQLQuerier) GetBundle(ctx context.Context, pkgName, channelName, csvName string) (*api.Bundle, error) { - query := `SELECT DISTINCT channel_entry.entry_id, operatorbundle.name, operatorbundle.bundle, operatorbundle.bundlepath + query := `SELECT DISTINCT channel_entry.entry_id, operatorbundle.name, operatorbundle.bundle, operatorbundle.bundlepath, operatorbundle.version, operatorbundle.skiprange FROM operatorbundle INNER JOIN channel_entry ON operatorbundle.name=channel_entry.operatorbundle_name WHERE channel_entry.package_name=? AND channel_entry.channel_name=? AND operatorbundle_name=? LIMIT 1` rows, err := s.db.QueryContext(ctx, query, pkgName, channelName, csvName) if err != nil { return nil, err } + defer rows.Close() if !rows.Next() { return nil, fmt.Errorf("no entry found for %s %s %s", pkgName, channelName, csvName) @@ -124,7 +130,9 @@ func (s *SQLQuerier) GetBundle(ctx context.Context, pkgName, channelName, csvNam var name sql.NullString var bundle sql.NullString var bundlePath sql.NullString - if err := rows.Scan(&entryId, &name, &bundle, &bundlePath); err != nil { + var version sql.NullString + var skipRange sql.NullString + if err := rows.Scan(&entryId, &name, &bundle, &bundlePath, &version, &skipRange); err != nil { return nil, err } @@ -139,6 +147,8 @@ func (s *SQLQuerier) GetBundle(ctx context.Context, pkgName, channelName, csvNam out.PackageName = pkgName out.ChannelName = channelName out.BundlePath = bundlePath.String + out.Version = version.String + out.SkipRange = skipRange.String provided, required, err := s.GetApisForEntry(ctx, entryId.Int64) if err != nil { @@ -151,7 +161,7 @@ func (s *SQLQuerier) GetBundle(ctx context.Context, pkgName, channelName, csvNam } func (s *SQLQuerier) GetBundleForChannel(ctx context.Context, pkgName string, channelName string) (*api.Bundle, error) { - query := `SELECT DISTINCT channel_entry.entry_id, operatorbundle.name, operatorbundle.bundle, operatorbundle.bundlepath FROM channel + query := `SELECT DISTINCT channel_entry.entry_id, operatorbundle.name, operatorbundle.bundle, operatorbundle.bundlepath, operatorbundle.version, operatorbundle.skiprange FROM channel INNER JOIN operatorbundle ON channel.head_operatorbundle_name=operatorbundle.name INNER JOIN channel_entry ON (channel_entry.channel_name = channel.name and channel_entry.package_name=channel.package_name and channel_entry.operatorbundle_name=operatorbundle.name) WHERE channel.package_name=? AND channel.name=? LIMIT 1` @@ -159,6 +169,7 @@ func (s *SQLQuerier) GetBundleForChannel(ctx context.Context, pkgName string, ch if err != nil { return nil, err } + defer rows.Close() if !rows.Next() { return nil, fmt.Errorf("no entry found for %s %s", pkgName, channelName) @@ -167,7 +178,9 @@ func (s *SQLQuerier) GetBundleForChannel(ctx context.Context, pkgName string, ch var name sql.NullString var bundle sql.NullString var bundlePath sql.NullString - if err := rows.Scan(&entryId, &name, &bundle, &bundlePath); err != nil { + var version sql.NullString + var skipRange sql.NullString + if err := rows.Scan(&entryId, &name, &bundle, &bundlePath, &version, &skipRange); err != nil { return nil, err } @@ -182,6 +195,8 @@ func (s *SQLQuerier) GetBundleForChannel(ctx context.Context, pkgName string, ch out.PackageName = pkgName out.ChannelName = channelName out.BundlePath = bundlePath.String + out.Version = version.String + out.SkipRange = skipRange.String provided, required, err := s.GetApisForEntry(ctx, entryId.Int64) if err != nil { @@ -202,6 +217,7 @@ func (s *SQLQuerier) GetChannelEntriesThatReplace(ctx context.Context, name stri if err != nil { return } + defer rows.Close() entries = []*registry.ChannelEntry{} @@ -228,7 +244,7 @@ func (s *SQLQuerier) GetChannelEntriesThatReplace(ctx context.Context, name stri } func (s *SQLQuerier) GetBundleThatReplaces(ctx context.Context, name, pkgName, channelName string) (*api.Bundle, error) { - query := `SELECT DISTINCT replaces.entry_id, operatorbundle.name, operatorbundle.bundle, operatorbundle.bundlepath + query := `SELECT DISTINCT replaces.entry_id, operatorbundle.name, operatorbundle.bundle, operatorbundle.bundlepath, operatorbundle.version, operatorbundle.skiprange FROM channel_entry LEFT OUTER JOIN channel_entry replaces ON replaces.replaces = channel_entry.entry_id INNER JOIN operatorbundle ON replaces.operatorbundle_name = operatorbundle.name @@ -237,6 +253,8 @@ func (s *SQLQuerier) GetBundleThatReplaces(ctx context.Context, name, pkgName, c if err != nil { return nil, err } + defer rows.Close() + if !rows.Next() { return nil, fmt.Errorf("no entry found for %s %s", pkgName, channelName) @@ -245,7 +263,9 @@ func (s *SQLQuerier) GetBundleThatReplaces(ctx context.Context, name, pkgName, c var outName sql.NullString var bundle sql.NullString var bundlePath sql.NullString - if err := rows.Scan(&entryId, &outName, &bundle, &bundlePath); err != nil { + var version sql.NullString + var skipRange sql.NullString + if err := rows.Scan(&entryId, &outName, &bundle, &bundlePath, &version, &skipRange); err != nil { return nil, err } @@ -260,6 +280,8 @@ func (s *SQLQuerier) GetBundleThatReplaces(ctx context.Context, name, pkgName, c out.PackageName = pkgName out.ChannelName = channelName out.BundlePath = bundlePath.String + out.Version = version.String + out.SkipRange = skipRange.String provided, required, err := s.GetApisForEntry(ctx, entryId.Int64) if err != nil { @@ -282,6 +304,7 @@ func (s *SQLQuerier) GetChannelEntriesThatProvide(ctx context.Context, group, ve if err != nil { return } + defer rows.Close() entries = []*registry.ChannelEntry{} @@ -320,6 +343,7 @@ func (s *SQLQuerier) GetLatestChannelEntriesThatProvide(ctx context.Context, gro if err != nil { return nil, err } + defer rows.Close() entries = []*registry.ChannelEntry{} @@ -348,8 +372,8 @@ func (s *SQLQuerier) GetLatestChannelEntriesThatProvide(ctx context.Context, gro } // Get the the latest bundle that provides the API in a default channel, error unless there is ONLY one -func (s *SQLQuerier) GetBundleThatProvides(ctx context.Context, group, version, kind string) (*api.Bundle, error) { - query := `SELECT DISTINCT channel_entry.entry_id, operatorbundle.bundle, operatorbundle.bundlepath, MIN(channel_entry.depth), channel_entry.operatorbundle_name, channel_entry.package_name, channel_entry.channel_name, channel_entry.replaces +func (s *SQLQuerier) GetBundleThatProvides(ctx context.Context, group, apiVersion, kind string) (*api.Bundle, error) { + query := `SELECT DISTINCT channel_entry.entry_id, operatorbundle.bundle, operatorbundle.bundlepath, MIN(channel_entry.depth), channel_entry.operatorbundle_name, channel_entry.package_name, channel_entry.channel_name, channel_entry.replaces, operatorbundle.version, operatorbundle.skiprange FROM channel_entry INNER JOIN api_provider ON channel_entry.entry_id = api_provider.channel_entry_id INNER JOIN operatorbundle ON operatorbundle.name = channel_entry.operatorbundle_name @@ -357,13 +381,14 @@ func (s *SQLQuerier) GetBundleThatProvides(ctx context.Context, group, version, WHERE api_provider.group_name = ? AND api_provider.version = ? AND api_provider.kind = ? AND package.default_channel = channel_entry.channel_name GROUP BY channel_entry.package_name, channel_entry.channel_name` - rows, err := s.db.QueryContext(ctx, query, group, version, kind) + rows, err := s.db.QueryContext(ctx, query, group, apiVersion, kind) if err != nil { return nil, err } + defer rows.Close() if !rows.Next() { - return nil, fmt.Errorf("no entry found that provides %s %s %s", group, version, kind) + return nil, fmt.Errorf("no entry found that provides %s %s %s", group, apiVersion, kind) } var entryId sql.NullInt64 var bundle sql.NullString @@ -373,12 +398,14 @@ func (s *SQLQuerier) GetBundleThatProvides(ctx context.Context, group, version, var pkgName sql.NullString var channelName sql.NullString var replaces sql.NullString - if err := rows.Scan(&entryId, &bundle, &bundlePath, &min_depth, &bundleName, &pkgName, &channelName, &replaces); err != nil { + var version sql.NullString + var skipRange sql.NullString + if err := rows.Scan(&entryId, &bundle, &bundlePath, &min_depth, &bundleName, &pkgName, &channelName, &replaces, &version, &skipRange); err != nil { return nil, err } if !bundle.Valid { - return nil, fmt.Errorf("no entry found that provides %s %s %s", group, version, kind) + return nil, fmt.Errorf("no entry found that provides %s %s %s", group, apiVersion, kind) } out := &api.Bundle{} @@ -392,6 +419,8 @@ func (s *SQLQuerier) GetBundleThatProvides(ctx context.Context, group, version, out.PackageName = pkgName.String out.ChannelName = channelName.String out.BundlePath = bundlePath.String + out.Version = version.String + out.SkipRange = skipRange.String provided, required, err := s.GetApisForEntry(ctx, entryId.Int64) if err != nil { @@ -409,6 +438,8 @@ func (s *SQLQuerier) ListImages(ctx context.Context) ([]string, error) { if err != nil { return nil, err } + defer rows.Close() + images := []string{} for rows.Next() { var imgName sql.NullString @@ -428,6 +459,7 @@ func (s *SQLQuerier) GetImagesForBundle(ctx context.Context, csvName string) ([] if err != nil { return nil, err } + defer rows.Close() images := []string{} for rows.Next() { var imgName sql.NullString @@ -450,6 +482,7 @@ func (s *SQLQuerier) GetApisForEntry(ctx context.Context, entryId int64) (provid if err != nil { return nil,nil, err } + provided = []*api.GroupVersionKind{} for providedRows.Next() { var groupName sql.NullString @@ -470,6 +503,9 @@ func (s *SQLQuerier) GetApisForEntry(ctx context.Context, entryId int64) (provid Plural: pluralName.String, }) } + if err := providedRows.Close(); err != nil { + return nil, nil, err + } requiredQuery := `SELECT DISTINCT api.group_name, api.version, api.kind, api.plural FROM api INNER JOIN api_requirer ON (api.group_name=api_requirer.group_name AND api.version=api_requirer.version AND api.kind=api_requirer.kind) @@ -499,6 +535,9 @@ func (s *SQLQuerier) GetApisForEntry(ctx context.Context, entryId int64) (provid Plural: pluralName.String, }) } + if err := requiredRows.Close(); err != nil { + return nil, nil, err + } return } diff --git a/vendor/modules.txt b/vendor/modules.txt index cee85d7b2ba..9824a390b76 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -156,7 +156,7 @@ github.com/openshift/client-go/config/informers/externalversions/config github.com/openshift/client-go/config/informers/externalversions/config/v1 github.com/openshift/client-go/config/informers/externalversions/internalinterfaces github.com/openshift/client-go/config/listers/config/v1 -# github.com/operator-framework/operator-registry v1.5.1 +# github.com/operator-framework/operator-registry v1.5.1 => ../operator-registry github.com/operator-framework/operator-registry/pkg/api github.com/operator-framework/operator-registry/pkg/api/grpc_health_v1 github.com/operator-framework/operator-registry/pkg/client