Skip to content

Commit e40d4f4

Browse files
Merge pull request #709 from njhale/grpc-address
feat(catalogsource): allow grpc source types that don't require an image
2 parents 7bd571b + 063ef26 commit e40d4f4

File tree

17 files changed

+442
-129
lines changed

17 files changed

+442
-129
lines changed

cmd/catalog/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,3 @@ func main() {
9999
_, done := catalogOperator.Run(stopCh)
100100
<-done
101101
}
102-

deploy/chart/templates/0000_50_olm_05-catalogsource.crd.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ spec:
6262
type: string
6363
description: The name of a ConfigMap that holds the entries for an in-memory catalog.
6464

65+
address:
66+
type: string
67+
description: An optional address. When set, directs OLM to connect to use a pre-existing registry server at this address.
68+
6569
image:
6670
type: string
67-
description: An image that serves a grpc registry. Only valid for `grpc` sourceType.
71+
description: An image that serves a grpc registry. Only valid for `grpc` sourceType. If both image and address are set, OLM does not use the address field.
6872

6973
displayName:
7074
type: string

deploy/ocp/manifests/0.8.1/0000_50_olm_05-catalogsource.crd.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ spec:
6464
type: string
6565
description: The name of a ConfigMap that holds the entries for an in-memory catalog.
6666

67+
address:
68+
type: string
69+
description: An optional address. When set, directs OLM to connect to use a pre-existing registry server at this address.
70+
6771
image:
6872
type: string
69-
description: An image that serves a grpc registry. Only valid for `grpc` sourceType.
73+
description: An image that serves a grpc registry. Only valid for `grpc` sourceType. If both image and address are set, OLM does not use the address field.
7074

7175
displayName:
7276
type: string

deploy/okd/manifests/0.8.1/0000_50_olm_05-catalogsource.crd.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ spec:
6464
type: string
6565
description: The name of a ConfigMap that holds the entries for an in-memory catalog.
6666

67+
address:
68+
type: string
69+
description: An optional address. When set, directs OLM to connect to use a pre-existing registry server at this address.
70+
6771
image:
6872
type: string
69-
description: An image that serves a grpc registry. Only valid for `grpc` sourceType.
73+
description: An image that serves a grpc registry. Only valid for `grpc` sourceType. If both image and address are set, OLM does not use the address field.
7074

7175
displayName:
7276
type: string

deploy/upstream/manifests/0.8.1/0000_50_olm_05-catalogsource.crd.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ spec:
6464
type: string
6565
description: The name of a ConfigMap that holds the entries for an in-memory catalog.
6666

67+
address:
68+
type: string
69+
description: An optional address. When set, directs OLM to connect to use a pre-existing registry server at this address.
70+
6771
image:
6872
type: string
69-
description: An image that serves a grpc registry. Only valid for `grpc` sourceType.
73+
description: An image that serves a grpc registry. Only valid for `grpc` sourceType. If both image and address are set, OLM does not use the address field.
7074

7175
displayName:
7276
type: string

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ k8s.io/apimachinery v0.0.0-20181203235515-3d8ee2261517/go.mod h1:ccL7Eh7zubPUSh9
297297
k8s.io/apimachinery v0.0.0-20190118094746-1525e4dadd2d/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
298298
k8s.io/apimachinery v0.0.0-20190208202428-1a579f8a7b42 h1:ju2lLx7i6XE8A9QLtwxlQngelP8SosMIjK4IYE/TLFI=
299299
k8s.io/apimachinery v0.0.0-20190208202428-1a579f8a7b42/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
300+
k8s.io/apimachinery v0.0.0-20190213190008-5eb658cbe970 h1:alS6VCwjuZxqOAhOnpSY/TbMvwVRAOWSTeE63v5Iz+M=
300301
k8s.io/apiserver v0.0.0-20181026151315-13cfe3978170 h1:CqI85nZvPaV+7JFono0nAOGOx2brocqefcOhDPVhHKI=
301302
k8s.io/apiserver v0.0.0-20181026151315-13cfe3978170/go.mod h1:6bqaTSOSJavUIXUtfaR9Os9JtTCm8ZqH2SUl2S60C4w=
302303
k8s.io/client-go v0.0.0-20180718001006-59698c7d9724/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=

