Skip to content

Commit d090428

Browse files
Merge pull request #103 from anik120/image-digests2
Image digests for referencing bundles
2 parents 161f66a + 748192e commit d090428

File tree

13 files changed

+335
-154
lines changed

13 files changed

+335
-154
lines changed

pkg/api/conversion.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func BundleStringToObjectStrings(bundleString string) ([]string, error) {
5555
return objs, nil
5656
}
5757

58-
func BundleStringToAPIBundle(bundleString string, entry *registry.ChannelEntry) (*Bundle, error) {
58+
func BundleStringToAPIBundle(bundleString string, bundlepathString string, entry *registry.ChannelEntry) (*Bundle, error) {
5959
objs, err := BundleStringToObjectStrings(bundleString)
6060
if err != nil {
6161
return nil, err
@@ -80,5 +80,6 @@ func BundleStringToAPIBundle(bundleString string, entry *registry.ChannelEntry)
8080
}
8181
out.ChannelName = entry.ChannelName
8282
out.PackageName = entry.PackageName
83+
out.BundlePath = bundlepathString
8384
return out, nil
8485
}

pkg/api/registry.pb.go

Lines changed: 149 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/registry.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ message Bundle{
3636
string channelName = 3;
3737
string csvJson = 4;
3838
repeated string object = 5;
39+
string bundlePath = 6;
3940
}
4041

4142
message ChannelEntry{

pkg/registry/empty.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ func (EmptyQuery) GetPackage(ctx context.Context, name string) (*PackageManifest
2222
return nil, errors.New("empty querier: cannot get package")
2323
}
2424

25-
func (EmptyQuery) GetBundle(ctx context.Context, pkgName, channelName, csvName string) (string, error) {
26-
return "", errors.New("empty querier: cannot get bundle")
25+
func (EmptyQuery) GetBundle(ctx context.Context, pkgName, channelName, csvName string) (string, string, error) {
26+
return "", "", errors.New("empty querier: cannot get bundle")
2727
}
2828

29-
func (EmptyQuery) GetBundleForChannel(ctx context.Context, pkgName string, channelName string) (string, error) {
30-
return "", errors.New("empty querier: cannot get bundle for channel")
29+
func (EmptyQuery) GetBundleForChannel(ctx context.Context, pkgName string, channelName string) (string, string, error) {
30+
return "", "", errors.New("empty querier: cannot get bundle for channel")
3131
}
3232

3333
func (EmptyQuery) GetChannelEntriesThatReplace(ctx context.Context, name string) (entries []*ChannelEntry, err error) {
3434
return nil, errors.New("empty querier: cannot get channel entries that replace")
3535
}
3636

37-
func (EmptyQuery) GetBundleThatReplaces(ctx context.Context, name, pkgName, channelName string) (string, error) {
38-
return "", errors.New("empty querier: cannot get bundle that replaces")
37+
func (EmptyQuery) GetBundleThatReplaces(ctx context.Context, name, pkgName, channelName string) (string, string, error) {
38+
return "", "", errors.New("empty querier: cannot get bundle that replaces")
3939
}
4040

4141
func (EmptyQuery) GetChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (entries []*ChannelEntry, err error) {
@@ -46,8 +46,8 @@ func (EmptyQuery) GetLatestChannelEntriesThatProvide(ctx context.Context, group,
4646
return nil, errors.New("empty querier: cannot get latest channel entries that provide")
4747
}
4848

49-
func (EmptyQuery) GetBundleThatProvides(ctx context.Context, group, version, kind string) (string, *ChannelEntry, error) {
50-
return "", nil, errors.New("empty querier: cannot get bundle that provides")
49+
func (EmptyQuery) GetBundleThatProvides(ctx context.Context, group, version, kind string) (string, string, *ChannelEntry, error) {
50+
return "", "", nil, errors.New("empty querier: cannot get bundle that provides")
5151
}
5252

5353
func (EmptyQuery) ListImages(ctx context.Context) ([]string, error) {

pkg/registry/interface.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ type Query interface {
1313
ListTables(ctx context.Context) ([]string, error)
1414
ListPackages(ctx context.Context) ([]string, error)
1515
GetPackage(ctx context.Context, name string) (*PackageManifest, error)
16-
GetBundle(ctx context.Context, pkgName, channelName, csvName string) (string, error)
17-
GetBundleForChannel(ctx context.Context, pkgName string, channelName string) (string, error)
16+
GetBundle(ctx context.Context, pkgName, channelName, csvName string) (string, string, error)
17+
GetBundleForChannel(ctx context.Context, pkgName string, channelName string) (string, string, error)
1818
// Get all channel entries that say they replace this one
1919
GetChannelEntriesThatReplace(ctx context.Context, name string) (entries []*ChannelEntry, err error)
2020
// Get the bundle in a package/channel that replace this one
21-
GetBundleThatReplaces(ctx context.Context, name, pkgName, channelName string) (string, error)
21+
GetBundleThatReplaces(ctx context.Context, name, pkgName, channelName string) (string, string, error)
2222
// Get all channel entries that provide an api
2323
GetChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (entries []*ChannelEntry, err error)
2424
// Get latest channel entries that provide an api
2525
GetLatestChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (entries []*ChannelEntry, err error)
2626
// Get the the latest bundle that provides the API in a default channel
27-
GetBundleThatProvides(ctx context.Context, group, version, kind string) (string, *ChannelEntry, error)
27+
GetBundleThatProvides(ctx context.Context, group, version, kind string) (string, string, *ChannelEntry, error)
2828
// List all images in the database
2929
ListImages(ctx context.Context) ([]string, error)
3030
// List all images for a particular bundle

pkg/server/server.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,40 @@ func (s *RegistryServer) GetPackage(ctx context.Context, req *api.GetPackageRequ
3939
}
4040

4141
func (s *RegistryServer) GetBundle(ctx context.Context, req *api.GetBundleRequest) (*api.Bundle, error) {
42-
bundleString, err := s.store.GetBundle(ctx, req.GetPkgName(), req.GetChannelName(), req.GetCsvName())
42+
bundleString, bundlepathString, err := s.store.GetBundle(ctx, req.GetPkgName(), req.GetChannelName(), req.GetCsvName())
4343
if err != nil {
4444
return nil, err
4545
}
46+
// If the value of the `bundle` field in the OperatorBundle table is NULL, return a
47+
// Bundle struct with available fields
48+
if bundleString == "" {
49+
bundle := &api.Bundle{
50+
PackageName: req.PkgName,
51+
ChannelName: req.ChannelName,
52+
CsvName: req.CsvName,
53+
CsvJson: "",
54+
Object: []string{},
55+
BundlePath: bundlepathString,
56+
}
57+
return bundle, nil
58+
}
4659
entry := &registry.ChannelEntry{
4760
PackageName: req.GetPkgName(),
4861
ChannelName: req.GetChannelName(),
4962
}
50-
return api.BundleStringToAPIBundle(bundleString, entry)
63+
return api.BundleStringToAPIBundle(bundleString, bundlepathString, entry)
5164
}
5265

5366
func (s *RegistryServer) GetBundleForChannel(ctx context.Context, req *api.GetBundleInChannelRequest) (*api.Bundle, error) {
54-
bundleString, err := s.store.GetBundleForChannel(ctx, req.GetPkgName(), req.GetChannelName())
67+
bundleString, bundlepathString, err := s.store.GetBundleForChannel(ctx, req.GetPkgName(), req.GetChannelName())
5568
if err != nil {
5669
return nil, err
5770
}
5871
entry := &registry.ChannelEntry{
5972
PackageName: req.GetPkgName(),
6073
ChannelName: req.GetChannelName(),
6174
}
62-
return api.BundleStringToAPIBundle(bundleString, entry)
75+
return api.BundleStringToAPIBundle(bundleString, bundlepathString, entry)
6376
}
6477

6578
func (s *RegistryServer) GetChannelEntriesThatReplace(req *api.GetAllReplacementsRequest, stream api.Registry_GetChannelEntriesThatReplaceServer) error {
@@ -76,7 +89,7 @@ func (s *RegistryServer) GetChannelEntriesThatReplace(req *api.GetAllReplacement
7689
}
7790

7891
func (s *RegistryServer) GetBundleThatReplaces(ctx context.Context, req *api.GetReplacementRequest) (*api.Bundle, error) {
79-
bundleString, err := s.store.GetBundleThatReplaces(ctx, req.GetCsvName(), req.GetPkgName(), req.GetChannelName())
92+
bundleString, bundlepathString, err := s.store.GetBundleThatReplaces(ctx, req.GetCsvName(), req.GetPkgName(), req.GetChannelName())
8093
if err != nil {
8194
return nil, err
8295
}
@@ -85,7 +98,7 @@ func (s *RegistryServer) GetBundleThatReplaces(ctx context.Context, req *api.Get
8598
ChannelName: req.GetChannelName(),
8699
Replaces: req.GetCsvName(),
87100
}
88-
return api.BundleStringToAPIBundle(bundleString, entry)
101+
return api.BundleStringToAPIBundle(bundleString, bundlepathString, entry)
89102
}
90103

91104
func (s *RegistryServer) GetChannelEntriesThatProvide(req *api.GetAllProvidersRequest, stream api.Registry_GetChannelEntriesThatProvideServer) error {
@@ -115,9 +128,9 @@ func (s *RegistryServer) GetLatestChannelEntriesThatProvide(req *api.GetLatestPr
115128
}
116129

117130
func (s *RegistryServer) GetDefaultBundleThatProvides(ctx context.Context, req *api.GetDefaultProviderRequest) (*api.Bundle, error) {
118-
bundleString, channelEntry, err := s.store.GetBundleThatProvides(ctx, req.GetGroup(), req.GetVersion(), req.GetKind())
131+
bundleString, bundlepathString, channelEntry, err := s.store.GetBundleThatProvides(ctx, req.GetGroup(), req.GetVersion(), req.GetKind())
119132
if err != nil {
120133
return nil, err
121134
}
122-
return api.BundleStringToAPIBundle(bundleString, channelEntry)
135+
return api.BundleStringToAPIBundle(bundleString, bundlepathString, channelEntry)
123136
}

pkg/server/server_test.go

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.

pkg/sqlite/configmap_test.go

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

pkg/sqlite/directory_test.go

Lines changed: 6 additions & 4 deletions
Large diffs are not rendered by default.

pkg/sqlite/load.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *SQLLoader) AddOperatorBundle(bundle *registry.Bundle) error {
5656
tx.Rollback()
5757
}()
5858

59-
stmt, err := tx.Prepare("insert into operatorbundle(name, csv, bundle) values(?, ?, ?)")
59+
stmt, err := tx.Prepare("insert into operatorbundle(name, csv, bundle, bundlepath) values(?, ?, ?, ?)")
6060
if err != nil {
6161
return err
6262
}
@@ -77,7 +77,7 @@ func (s *SQLLoader) AddOperatorBundle(bundle *registry.Bundle) error {
7777
return fmt.Errorf("csv name not found")
7878
}
7979

80-
if _, err := stmt.Exec(csvName, csvBytes, bundleBytes); err != nil {
80+
if _, err := stmt.Exec(csvName, csvBytes, bundleBytes, nil); err != nil {
8181
return err
8282
}
8383

0 commit comments

Comments
 (0)