Skip to content

Commit bce439e

Browse files
committed
Compose registry client & interface under a new interface
1. Compose client.Client and client.Interface (registry) under a new RegitryClientInterface so they can use all funcs from both sides in one place. 2. Update unit and e2e tests with new changes Signed-off-by: Vu Dinh <[email protected]>
1 parent 4428e04 commit bce439e

File tree

7 files changed

+640
-127
lines changed

7 files changed

+640
-127
lines changed

pkg/controller/registry/grpc/source.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,8 @@ func (s *SourceStore) Remove(key resolver.CatalogKey) error {
191191
return source.Conn.Close()
192192
}
193193

194-
func (s *SourceStore) AsClients(namespaces ...string) (map[resolver.CatalogKey]client.Interface, map[resolver.CatalogKey]registry.RegistryClientInterface) {
195-
refsInterface := map[resolver.CatalogKey]client.Interface{}
196-
refsClient := map[resolver.CatalogKey]registry.RegistryClientInterface{}
194+
func (s *SourceStore) AsClients(namespaces ...string) map[resolver.CatalogKey]registry.RegistryClientInterface {
195+
refs := map[resolver.CatalogKey]registry.RegistryClientInterface{}
197196
s.sourcesLock.RLock()
198197
defer s.sourcesLock.RUnlock()
199198
for key, source := range s.sources {
@@ -202,13 +201,12 @@ func (s *SourceStore) AsClients(namespaces ...string) (map[resolver.CatalogKey]c
202201
}
203202
for _, namespace := range namespaces {
204203
if key.Namespace == namespace {
205-
refsInterface[key] = client.NewClientFromConn(source.Conn)
206-
refsClient[key] = registry.NewRegistryClient(client.NewClientFromConn(source.Conn))
204+
refs[key] = registry.NewRegistryClient(client.NewClientFromConn(source.Conn))
207205
}
208206
}
209207
refs[key] = client.NewClientFromConn(source.Conn)
210208
}
211209

212210
// TODO : remove unhealthy
213-
return refsInterface, refsClient
211+
return refs
214212
}

pkg/controller/registry/registry_client.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type ChannelEntryStream interface {
1616
}
1717

1818
type RegistryClientInterface interface {
19+
client.Interface
1920
FindBundleThatProvides(ctx context.Context, group, version, kind, pkgName string) (*registryapi.Bundle, error)
2021
GetLatestChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (*ChannelEntryIterator, error)
2122
}
@@ -47,19 +48,21 @@ func (ceit *ChannelEntryIterator) Error() error {
4748
return ceit.error
4849
}
4950

50-
type OLMRegistryClient struct {
51+
type RegistryClient struct {
52+
client.Interface
5153
Client *client.Client
5254
}
5355

54-
func NewRegistryClient(client *client.Client) *OLMRegistryClient {
55-
return &OLMRegistryClient{Client: client}
56+
func NewRegistryClient(client *client.Client) *RegistryClient {
57+
return &RegistryClient{client, client}
5658
}
5759

58-
var _ RegistryClientInterface = &OLMRegistryClient{}
60+
var _ RegistryClientInterface = &RegistryClient{}
61+
var _ client.Interface = &RegistryClient{}
5962

6063
// GetLatestChannelEntriesThatProvide uses registry client to get a list of
6164
// latest channel entries that provide the requested API (via an iterator)
62-
func (rc *OLMRegistryClient) GetLatestChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (*ChannelEntryIterator, error) {
65+
func (rc *RegistryClient) GetLatestChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (*ChannelEntryIterator, error) {
6366
stream, err := rc.Client.Registry.GetLatestChannelEntriesThatProvide(ctx, &registryapi.GetLatestProvidersRequest{Group: group, Version: version, Kind: kind})
6467
if err != nil {
6568
return nil, err
@@ -69,7 +72,7 @@ func (rc *OLMRegistryClient) GetLatestChannelEntriesThatProvide(ctx context.Cont
6972

7073
// FindBundleThatProvides returns a bundle that provides the request API and
7174
// doesn't belong to the provided package
72-
func (rc *OLMRegistryClient) FindBundleThatProvides(ctx context.Context, group, version, kind, pkgName string) (*registryapi.Bundle, error) {
75+
func (rc *RegistryClient) FindBundleThatProvides(ctx context.Context, group, version, kind, pkgName string) (*registryapi.Bundle, error) {
7376
it, err := rc.GetLatestChannelEntriesThatProvide(ctx, group, version, kind)
7477
if err != nil {
7578
return nil, err
@@ -88,18 +91,22 @@ func (rc *OLMRegistryClient) FindBundleThatProvides(ctx context.Context, group,
8891
// FilterChannelEntries filters out a channel entries that provide the requested
8992
// API and come from the same package with original operator and returns the
9093
// first entry on the list
91-
func (rc *OLMRegistryClient) filterChannelEntries(it *ChannelEntryIterator, pkgName string) *opregistry.ChannelEntry {
92-
var entry *opregistry.ChannelEntry
94+
func (rc *RegistryClient) filterChannelEntries(it *ChannelEntryIterator, pkgName string) *opregistry.ChannelEntry {
95+
var entries []*opregistry.ChannelEntry
9396
for e := it.Next(); e != nil; e = it.Next() {
9497
if e.PackageName != pkgName {
95-
entry = &opregistry.ChannelEntry{
98+
entry := &opregistry.ChannelEntry{
9699
PackageName: e.PackageName,
97100
ChannelName: e.ChannelName,
98101
BundleName: e.BundleName,
99102
Replaces: e.Replaces,
100103
}
101-
break
104+
entries = append(entries, entry)
102105
}
103106
}
104-
return entry
107+
108+
if entries != nil {
109+
return entries[0]
110+
}
111+
return nil
105112
}

0 commit comments

Comments
 (0)