Skip to content

Commit 518e9be

Browse files
committed
refactor(schema): split groupOrName into group and plural fields
- Split all groupOrName references into group and plural - Change SQL schema to match - Regen protobuf
1 parent 0fb42be commit 518e9be

File tree

13 files changed

+194
-143
lines changed

13 files changed

+194
-143
lines changed

pkg/api/conversion.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"k8s.io/apimachinery/pkg/util/yaml"
1111
)
1212

13-
func PackageManifestToApiPackage(manifest *registry.PackageManifest) *Package {
13+
func PackageManifestToAPIPackage(manifest *registry.PackageManifest) *Package {
1414
channels := []*Channel{}
1515
for _, c := range manifest.Channels {
16-
channels = append(channels, PackageChannelToApiChannel(&c))
16+
channels = append(channels, PackageChannelToAPIChannel(&c))
1717
}
1818
return &Package{
1919
Name: manifest.PackageName,
@@ -22,14 +22,14 @@ func PackageManifestToApiPackage(manifest *registry.PackageManifest) *Package {
2222
}
2323
}
2424

25-
func PackageChannelToApiChannel(channel *registry.PackageChannel) *Channel {
25+
func PackageChannelToAPIChannel(channel *registry.PackageChannel) *Channel {
2626
return &Channel{
2727
Name: channel.Name,
2828
CsvName: channel.CurrentCSVName,
2929
}
3030
}
3131

32-
func ChannelEntryToApiChannelEntry(entry *registry.ChannelEntry) *ChannelEntry {
32+
func ChannelEntryToAPIChannelEntry(entry *registry.ChannelEntry) *ChannelEntry {
3333
return &ChannelEntry{
3434
PackageName: entry.PackageName,
3535
ChannelName: entry.ChannelName,
@@ -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, entry *registry.ChannelEntry) (*Bundle, error) {
5959
objs, err := BundleStringToObjectStrings(bundleString)
6060
if err != nil {
6161
return nil, err

pkg/api/registry.pb.go

Lines changed: 89 additions & 64 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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,23 @@ message GetReplacementRequest{
7070
}
7171

7272
message GetAllProvidersRequest{
73-
string groupOrName = 1;
73+
string group = 1;
7474
string version = 2;
7575
string kind = 3;
76+
string plural = 4;
7677
}
7778

7879
message GetLatestProvidersRequest{
79-
string groupOrName = 1;
80+
string group = 1;
8081
string version = 2;
8182
string kind = 3;
83+
string plural = 4;
8284
}
8385

8486
message GetDefaultProviderRequest{
85-
string groupOrName = 1;
87+
string group = 1;
8688
string version = 2;
8789
string kind = 3;
90+
string plural = 4;
8891
}
8992

pkg/client/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
type Interface interface {
1414
GetBundleInPackageChannel(ctx context.Context, packageName, channelName string) (*registry.Bundle, error)
1515
GetReplacementBundleInPackageChannel(ctx context.Context, currentName, packageName, channelName string) (*registry.Bundle, error)
16-
GetBundleThatProvides(ctx context.Context, groupOrName, version, kind string) (*registry.Bundle, error)
16+
GetBundleThatProvides(ctx context.Context, group, version, kind string) (*registry.Bundle, error)
1717
}
1818

1919
type Client struct {
@@ -40,8 +40,8 @@ func (c *Client) GetReplacementBundleInPackageChannel(ctx context.Context, curre
4040
return registry.NewBundleFromStrings(bundle.CsvName, packageName, channelName, bundle.Object)
4141
}
4242

43-
func (c *Client) GetBundleThatProvides(ctx context.Context, groupOrName, version, kind string) (*registry.Bundle, error) {
44-
bundle, err := c.client.GetDefaultBundleThatProvides(ctx, &api.GetDefaultProviderRequest{GroupOrName: groupOrName, Version: version, Kind: kind})
43+
func (c *Client) GetBundleThatProvides(ctx context.Context, group, version, kind string) (*registry.Bundle, error) {
44+
bundle, err := c.client.GetDefaultBundleThatProvides(ctx, &api.GetDefaultProviderRequest{Group: group, Version: version, Kind: kind})
4545
if err != nil {
4646
return nil, err
4747
}

pkg/registry/interface.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
type Load interface {
88
AddOperatorBundle(bundle *Bundle) error
99
AddPackageChannels(manifest PackageManifest) error
10-
AddProvidedApis() error
10+
AddProvidedAPIs() error
1111
}
1212

1313
type Query interface {
@@ -20,9 +20,9 @@ type Query interface {
2020
// Get the bundle in a package/channel that replace this one
2121
GetBundleThatReplaces(ctx context.Context, name, pkgName, channelName string) (string, error)
2222
// Get all channel entries that provide an api
23-
GetChannelEntriesThatProvide(ctx context.Context, groupOrName, version, kind string) (entries []*ChannelEntry, err error)
23+
GetChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (entries []*ChannelEntry, err error)
2424
// Get latest channel entries that provide an api
25-
GetLatestChannelEntriesThatProvide(ctx context.Context, groupOrName, version, kind string) (entries []*ChannelEntry, err error)
25+
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, groupOrName, version, kind string) (string, *ChannelEntry, error)
27+
GetBundleThatProvides(ctx context.Context, group, version, kind string) (string, *ChannelEntry, error)
2828
}

pkg/server/server.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (s *RegistryServer) GetPackage(ctx context.Context, req *api.GetPackageRequ
3535
if err != nil {
3636
return nil, err
3737
}
38-
return api.PackageManifestToApiPackage(packageManifest), nil
38+
return api.PackageManifestToAPIPackage(packageManifest), nil
3939
}
4040

4141
func (s *RegistryServer) GetBundleForChannel(ctx context.Context, req *api.GetBundleInChannelRequest) (*api.Bundle, error) {
@@ -47,7 +47,7 @@ func (s *RegistryServer) GetBundleForChannel(ctx context.Context, req *api.GetBu
4747
PackageName: req.GetPkgName(),
4848
ChannelName: req.GetChannelName(),
4949
}
50-
return api.BundleStringToApiBundle(bundleString, entry)
50+
return api.BundleStringToAPIBundle(bundleString, entry)
5151
}
5252

5353
func (s *RegistryServer) GetChannelEntriesThatReplace(req *api.GetAllReplacementsRequest, stream api.Registry_GetChannelEntriesThatReplaceServer) error {
@@ -56,7 +56,7 @@ func (s *RegistryServer) GetChannelEntriesThatReplace(req *api.GetAllReplacement
5656
return err
5757
}
5858
for _, e := range channelEntries {
59-
if err := stream.Send(api.ChannelEntryToApiChannelEntry(e)); err != nil {
59+
if err := stream.Send(api.ChannelEntryToAPIChannelEntry(e)); err != nil {
6060
return err
6161
}
6262
}
@@ -71,41 +71,41 @@ func (s *RegistryServer) GetBundleThatReplaces(ctx context.Context, req *api.Get
7171
entry := &registry.ChannelEntry{
7272
PackageName: req.GetPkgName(),
7373
ChannelName: req.GetChannelName(),
74-
Replaces: req.GetCsvName(),
74+
Replaces: req.GetCsvName(),
7575
}
76-
return api.BundleStringToApiBundle(bundleString, entry)
76+
return api.BundleStringToAPIBundle(bundleString, entry)
7777
}
7878

7979
func (s *RegistryServer) GetChannelEntriesThatProvide(req *api.GetAllProvidersRequest, stream api.Registry_GetChannelEntriesThatProvideServer) error {
80-
channelEntries, err := s.store.GetChannelEntriesThatProvide(stream.Context(), req.GetGroupOrName(), req.GetVersion(), req.GetKind())
80+
channelEntries, err := s.store.GetChannelEntriesThatProvide(stream.Context(), req.GetGroup(), req.GetVersion(), req.GetKind())
8181
if err != nil {
8282
return err
8383
}
8484
for _, e := range channelEntries {
85-
if err := stream.Send(api.ChannelEntryToApiChannelEntry(e)); err != nil {
85+
if err := stream.Send(api.ChannelEntryToAPIChannelEntry(e)); err != nil {
8686
return err
8787
}
8888
}
8989
return nil
9090
}
9191

9292
func (s *RegistryServer) GetLatestChannelEntriesThatProvide(req *api.GetLatestProvidersRequest, stream api.Registry_GetLatestChannelEntriesThatProvideServer) error {
93-
channelEntries, err := s.store.GetLatestChannelEntriesThatProvide(stream.Context(), req.GetGroupOrName(), req.GetVersion(), req.GetKind())
93+
channelEntries, err := s.store.GetLatestChannelEntriesThatProvide(stream.Context(), req.GetGroup(), req.GetVersion(), req.GetKind())
9494
if err != nil {
9595
return err
9696
}
9797
for _, e := range channelEntries {
98-
if err := stream.Send(api.ChannelEntryToApiChannelEntry(e)); err != nil {
98+
if err := stream.Send(api.ChannelEntryToAPIChannelEntry(e)); err != nil {
9999
return err
100100
}
101101
}
102102
return nil
103103
}
104104

105105
func (s *RegistryServer) GetDefaultBundleThatProvides(ctx context.Context, req *api.GetDefaultProviderRequest) (*api.Bundle, error) {
106-
bundleString, channelEntry, err := s.store.GetBundleThatProvides(ctx, req.GetGroupOrName(), req.GetVersion(), req.GetKind())
106+
bundleString, channelEntry, err := s.store.GetBundleThatProvides(ctx, req.GetGroup(), req.GetVersion(), req.GetKind())
107107
if err != nil {
108108
return nil, err
109109
}
110-
return api.BundleStringToApiBundle(bundleString, channelEntry)
110+
return api.BundleStringToAPIBundle(bundleString, channelEntry)
111111
}

pkg/server/server_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func TestGetChannelEntriesThatProvide(t *testing.T) {
197197
c, conn := client(t)
198198
defer conn.Close()
199199

200-
stream, err := c.GetChannelEntriesThatProvide(context.TODO(), &api.GetAllProvidersRequest{GroupOrName: "etcdclusters.etcd.database.coreos.com", Version: "v1beta2", Kind: "EtcdCluster"})
200+
stream, err := c.GetChannelEntriesThatProvide(context.TODO(), &api.GetAllProvidersRequest{Group: "etcd.database.coreos.com", Version: "v1beta2", Kind: "EtcdCluster"})
201201
require.NoError(t, err)
202202

203203
channelEntries := []*api.ChannelEntry{}
@@ -248,7 +248,7 @@ func TestGetLatestChannelEntriesThatProvide(t *testing.T) {
248248
c, conn := client(t)
249249
defer conn.Close()
250250

251-
stream, err := c.GetLatestChannelEntriesThatProvide(context.TODO(), &api.GetLatestProvidersRequest{GroupOrName: "etcdclusters.etcd.database.coreos.com", Version: "v1beta2", Kind: "EtcdCluster"})
251+
stream, err := c.GetLatestChannelEntriesThatProvide(context.TODO(), &api.GetLatestProvidersRequest{Group: "etcd.database.coreos.com", Version: "v1beta2", Kind: "EtcdCluster"})
252252
require.NoError(t, err)
253253

254254
channelEntries := []*api.ChannelEntry{}
@@ -287,7 +287,7 @@ func TestGetDefaultBundleThatProvides(t *testing.T) {
287287
c, conn := client(t)
288288
defer conn.Close()
289289

290-
bundle, err := c.GetDefaultBundleThatProvides(context.TODO(), &api.GetDefaultProviderRequest{GroupOrName: "etcdclusters.etcd.database.coreos.com", Version: "v1beta2", Kind: "EtcdCluster"})
290+
bundle, err := c.GetDefaultBundleThatProvides(context.TODO(), &api.GetDefaultProviderRequest{Group: "etcd.database.coreos.com", Version: "v1beta2", Kind: "EtcdCluster"})
291291
require.NoError(t, err)
292292
expected := &api.Bundle{
293293
CsvName: "etcdoperator.v0.9.2",

pkg/sqlite/configmap.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (c *ConfigMapLoader) Populate() error {
6868
crd.Spec.Versions = []v1beta1.CustomResourceDefinitionVersion{{Name: crd.Spec.Version, Served: true, Storage: true}}
6969
}
7070
for _, version := range crd.Spec.Versions {
71-
gvk := registry.APIKey{crd.Spec.Group, version.Name, crd.Spec.Names.Kind, crd.Spec.Names.Plural}
71+
gvk := registry.APIKey{Group: crd.Spec.Group, Version: version.Name, Kind: crd.Spec.Names.Kind, Plural: crd.Spec.Names.Plural}
7272
log.WithField("gvk", gvk).Debug("loading CRD")
7373
if _, ok := c.crds[gvk]; ok {
7474
log.WithField("gvk", gvk).Debug("crd added twice")
@@ -116,7 +116,7 @@ func (c *ConfigMapLoader) Populate() error {
116116
log.WithError(err).Debug("error parsing owned name")
117117
return fmt.Errorf("error parsing owned name")
118118
}
119-
gvk := registry.APIKey{split[1], owned.Version, owned.Kind, split[0]}
119+
gvk := registry.APIKey{Group: split[1], Version: owned.Version, Kind: owned.Kind, Plural: split[0]}
120120
if crdUnst, ok := c.crds[gvk]; !ok {
121121
log.WithField("gvk", gvk).WithError(err).Debug("couldn't find owned CRD in crd list")
122122
} else {
@@ -155,7 +155,7 @@ func (c *ConfigMapLoader) Populate() error {
155155
}
156156

157157
log.Info("extracting provided API information")
158-
if err := c.store.AddProvidedApis(); err != nil {
158+
if err := c.store.AddProvidedAPIs(); err != nil {
159159
return err
160160
}
161161
return nil

pkg/sqlite/configmap_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package sqlite
22

33
import (
44
"context"
5-
"github.com/operator-framework/operator-registry/pkg/registry"
65
"os"
76
"testing"
8-
7+
98
"github.com/sirupsen/logrus"
109
"github.com/stretchr/testify/require"
1110
"k8s.io/api/core/v1"
1211
"k8s.io/apimachinery/pkg/util/yaml"
12+
13+
"github.com/operator-framework/operator-registry/pkg/registry"
1314
)
1415

1516
func TestConfigMapLoader(t *testing.T) {
@@ -82,7 +83,7 @@ func TestQuerierForConfigmap(t *testing.T) {
8283
require.NoError(t, err)
8384
require.EqualValues(t, expectedBundle, etcdBundleByReplaces)
8485

85-
etcdChannelEntriesThatProvide, err := store.GetChannelEntriesThatProvide(context.TODO(), "etcdclusters.etcd.database.coreos.com", "v1beta2", "EtcdCluster")
86+
etcdChannelEntriesThatProvide, err := store.GetChannelEntriesThatProvide(context.TODO(), "etcd.database.coreos.com", "v1beta2", "EtcdCluster")
8687
require.ElementsMatch(t, []*registry.ChannelEntry{
8788
{"etcd", "alpha", "etcdoperator.v0.6.1", ""},
8889
{"etcd", "alpha", "etcdoperator.v0.9.0", "etcdoperator.v0.6.1"},
@@ -91,11 +92,11 @@ func TestQuerierForConfigmap(t *testing.T) {
9192
etcdChannelEntriesThatProvideAPIServer, err := store.GetChannelEntriesThatProvide(context.TODO(), "etcd.database.coreos.com", "v1beta2", "FakeEtcdObject")
9293
require.ElementsMatch(t, []*registry.ChannelEntry{{"etcd", "alpha", "etcdoperator.v0.9.0", "etcdoperator.v0.6.1"}}, etcdChannelEntriesThatProvideAPIServer)
9394

94-
etcdLatestChannelEntriesThatProvide, err := store.GetLatestChannelEntriesThatProvide(context.TODO(), "etcdclusters.etcd.database.coreos.com", "v1beta2", "EtcdCluster")
95+
etcdLatestChannelEntriesThatProvide, err := store.GetLatestChannelEntriesThatProvide(context.TODO(), "etcd.database.coreos.com", "v1beta2", "EtcdCluster")
9596
require.NoError(t, err)
9697
require.ElementsMatch(t, []*registry.ChannelEntry{{"etcd", "alpha", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"}}, etcdLatestChannelEntriesThatProvide)
9798

98-
etcdBundleByProvides, entry, err := store.GetBundleThatProvides(context.TODO(), "etcdclusters.etcd.database.coreos.com", "v1beta2", "EtcdCluster")
99+
etcdBundleByProvides, entry, err := store.GetBundleThatProvides(context.TODO(), "etcd.database.coreos.com", "v1beta2", "EtcdCluster")
99100
require.NoError(t, err)
100101
require.Equal(t, expectedBundle, etcdBundleByProvides)
101102
require.Equal(t, &registry.ChannelEntry{"etcd", "alpha","etcdoperator.v0.9.2", ""}, entry)

pkg/sqlite/directory.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ package sqlite
22

33
import (
44
"fmt"
5-
"github.com/operator-framework/operator-registry/pkg/schema"
65
"io/ioutil"
76
"os"
87
"path/filepath"
98
"strings"
109

1110
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
12-
"github.com/operator-framework/operator-registry/pkg/registry"
1311
"github.com/sirupsen/logrus"
14-
1512
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
16-
1713
"k8s.io/apimachinery/pkg/util/yaml"
1814
"k8s.io/client-go/kubernetes/scheme"
15+
16+
"github.com/operator-framework/operator-registry/pkg/registry"
17+
"github.com/operator-framework/operator-registry/pkg/schema"
1918
)
2019

2120
type SQLPopulator interface {
@@ -59,7 +58,7 @@ func (d *DirectoryLoader) Populate() error {
5958
}
6059

6160
log.Info("extracting provided API information")
62-
if err := d.store.AddProvidedApis(); err != nil {
61+
if err := d.store.AddProvidedAPIs(); err != nil {
6362
return err
6463
}
6564
return nil

0 commit comments

Comments
 (0)