manifests/0000_50_olm_05-catalogsource.crd.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ spec:
6262
type: string
6363
description: The name of a ConfigMap that holds the entries for an in-memory catalog.
6464

65+
address:
66+
type: string
67+
description: An optional address. When set, directs OLM to connect to use a pre-existing registry server at this address.
68+
6569
image:
6670
type: string
67-
description: An image that serves a grpc registry. Only valid for `grpc` sourceType.
71+
description: An image that serves a grpc registry. Only valid for `grpc` sourceType. If both image and address are set, OLM does not use the address field.
6872

6973
displayName:
7074
type: string

pkg/api/apis/operators/v1alpha1/catalogsource_types.go

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,43 @@ const (
1818
type SourceType string
1919

2020
const (
21-
SourceTypeInternal SourceType = "internal"
21+
// SourceTypeInternal (deprecated) specifies a CatalogSource of type SourceTypeConfigmap
22+
SourceTypeInternal SourceType = "internal"
23+
24+
// SourceTypeConfigmap specifies a CatalogSource that generates a configmap-server registry
2225
SourceTypeConfigmap SourceType = "configmap"
23-
SourceTypeGrpc SourceType = "grpc"
26+
27+
// SourceTypeGrpc specifies a CatalogSource that can use an operator registry image to generate a
28+
// registry-server or connect to a pre-existing registry at an address.
29+
SourceTypeGrpc SourceType = "grpc"
2430
)
2531

2632
type CatalogSourceSpec struct {
33+
// SourceType is the type of source
2734
SourceType SourceType `json:"sourceType"`
28-
ConfigMap string `json:"configMap,omitempty"`
29-
Image string `json:"image,omitempty"`
30-
Secrets []string `json:"secrets,omitempty"`
35+
36+
// ConfigMap is the name of the ConfigMap to be used to back a configmap-server registry.
37+
// Only used when SourceType = SourceTypeConfigmap or SourceTypeInternal.
38+
// +Optional
39+
ConfigMap string `json:"configMap,omitempty"`
40+
41+
// Address is a host that OLM can use to connect to a pre-existing registry.
42+
// Format: <registry-host or ip>:<port>
43+
// Only used when SourceType = SourceTypeGrpc.
44+
// Ignored when the Image field is set.
45+
// +Optional
46+
Address string `json:"address,omitempty"`
47+
48+
// Image is an operator-registry container image to instantiate a registry-server with.
49+
// Only used when SourceType = SourceTypeGrpc.
50+
// If present, the address field is ignored.
51+
// +Optional
52+
Image string `json:"image,omitempty"`
53+
54+
// Secrets represent set of secrets that can be used to access the contents of the catalog.
55+
// It is best to keep this list small, since each will need to be tried for every catalog entry.
56+
// +Optional
57+
Secrets []string `json:"secrets,omitempty"`
3158

3259
// Metadata
3360
DisplayName string `json:"displayName,omitempty"`
@@ -53,6 +80,7 @@ type CatalogSourceStatus struct {
5380
RegistryServiceStatus *RegistryServiceStatus `json:"registryService,omitempty"`
5481
LastSync metav1.Time `json:"lastSync,omitempty"`
5582
}
83+
5684
type ConfigMapResourceReference struct {
5785
Name string `json:"name"`
5886
Namespace string `json:"namespace"`
@@ -71,6 +99,13 @@ type CatalogSource struct {
7199
Status CatalogSourceStatus `json:"status"`
72100
}
73101

102+
func (c *CatalogSource) Address() string {
103+
if c.Spec.Address != "" {
104+
return c.Spec.Address
105+
}
106+
return c.Status.RegistryServiceStatus.Address()
107+
}
108+
74109
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
75110
type CatalogSourceList struct {
76111
metav1.TypeMeta `json:",inline"`

pkg/controller/operators/catalog/operator.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func NewOperator(kubeconfigPath string, logger *logrus.Logger, wakeupInterval ti
7777
watchedNamespaces = []string{metav1.NamespaceAll}
7878
}
7979

80-
// Create a new client for ALM types (CRs)
80+
// Create a new client for OLM types (CRs)
8181
crClient, err := client.NewClient(kubeconfigPath)
8282
if err != nil {
8383
return nil, err
@@ -381,24 +381,26 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
381381

382382
return nil
383383
}
384+
385+
logger.Debug("catsrc configmap state good, checking registry pod")
384386
}
385387

386-
reconciler := o.reconciler.ReconcilerForSourceType(catsrc.Spec.SourceType)
388+
reconciler := o.reconciler.ReconcilerForSource(catsrc)
387389
if reconciler == nil {
390+
// TODO: Add failure status on catalogsource and remove from sources
388391
return fmt.Errorf("no reconciler for source type %s", catsrc.Spec.SourceType)
389392
}
390393

391-
logger.Debug("catsrc configmap state good, checking registry pod")
392394

393395
// if registry pod hasn't been created or hasn't been updated since the last configmap update, recreate it
394396
if catsrc.Status.RegistryServiceStatus == nil || catsrc.Status.RegistryServiceStatus.CreatedAt.Before(&catsrc.Status.LastSync) {
395-
logger.Debug("registry pod scheduled for recheck")
397+
logger.Debug("registry server scheduled recheck")
396398

397399
if err := reconciler.EnsureRegistryServer(out); err != nil {
398400
logger.WithError(err).Warn("couldn't ensure registry server")
399401
return err
400402
}
401-
logger.Debug("ensured registry pod")
403+
logger.Debug("ensured registry server")
402404

403405
out.Status.RegistryServiceStatus.CreatedAt = timeNow()
404406
out.Status.LastSync = timeNow()
@@ -410,18 +412,18 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
410412
}
411413

412414
o.sourcesLastUpdate = timeNow()
413-
logger.Debug("registry pod recreated")
415+
logger.Debug("registry server recreated")
414416

415417
return nil
416418
}
417-
logger.Debug("registry pod state good")
419+
logger.Debug("registry state good")
418420

419421
// update operator's view of sources
420422
sourcesUpdated := false
421423
func() {
422424
o.sourcesLock.Lock()
423425
defer o.sourcesLock.Unlock()
424-
address := catsrc.Status.RegistryServiceStatus.Address()
426+
address := catsrc.Address()
425427
currentSource, ok := o.sources[sourceKey]
426428
logger = logger.WithField("currentSource", sourceKey)
427429
if !ok || currentSource.Address != address || catsrc.Status.LastSync.After(currentSource.LastConnect.Time) {
@@ -664,7 +666,7 @@ func (o *Operator) ensureResolverSources(logger *logrus.Entry, namespace string)
664666
logger.WithField("clientState", client.Conn.GetState()).Debug("source")
665667
if client.Conn.GetState() == connectivity.TransientFailure {
666668
logger.WithField("clientState", client.Conn.GetState()).Debug("waiting for connection")
667-
ctx, _ := context.WithTimeout(context.TODO(), 5*time.Second)
669+
ctx, _ := context.WithTimeout(context.TODO(), 2*time.Second)
668670
changed := client.Conn.WaitForStateChange(ctx, connectivity.TransientFailure)
669671
if !changed {
670672
logger.WithField("clientState", client.Conn.GetState()).Debug("source in transient failure and didn't recover")

pkg/controller/operators/catalog/subscriptions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func TestSyncSubscriptions(t *testing.T) {
499499
require.NoError(t, err)
500500

501501
o.reconciler = &fakes.FakeReconcilerFactory{
502-
ReconcilerForSourceTypeStub: func(sourceType v1alpha1.SourceType) reconciler.RegistryReconciler {
502+
ReconcilerForSourceStub: func(source *v1alpha1.CatalogSource) reconciler.RegistryReconciler {
503503
return &fakes.FakeRegistryReconciler{
504504
EnsureRegistryServerStub: func(source *v1alpha1.CatalogSource) error {
505505
return nil

0 commit comments

Comments
 (0)