Skip to content

Commit 87c3383

Browse files
committed
drop all sqlite support (and channel priority properties)
1 parent ca76c57 commit 87c3383

163 files changed

Lines changed: 33 additions & 58036 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ $(PROTOC):
2727
null :=
2828
space := $(null) #
2929
comma := ,
30-
# default to json1 for sqlite3 and containers_image_openpgp for containers/image
31-
TAGS := json1,containers_image_openpgp
30+
# default to containers_image_openpgp for containers/image
31+
TAGS := containers_image_openpgp
3232

3333
# Cluster to use for e2e testing
3434
CLUSTER ?= ""
@@ -62,8 +62,8 @@ build: clean $(CMDS) $(OPM)
6262
cross: opm_version_flags=-ldflags "-X '$(PKG)/cmd/opm/version.gitCommit=$(GIT_COMMIT)' -X '$(PKG)/cmd/opm/version.opmVersion=$(OPM_VERSION)' -X '$(PKG)/cmd/opm/version.buildDate=$(BUILD_DATE)'"
6363
cross:
6464
ifeq ($(shell go env GOARCH),amd64)
65-
GOOS=darwin CC=o64-clang CXX=o64-clang++ CGO_ENABLED=1 CGO_LDFLAGS='-Wl,-undefined,dynamic_lookup' $(GO) build $(opm_version_flags) -tags=$(TAGS) -o "bin/darwin-amd64-opm" --ldflags "-extld=o64-clang -extldflags=-Wl,-undefined,dynamic_lookup" ./cmd/opm
66-
GOOS=windows CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_ENABLED=1 $(GO) build $(opm_version_flags) -tags=$(TAGS) -o "bin/windows-amd64-opm" --ldflags "-extld=x86_64-w64-mingw32-gcc" -buildmode=exe ./cmd/opm
65+
GOOS=darwin CGO_ENABLED=0 $(GO) build $(opm_version_flags) -tags=$(TAGS) -o "bin/darwin-amd64-opm" ./cmd/opm
66+
GOOS=windows CGO_ENABLED=0 $(GO) build $(opm_version_flags) -tags=$(TAGS) -o "bin/windows-amd64-opm" -buildmode=exe ./cmd/opm
6767
endif
6868

6969
.PHONY: static

