Skip to content

Commit 2c94486

Browse files
Merge pull request #20 from njhale/get-bundle
feat(bundles): add GetBundle request
2 parents 525487b + 6a477e1 commit 2c94486

File tree

9 files changed

+182
-59
lines changed

9 files changed

+182
-59
lines changed

pkg/api/registry.pb.go

Lines changed: 107 additions & 57 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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ package api;
44

55
service Registry {
66
rpc ListPackages(ListPackageRequest) returns (stream PackageName) {}
7-
rpc GetPackage(GetPackageRequest) returns (Package) {}
7+
rpc GetPackage(GetPackageRequest) returns (Package) {}
8+
rpc GetBundle(GetBundleRequest) returns (Bundle) {}
89
rpc GetBundleForChannel(GetBundleInChannelRequest) returns (Bundle) {}
910
rpc GetChannelEntriesThatReplace(GetAllReplacementsRequest) returns (stream ChannelEntry) {}
1011
rpc GetBundleThatReplaces(GetReplacementRequest) returns (Bundle) {}
@@ -51,7 +52,9 @@ message GetPackageRequest{
5152
}
5253

5354
message GetBundleRequest{
54-
string csvName = 1;
55+
string pkgName = 1;
56+
string channelName = 2;
57+
string csvName = 3;
5558
}
5659

5760
message GetBundleInChannelRequest{

pkg/client/client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
type Interface interface {
14+
GetBundle(ctx context.Context, packageName, channelName, csvName string) (*registry.Bundle, error)
1415
GetBundleInPackageChannel(ctx context.Context, packageName, channelName string) (*registry.Bundle, error)
1516
GetReplacementBundleInPackageChannel(ctx context.Context, currentName, packageName, channelName string) (*registry.Bundle, error)
1617
GetBundleThatProvides(ctx context.Context, group, version, kind string) (*registry.Bundle, error)
@@ -24,6 +25,14 @@ type Client struct {
2425

2526
var _ Interface = &Client{}
2627

28+
func (c *Client) GetBundle(ctx context.Context, packageName, channelName, csvName string) (*registry.Bundle, error) {
29+
bundle, err := c.Registry.GetBundle(ctx, &api.GetBundleRequest{PkgName: packageName, ChannelName: channelName, CsvName: csvName})
30+
if err != nil {
31+
return nil, err
32+
}
33+
return registry.NewBundleFromStrings(bundle.CsvName, bundle.PackageName, bundle.ChannelName, bundle.Object)
34+
}
35+
2736
func (c *Client) GetBundleInPackageChannel(ctx context.Context, packageName, channelName string) (*registry.Bundle, error) {
2837
bundle, err := c.Registry.GetBundleForChannel(ctx, &api.GetBundleInChannelRequest{PkgName: packageName, ChannelName: channelName})
2938
if err != nil {

pkg/registry/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type Query interface {
1414
ListTables(ctx context.Context) ([]string, error)
1515
ListPackages(ctx context.Context) ([]string, error)
1616
GetPackage(ctx context.Context, name string) (*PackageManifest, error)
17+
GetBundle(ctx context.Context, pkgName, channelName, csvName string) (string, error)
1718
GetBundleForChannel(ctx context.Context, pkgName string, channelName string) (string, error)
1819
// Get all channel entries that say they replace this one
1920
GetChannelEntriesThatReplace(ctx context.Context, name string) (entries []*ChannelEntry, err error)

pkg/server/server.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ func (s *RegistryServer) GetPackage(ctx context.Context, req *api.GetPackageRequ
3838
return api.PackageManifestToAPIPackage(packageManifest), nil
3939
}
4040

41+
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())
43+
if err != nil {
44+
return nil, err
45+
}
46+
entry := &registry.ChannelEntry{
47+
PackageName: req.GetPkgName(),
48+
ChannelName: req.GetChannelName(),
49+
}
50+
return api.BundleStringToAPIBundle(bundleString, entry)
51+
}
52+
4153
func (s *RegistryServer) GetBundleForChannel(ctx context.Context, req *api.GetBundleInChannelRequest) (*api.Bundle, error) {
4254
bundleString, err := s.store.GetBundleForChannel(ctx, req.GetPkgName(), req.GetChannelName())
4355
if err != nil {

pkg/server/server_test.go

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

pkg/sqlite/configmap_test.go

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

pkg/sqlite/directory_test.go

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

pkg/sqlite/query.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ func (s *SQLQuerier) GetPackage(ctx context.Context, name string) (*registry.Pac
103103
return pkg, nil
104104
}
105105

106+
func (s *SQLQuerier) GetBundle(ctx context.Context, pkgName, channelName, csvName string) (string, error) {
107+
query := `SELECT DISTINCT operatorbundle.bundle
108+
FROM operatorbundle INNER JOIN channel_entry ON operatorbundle.name=channel_entry.operatorbundle_name
109+
WHERE channel_entry.package_name=? AND channel_entry.channel_name=? AND operatorbundle.name=? LIMIT 1`
110+
rows, err := s.db.QueryContext(ctx, query, pkgName, channelName, csvName)
111+
if err != nil {
112+
return "", err
113+
}
114+
115+
if !rows.Next() {
116+
return "", fmt.Errorf("no bundle found for csv %s", csvName)
117+
}
118+
var bundleStringSQL sql.NullString
119+
if err := rows.Scan(&bundleStringSQL); err != nil {
120+
return "", err
121+
}
122+
return bundleStringSQL.String, nil
123+
}
124+
106125
func (s *SQLQuerier) GetBundleForChannel(ctx context.Context, pkgName string, channelName string) (string, error) {
107126
query := `SELECT DISTINCT operatorbundle.bundle
108127
FROM channel INNER JOIN operatorbundle ON channel.head_operatorbundle_name=operatorbundle.name

0 commit comments

Comments
 (0)