1
- //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o resolver/fakes/fake_registry_client_interface.go . RegistryClientInterface
1
+ //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o resolver/fakes/fake_registry_client_interface.go . ClientInterface
2
2
package registry
3
3
4
4
import (
5
5
"context"
6
6
"fmt"
7
7
"io"
8
8
9
+ "google.golang.org/grpc"
10
+
9
11
registryapi "github.com/operator-framework/operator-registry/pkg/api"
10
12
"github.com/operator-framework/operator-registry/pkg/client"
11
13
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
12
14
)
13
15
16
+ // ChannelEntryStream interface
14
17
type ChannelEntryStream interface {
15
18
Recv () (* registryapi.ChannelEntry , error )
16
19
}
17
20
18
- type RegistryClientInterface interface {
21
+ // ClientInterface that extends client.Interface
22
+ type ClientInterface interface {
19
23
client.Interface
20
- FindBundleThatProvides (ctx context.Context , group , version , kind , pkgName string ) (* registryapi.Bundle , error )
24
+ FindBundleThatProvides (ctx context.Context , group , version , kind , excludedPkgName string ) (* registryapi.Bundle , error )
21
25
GetLatestChannelEntriesThatProvide (ctx context.Context , group , version , kind string ) (* ChannelEntryIterator , error )
22
26
}
23
27
28
+ // ChannelEntryIterator struct
24
29
type ChannelEntryIterator struct {
25
30
stream ChannelEntryStream
26
31
error error
27
32
}
28
33
34
+ // NewChannelEntryIterator returns a new ChannelEntryIterator
29
35
func NewChannelEntryIterator (stream ChannelEntryStream ) * ChannelEntryIterator {
30
36
return & ChannelEntryIterator {stream : stream }
31
37
}
32
38
39
+ // Next returns the next Channel Entry in the grpc stream
33
40
func (ceit * ChannelEntryIterator ) Next () * registryapi.ChannelEntry {
34
41
if ceit .error != nil {
35
42
return nil
@@ -48,21 +55,23 @@ func (ceit *ChannelEntryIterator) Error() error {
48
55
return ceit .error
49
56
}
50
57
51
- type RegistryClient struct {
52
- client. Interface
53
- Client * client.Client
58
+ // Client struct with a registry client embedded
59
+ type Client struct {
60
+ * client.Client
54
61
}
55
62
56
- func NewRegistryClient (client * client.Client ) * RegistryClient {
57
- return & RegistryClient {client , client }
63
+ // NewClientFromConn returns the next Channel Entry in the grpc stream
64
+ func NewClientFromConn (conn * grpc.ClientConn ) * Client {
65
+ return & Client {
66
+ Client : client .NewClientFromConn (conn ),
67
+ }
58
68
}
59
69
60
- var _ RegistryClientInterface = & RegistryClient {}
61
- var _ client.Interface = & RegistryClient {}
70
+ var _ ClientInterface = & Client {}
62
71
63
72
// GetLatestChannelEntriesThatProvide uses registry client to get a list of
64
73
// latest channel entries that provide the requested API (via an iterator)
65
- func (rc * RegistryClient ) GetLatestChannelEntriesThatProvide (ctx context.Context , group , version , kind string ) (* ChannelEntryIterator , error ) {
74
+ func (rc * Client ) GetLatestChannelEntriesThatProvide (ctx context.Context , group , version , kind string ) (* ChannelEntryIterator , error ) {
66
75
stream , err := rc .Client .Registry .GetLatestChannelEntriesThatProvide (ctx , & registryapi.GetLatestProvidersRequest {Group : group , Version : version , Kind : kind })
67
76
if err != nil {
68
77
return nil , err
@@ -72,14 +81,14 @@ func (rc *RegistryClient) GetLatestChannelEntriesThatProvide(ctx context.Context
72
81
73
82
// FindBundleThatProvides returns a bundle that provides the request API and
74
83
// doesn't belong to the provided package
75
- func (rc * RegistryClient ) FindBundleThatProvides (ctx context.Context , group , version , kind , pkgName string ) (* registryapi.Bundle , error ) {
84
+ func (rc * Client ) FindBundleThatProvides (ctx context.Context , group , version , kind , excludedPkgName string ) (* registryapi.Bundle , error ) {
76
85
it , err := rc .GetLatestChannelEntriesThatProvide (ctx , group , version , kind )
77
86
if err != nil {
78
87
return nil , err
79
88
}
80
- entry := rc .filterChannelEntries (it , pkgName )
89
+ entry := rc .filterChannelEntries (it , excludedPkgName )
81
90
if entry == nil {
82
- return nil , fmt .Errorf ("Unable to find a channel entry which doesn't belong to package %s" , pkgName )
91
+ return nil , fmt .Errorf ("Unable to find a channel entry which doesn't belong to package %s" , excludedPkgName )
83
92
}
84
93
bundle , err := rc .Client .Registry .GetBundle (ctx , & registryapi.GetBundleRequest {PkgName : entry .PackageName , ChannelName : entry .ChannelName , CsvName : entry .BundleName })
85
94
if err != nil {
@@ -91,10 +100,10 @@ func (rc *RegistryClient) FindBundleThatProvides(ctx context.Context, group, ver
91
100
// FilterChannelEntries filters out a channel entries that provide the requested
92
101
// API and come from the same package with original operator and returns the
93
102
// first entry on the list
94
- func (rc * RegistryClient ) filterChannelEntries (it * ChannelEntryIterator , pkgName string ) * opregistry.ChannelEntry {
103
+ func (rc * Client ) filterChannelEntries (it * ChannelEntryIterator , excludedPkgName string ) * opregistry.ChannelEntry {
95
104
var entries []* opregistry.ChannelEntry
96
105
for e := it .Next (); e != nil ; e = it .Next () {
97
- if e .PackageName != pkgName {
106
+ if e .PackageName != excludedPkgName {
98
107
entry := & opregistry.ChannelEntry {
99
108
PackageName : e .PackageName ,
100
109
ChannelName : e .ChannelName ,
0 commit comments