alpha/action/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (r *ListBundlesResult) WriteColumns(w io.Writer) error {
186186
func indexRefToModel(ctx context.Context, ref string, reg image.Registry) (model.Model, error) {
187187
render := Render{
188188
Refs: []string{ref},
189-
AllowedRefMask: RefDCImage | RefDCDir | RefSqliteImage | RefSqliteFile,
189+
AllowedRefMask: RefDCImage | RefDCDir,
190190
Registry: reg,
191191
}
192192
cfg, err := render.Run(ctx)

alpha/action/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (m Migrate) Run(ctx context.Context) error {
3434
Migrations: m.Migrations,
3535

3636
// Only allow catalogs to be migrated.
37-
AllowedRefMask: RefSqliteImage | RefSqliteFile | RefDCImage | RefDCDir,
37+
AllowedRefMask: RefDCImage | RefDCDir,
3838
}
3939
if m.Registry != nil {
4040
r.Registry = m.Registry

alpha/action/migrate_test.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import (
44
"context"
55
"io/fs"
66
"os"
7-
"path/filepath"
7+
"strings"
88
"testing"
99

1010
"github.com/stretchr/testify/require"
1111

1212
"github.com/operator-framework/operator-registry/alpha/action"
1313
"github.com/operator-framework/operator-registry/alpha/declcfg"
14-
"github.com/operator-framework/operator-registry/pkg/containertools"
1514
"github.com/operator-framework/operator-registry/pkg/image"
1615
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
1716
)
@@ -31,11 +30,6 @@ func TestMigrate(t *testing.T) {
3130
image.SimpleReference("test.registry/bar-operator/bar-bundle:v0.2.0"): "testdata/bar-bundle-v0.2.0",
3231
}
3332

34-
sqliteDBDir := t.TempDir()
35-
dbFile := filepath.Join(sqliteDBDir, "index.db")
36-
err := generateSqliteFile(dbFile, sqliteBundles)
37-
require.NoError(t, err)
38-
3933
reg, err := newMigrateRegistry(t, sqliteBundles)
4034
require.NoError(t, err)
4135

@@ -56,7 +50,7 @@ func TestMigrate(t *testing.T) {
5650
{
5751
name: "SqliteFile/Success",
5852
migrate: action.Migrate{
59-
CatalogRef: dbFile,
53+
CatalogRef: "dummy.db",
6054
WriteFunc: declcfg.WriteYAML,
6155
FileExt: ".yaml",
6256
Registry: reg,
@@ -117,6 +111,9 @@ func TestMigrate(t *testing.T) {
117111
}
118112
for _, s := range specs {
119113
t.Run(s.name, func(t *testing.T) {
114+
if strings.Contains(s.name, "Sqlite") {
115+
t.Skip("Skipping sqlite test - sqlite support removed")
116+
}
120117
s.migrate.OutputDir = t.TempDir()
121118

122119
err := s.migrate.Run(context.Background())
@@ -142,11 +139,6 @@ func TestMigrate(t *testing.T) {
142139
}
143140

144141
func newMigrateRegistry(t *testing.T, imageMap map[image.Reference]string) (image.Registry, error) {
145-
subSqliteImage, err := generateSqliteFS(t, imageMap)
146-
if err != nil {
147-
return nil, err
148-
}
149-
150142
subDeclcfgImage, err := fs.Sub(declcfgImage, "testdata/foo-index-v0.2.0-declcfg")
151143
if err != nil {
152144
return nil, err
@@ -158,12 +150,6 @@ func newMigrateRegistry(t *testing.T, imageMap map[image.Reference]string) (imag
158150
}
159151

160152
reg := &image.MockRegistry{RemoteImages: map[image.Reference]*image.MockImage{
161-
image.SimpleReference("test.registry/migrate/catalog:sqlite"): {
162-
Labels: map[string]string{
163-
containertools.DbLocationLabel: "/database/index.db",
164-
},
165-
FS: subSqliteImage,
166-
},
167153
image.SimpleReference("test.registry/foo-operator/foo-index-declcfg:v0.2.0"): {
168154
Labels: map[string]string{
169155
"operators.operatorframework.io.index.configs.v1": "/foo",

alpha/action/render.go

Lines changed: 3 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@ package action
22

33
import (
44
"context"
5-
"database/sql"
65
"encoding/json"
76
"errors"
87
"fmt"
98
"os"
109
"path/filepath"
1110
"sort"
1211
"strings"
13-
"sync"
1412
"text/template"
1513

16-
"github.com/h2non/filetype"
17-
"github.com/h2non/filetype/matchers"
1814
"k8s.io/apimachinery/pkg/util/sets"
1915

2016
"github.com/operator-framework/operator-registry/alpha/action/migrations"
@@ -25,17 +21,12 @@ import (
2521
"github.com/operator-framework/operator-registry/pkg/image/containersimageregistry"
2622
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
2723
"github.com/operator-framework/operator-registry/pkg/registry"
28-
"github.com/operator-framework/operator-registry/pkg/sqlite"
2924
)
3025

31-
var logDeprecationMessage sync.Once
32-
3326
type RefType uint
3427

3528
const (
3629
RefBundleImage RefType = 1 << iota
37-
RefSqliteImage
38-
RefSqliteFile
3930
RefDCImage
4031
RefDCDir
4132
RefBundleDir
@@ -55,15 +46,9 @@ type Render struct {
5546
AllowedRefMask RefType
5647
ImageRefTemplate *template.Template
5748
Migrations *migrations.Migrations
58-
59-
skipSqliteDeprecationLog bool
6049
}
6150

6251
func (r Render) Run(ctx context.Context) (*declcfg.DeclarativeConfig, error) {
63-
if r.skipSqliteDeprecationLog {
64-
// exhaust once with a no-op function.
65-
logDeprecationMessage.Do(func() {})
66-
}
6752
if r.Registry == nil {
6853
reg, err := containersimageregistry.NewDefault()
6954
if err != nil {
@@ -125,21 +110,8 @@ func (r Render) renderReference(ctx context.Context, ref string) (*declcfg.Decla
125110
}
126111
return declcfg.LoadFS(ctx, os.DirFS(ref))
127112
}
128-
// The only supported file type is an sqlite DB file,
129-
// since declarative configs will be in a directory.
130-
if err := checkDBFile(ref); err != nil {
131-
return nil, err
132-
}
133-
if !r.AllowedRefMask.Allowed(RefSqliteFile) {
134-
return nil, fmt.Errorf("cannot render sqlite file: %w", ErrNotAllowed)
135-
}
136-
137-
db, err := sqlite.Open(ref)
138-
if err != nil {
139-
return nil, err
140-
}
141-
defer db.Close()
142-
return sqliteToDeclcfg(ctx, db)
113+
// Only directories are supported for file-based catalogs and bundles.
114+
return nil, fmt.Errorf("ref %q is not a directory", ref)
143115
}
144116

145117
func (r Render) imageToDeclcfg(ctx context.Context, imageRef string) (*declcfg.DeclarativeConfig, error) {
@@ -161,21 +133,7 @@ func (r Render) imageToDeclcfg(ctx context.Context, imageRef string) (*declcfg.D
161133
}
162134

163135
var cfg *declcfg.DeclarativeConfig
164-
// nolint:nestif
165-
if dbFile, ok := labels[containertools.DbLocationLabel]; ok {
166-
if !r.AllowedRefMask.Allowed(RefSqliteImage) {
167-
return nil, fmt.Errorf("cannot render sqlite image: %w", ErrNotAllowed)
168-
}
169-
db, err := sqlite.Open(filepath.Join(tmpDir, dbFile))
170-
if err != nil {
171-
return nil, err
172-
}
173-
defer db.Close()
174-
cfg, err = sqliteToDeclcfg(ctx, db)
175-
if err != nil {
176-
return nil, err
177-
}
178-
} else if configsDir, ok := labels[containertools.ConfigsLocationLabel]; ok {
136+
if configsDir, ok := labels[containertools.ConfigsLocationLabel]; ok {
179137
if !r.AllowedRefMask.Allowed(RefDCImage) {
180138
return nil, fmt.Errorf("cannot render declarative config image: %w", ErrNotAllowed)
181139
}
@@ -213,93 +171,6 @@ func (r Render) imageToDeclcfg(ctx context.Context, imageRef string) (*declcfg.D
213171
}
214172

215173
// checkDBFile returns an error if ref is not an sqlite3 database.
216-
func checkDBFile(ref string) error {
217-
typ, err := filetype.MatchFile(ref)
218-
if err != nil {
219-
return err
220-
}
221-
if typ != matchers.TypeSqlite {
222-
return fmt.Errorf("ref %q has unsupported file type: %s", ref, typ)
223-
}
224-
return nil
225-
}
226-
227-
func sqliteToDeclcfg(ctx context.Context, db *sql.DB) (*declcfg.DeclarativeConfig, error) {
228-
logDeprecationMessage.Do(func() {
229-
sqlite.LogSqliteDeprecation()
230-
})
231-
232-
migrator, err := sqlite.NewSQLLiteMigrator(db)
233-
if err != nil {
234-
return nil, err
235-
}
236-
if migrator == nil {
237-
return nil, fmt.Errorf("failed to load migrator")
238-
}
239-
240-
if err := migrator.Migrate(ctx); err != nil {
241-
return nil, err
242-
}
243-
244-
q := sqlite.NewSQLLiteQuerierFromDb(db)
245-
m, err := sqlite.ToModel(ctx, q)
246-
if err != nil {
247-
return nil, err
248-
}
249-
250-
cfg := declcfg.ConvertFromModel(m)
251-
252-
if err := populateDBRelatedImages(ctx, &cfg, db); err != nil {
253-
return nil, err
254-
}
255-
256-
return &cfg, nil
257-
}
258-
259-
func populateDBRelatedImages(ctx context.Context, cfg *declcfg.DeclarativeConfig, db *sql.DB) error {
260-
rows, err := db.QueryContext(ctx, "SELECT image, operatorbundle_name FROM related_image")
261-
if err != nil {
262-
return err
263-
}
264-
defer rows.Close()
265-
266-
// nolint:staticcheck
267-
images := map[string]sets.String{}
268-
for rows.Next() {
269-
var (
270-
img sql.NullString
271-
bundleName sql.NullString
272-
)
273-
if err := rows.Scan(&img, &bundleName); err != nil {
274-
return err
275-
}
276-
if !img.Valid || !bundleName.Valid {
277-
continue
278-
}
279-
m, ok := images[bundleName.String]
280-
if !ok {
281-
m = sets.NewString()
282-
}
283-
m.Insert(img.String)
284-
images[bundleName.String] = m
285-
}
286-
287-
for i, b := range cfg.Bundles {
288-
ris, ok := images[b.Name]
289-
if !ok {
290-
continue
291-
}
292-
for _, ri := range b.RelatedImages {
293-
if ris.Has(ri.Image) {
294-
ris.Delete(ri.Image)
295-
}
296-
}
297-
for ri := range ris {
298-
cfg.Bundles[i].RelatedImages = append(cfg.Bundles[i].RelatedImages, declcfg.RelatedImage{Image: ri})
299-
}
300-
}
301-
return nil
302-
}
303174

304175
func bundleToDeclcfg(bundle *registry.Bundle) (*declcfg.Bundle, error) {
305176
objs, props, err := registry.ObjectsAndPropertiesFromBundle(bundle)

0 commit comments

Comments
 (0)