Skip to content

Commit 4dfe85c

Browse files
committed
feat(registry): add registrychecker
- Add RegistryChecker interface and implementations to check for missing/bad registry components - Add RegistryEnsurer interface to be responsible for the EnsureRegistry method - Compose RegistryResolver interface from RegistryEnsurer
1 parent 0db4a76 commit 4dfe85c

File tree

9 files changed

+261
-90
lines changed

9 files changed

+261
-90
lines changed

pkg/controller/operators/catalog/operator_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,7 @@ func NewFakeOperator(clientObjs []runtime.Object, k8sObjs []runtime.Object, extO
530530
sources: make(map[resolver.CatalogKey]resolver.SourceRef),
531531
resolver: &fakes.FakeResolver{},
532532
}
533-
534-
op.reconciler = &reconciler.RegistryReconcilerFactory{
535-
ConfigMapServerImage: "test:pod",
536-
OpClient: op.OpClient,
537-
Lister: lister,
538-
}
533+
op.reconciler = reconciler.NewRegistryReconcilerFactory(lister, op.OpClient, "test:pod")
539534

540535
var hasSyncedCheckFns []cache.InformerSynced
541536
for _, informer := range registryInformers {

pkg/controller/operators/catalog/subscriptions_test.go

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"time"
77

88
"github.com/stretchr/testify/require"
9-
"k8s.io/api/core/v1"
9+
v1 "k8s.io/api/core/v1"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
"k8s.io/apimachinery/pkg/runtime"
1212

@@ -72,11 +72,11 @@ func TestSyncSubscriptions(t *testing.T) {
7272
Resource: v1alpha1.StepResource{
7373
CatalogSource: "src",
7474
CatalogSourceNamespace: testNamespace,
75-
Group: v1alpha1.GroupName,
76-
Version: v1alpha1.GroupVersion,
77-
Kind: v1alpha1.ClusterServiceVersionKind,
78-
Name: "csv.v.1",
79-
Manifest: "{}",
75+
Group: v1alpha1.GroupName,
76+
Version: v1alpha1.GroupVersion,
77+
Kind: v1alpha1.ClusterServiceVersionKind,
78+
Name: "csv.v.1",
79+
Manifest: "{}",
8080
},
8181
},
8282
},
@@ -161,11 +161,11 @@ func TestSyncSubscriptions(t *testing.T) {
161161
Resource: v1alpha1.StepResource{
162162
CatalogSource: "src",
163163
CatalogSourceNamespace: testNamespace,
164-
Group: v1alpha1.GroupName,
165-
Version: v1alpha1.GroupVersion,
166-
Kind: v1alpha1.ClusterServiceVersionKind,
167-
Name: "csv.v.1",
168-
Manifest: "{}",
164+
Group: v1alpha1.GroupName,
165+
Version: v1alpha1.GroupVersion,
166+
Kind: v1alpha1.ClusterServiceVersionKind,
167+
Name: "csv.v.1",
168+
Manifest: "{}",
169169
},
170170
},
171171
},
@@ -206,11 +206,11 @@ func TestSyncSubscriptions(t *testing.T) {
206206
Resource: v1alpha1.StepResource{
207207
CatalogSource: "src",
208208
CatalogSourceNamespace: testNamespace,
209-
Group: v1alpha1.GroupName,
210-
Version: v1alpha1.GroupVersion,
211-
Kind: v1alpha1.ClusterServiceVersionKind,
212-
Name: "csv.v.2",
213-
Manifest: "{}",
209+
Group: v1alpha1.GroupName,
210+
Version: v1alpha1.GroupVersion,
211+
Kind: v1alpha1.ClusterServiceVersionKind,
212+
Name: "csv.v.2",
213+
Manifest: "{}",
214214
},
215215
},
216216
},
@@ -295,11 +295,11 @@ func TestSyncSubscriptions(t *testing.T) {
295295
Resource: v1alpha1.StepResource{
296296
CatalogSource: "src",
297297
CatalogSourceNamespace: testNamespace,
298-
Group: v1alpha1.GroupName,
299-
Version: v1alpha1.GroupVersion,
300-
Kind: v1alpha1.ClusterServiceVersionKind,
301-
Name: "csv.v.2",
302-
Manifest: "{}",
298+
Group: v1alpha1.GroupName,
299+
Version: v1alpha1.GroupVersion,
300+
Kind: v1alpha1.ClusterServiceVersionKind,
301+
Name: "csv.v.2",
302+
Manifest: "{}",
303303
},
304304
},
305305
},
@@ -340,35 +340,35 @@ func TestSyncSubscriptions(t *testing.T) {
340340
Resource: v1alpha1.StepResource{
341341
CatalogSource: "src",
342342
CatalogSourceNamespace: testNamespace,
343-
Group: v1alpha1.GroupName,
344-
Version: v1alpha1.GroupVersion,
345-
Kind: v1alpha1.ClusterServiceVersionKind,
346-
Name: "csv.v.2",
347-
Manifest: "{}",
343+
Group: v1alpha1.GroupName,
344+
Version: v1alpha1.GroupVersion,
345+
Kind: v1alpha1.ClusterServiceVersionKind,
346+
Name: "csv.v.2",
347+
Manifest: "{}",
348348
},
349349
},
350350
{
351351
Resolving: "csv.v.2",
352352
Resource: v1alpha1.StepResource{
353353
CatalogSource: "src",
354354
CatalogSourceNamespace: testNamespace,
355-
Group: v1alpha1.GroupName,
356-
Version: v1alpha1.GroupVersion,
357-
Kind: v1alpha1.ClusterServiceVersionKind,
358-
Name: "dep.v.1",
359-
Manifest: "{}",
355+
Group: v1alpha1.GroupName,
356+
Version: v1alpha1.GroupVersion,
357+
Kind: v1alpha1.ClusterServiceVersionKind,
358+
Name: "dep.v.1",
359+
Manifest: "{}",
360360
},
361361
},
362362
{
363363
Resolving: "csv.v.2",
364364
Resource: v1alpha1.StepResource{
365365
CatalogSource: "src",
366366
CatalogSourceNamespace: testNamespace,
367-
Group: v1alpha1.GroupName,
368-
Version: v1alpha1.GroupVersion,
369-
Kind: v1alpha1.SubscriptionKind,
370-
Name: "sub-dep",
371-
Manifest: "{}",
367+
Group: v1alpha1.GroupName,
368+
Version: v1alpha1.GroupVersion,
369+
Kind: v1alpha1.SubscriptionKind,
370+
Name: "sub-dep",
371+
Manifest: "{}",
372372
},
373373
},
374374
},
@@ -454,35 +454,35 @@ func TestSyncSubscriptions(t *testing.T) {
454454
Resource: v1alpha1.StepResource{
455455
CatalogSource: "src",
456456
CatalogSourceNamespace: testNamespace,
457-
Group: v1alpha1.GroupName,
458-
Version: v1alpha1.GroupVersion,
459-
Kind: v1alpha1.ClusterServiceVersionKind,
460-
Name: "csv.v.2",
461-
Manifest: "{}",
457+
Group: v1alpha1.GroupName,
458+
Version: v1alpha1.GroupVersion,
459+
Kind: v1alpha1.ClusterServiceVersionKind,
460+
Name: "csv.v.2",
461+
Manifest: "{}",
462462
},
463463
},
464464
{
465465
Resolving: "csv.v.2",
466466
Resource: v1alpha1.StepResource{
467467
CatalogSource: "src",
468468
CatalogSourceNamespace: testNamespace,
469-
Group: v1alpha1.GroupName,
470-
Version: v1alpha1.GroupVersion,
471-
Kind: v1alpha1.ClusterServiceVersionKind,
472-
Name: "dep.v.1",
473-
Manifest: "{}",
469+
Group: v1alpha1.GroupName,
470+
Version: v1alpha1.GroupVersion,
471+
Kind: v1alpha1.ClusterServiceVersionKind,
472+
Name: "dep.v.1",
473+
Manifest: "{}",
474474
},
475475
},
476476
{
477477
Resolving: "csv.v.2",
478478
Resource: v1alpha1.StepResource{
479479
CatalogSource: "src",
480480
CatalogSourceNamespace: testNamespace,
481-
Group: v1alpha1.GroupName,
482-
Version: v1alpha1.GroupVersion,
483-
Kind: v1alpha1.SubscriptionKind,
484-
Name: "sub-dep",
485-
Manifest: "{}",
481+
Group: v1alpha1.GroupName,
482+
Version: v1alpha1.GroupVersion,
483+
Kind: v1alpha1.SubscriptionKind,
484+
Name: "sub-dep",
485+
Manifest: "{}",
486486
},
487487
},
488488
},
@@ -498,7 +498,7 @@ func TestSyncSubscriptions(t *testing.T) {
498498
o, _, err := NewFakeOperator(tt.fields.existingOLMObjs, tt.fields.existingObjects, nil, nil, testNamespace, stopCh)
499499
require.NoError(t, err)
500500

501-
o.reconciler = &fakes.FakeReconcilerFactory{
501+
o.reconciler = &fakes.FakeRegistryReconcilerFactory{
502502
ReconcilerForSourceStub: func(source *v1alpha1.CatalogSource) reconciler.RegistryReconciler {
503503
return &fakes.FakeRegistryReconciler{
504504
EnsureRegistryServerStub: func(source *v1alpha1.CatalogSource) error {

pkg/controller/registry/reconciler/configmap.go

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/pkg/errors"
99
"github.com/sirupsen/logrus"
10-
"k8s.io/api/core/v1"
10+
v1 "k8s.io/api/core/v1"
1111
rbacv1 "k8s.io/api/rbac/v1"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
"k8s.io/apimachinery/pkg/labels"
@@ -189,6 +189,8 @@ type ConfigMapRegistryReconciler struct {
189189
Image string
190190
}
191191

192+
var _ RegistryEnsurer = &ConfigMapRegistryReconciler{}
193+
var _ RegistryChecker = &ConfigMapRegistryReconciler{}
192194
var _ RegistryReconciler = &ConfigMapRegistryReconciler{}
193195

194196
func (c *ConfigMapRegistryReconciler) currentService(source configMapCatalogSourceDecorator) *v1.Service {
@@ -257,7 +259,7 @@ func (c *ConfigMapRegistryReconciler) currentPodsWithCorrectResourceVersion(sour
257259
return pods
258260
}
259261

260-
// Ensure that all components of registry server are up to date.
262+
// EnsureRegistryServer ensures that all components of registry server are up to date.
261263
func (c *ConfigMapRegistryReconciler) EnsureRegistryServer(catalogSource *v1alpha1.CatalogSource) error {
262264
source := configMapCatalogSourceDecorator{catalogSource}
263265

@@ -403,3 +405,48 @@ func (c *ConfigMapRegistryReconciler) ensureService(source configMapCatalogSourc
403405
_, err := c.OpClient.CreateService(service)
404406
return err
405407
}
408+
409+
// CheckRegistryServer returns true if the given CatalogSource is considered healthy; false otherwise.
410+
func (c *ConfigMapRegistryReconciler) CheckRegistryServer(catalogSource *v1alpha1.CatalogSource) (healthy bool, err error) {
411+
source := configMapCatalogSourceDecorator{catalogSource}
412+
413+
image := c.Image
414+
if source.Spec.SourceType == "grpc" {
415+
image = source.Spec.Image
416+
}
417+
if image == "" {
418+
err = fmt.Errorf("no image for registry")
419+
return
420+
}
421+
422+
if source.Spec.SourceType == v1alpha1.SourceTypeConfigmap || source.Spec.SourceType == v1alpha1.SourceTypeInternal {
423+
configMap, err := c.Lister.CoreV1().ConfigMapLister().ConfigMaps(source.GetNamespace()).Get(source.Spec.ConfigMap)
424+
if err != nil {
425+
return false, fmt.Errorf("unable to get configmap %s/%s from cache", source.GetNamespace(), source.Spec.ConfigMap)
426+
}
427+
428+
if source.ConfigMapChanges(configMap) {
429+
return false, nil
430+
}
431+
432+
// recreate the pod if no existing pod is serving the latest image
433+
if len(c.currentPodsWithCorrectResourceVersion(source, image)) == 0 {
434+
return false, nil
435+
}
436+
}
437+
438+
// Check on registry resources
439+
// TODO: more complex checks for resources
440+
// TODO: add gRPC health check
441+
if c.currentServiceAccount(source) == nil ||
442+
c.currentRole(source) == nil ||
443+
c.currentRoleBinding(source) == nil ||
444+
c.currentService(source) == nil ||
445+
len(c.currentPods(source, c.Image)) != 1 {
446+
healthy = false
447+
return
448+
}
449+
450+
healthy = true
451+
return
452+
}

pkg/controller/registry/reconciler/grpc.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
1010
"github.com/pkg/errors"
1111
"github.com/sirupsen/logrus"
12-
"k8s.io/api/core/v1"
12+
v1 "k8s.io/api/core/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1414
"k8s.io/apimachinery/pkg/labels"
1515
"k8s.io/apimachinery/pkg/util/intstr"
@@ -144,7 +144,7 @@ func (c *GrpcRegistryReconciler) currentPodsWithCorrectImage(source grpcCatalogS
144144
return found
145145
}
146146

147-
// Ensure that all components of registry server are up to date.
147+
// EnsureRegistryServer ensures that all components of registry server are up to date.
148148
func (c *GrpcRegistryReconciler) EnsureRegistryServer(catalogSource *v1alpha1.CatalogSource) error {
149149
source := grpcCatalogSourceDecorator{catalogSource}
150150

@@ -206,3 +206,19 @@ func (c *GrpcRegistryReconciler) ensureService(source grpcCatalogSourceDecorator
206206
_, err := c.OpClient.CreateService(service)
207207
return err
208208
}
209+
210+
// CheckRegistryServer returns true if the given CatalogSource is considered healthy; false otherwise.
211+
func (c *GrpcRegistryReconciler) CheckRegistryServer(catalogSource *v1alpha1.CatalogSource) (healthy bool, err error) {
212+
source := grpcCatalogSourceDecorator{catalogSource}
213+
214+
// Check on registry resources
215+
// TODO: add gRPC health check
216+
if len(c.currentPodsWithCorrectImage(source)) == 1 ||
217+
c.currentService(source) == nil {
218+
healthy = false
219+
return
220+
}
221+
222+
healthy = true
223+
return
224+
}

pkg/controller/registry/reconciler/grpc_address.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@ import (
66

77
type GrpcAddressRegistryReconciler struct{}
88

9+
var _ RegistryEnsurer = &GrpcAddressRegistryReconciler{}
10+
var _ RegistryChecker = &GrpcAddressRegistryReconciler{}
911
var _ RegistryReconciler = &GrpcAddressRegistryReconciler{}
1012

13+
// EnsureRegistryServer ensures a registry server exists for the given CatalogSource.
1114
func (g *GrpcAddressRegistryReconciler) EnsureRegistryServer(catalogSource *v1alpha1.CatalogSource) error {
12-
1315
catalogSource.Status.RegistryServiceStatus = &v1alpha1.RegistryServiceStatus{
14-
CreatedAt: timeNow(),
15-
Protocol: "grpc",
16+
CreatedAt: timeNow(),
17+
Protocol: "grpc",
1618
}
1719

1820
return nil
1921
}
22+
23+
// CheckRegistryServer returns true if the given CatalogSource is considered healthy; false otherwise.
24+
func (g *GrpcAddressRegistryReconciler) CheckRegistryServer(catalogSource *v1alpha1.CatalogSource) (healthy bool, err error) {
25+
// TODO: add gRPC health check
26+
healthy = true
27+
return
28+
}

0 commit comments

Comments
 (0)