Skip to content

Commit 7e8e9f7

Browse files
authored
Fix GRPC CheckRegistryServer function (#2756)
Problem: The CheckRegistryServer function used by grpc catalogSources does not confirm that the serviceAccount associated with the catalogSource exists. Solution: Update the GRPC CheckRegistryServer function to check if the serviceAccount exists. Signed-off-by: Alexander Greene <[email protected]>
1 parent d35ba43 commit 7e8e9f7

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

pkg/controller/operators/catalog/operator_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ func TestSyncCatalogSources(t *testing.T) {
10371037
k8sObjs: []runtime.Object{
10381038
pod(*grpcCatalog),
10391039
service(grpcCatalog.GetName(), grpcCatalog.GetNamespace()),
1040+
serviceAccount(grpcCatalog.GetName(), grpcCatalog.GetNamespace(), "", objectReference("init secret")),
10401041
},
10411042
existingSources: []sourceAddress{
10421043
{

pkg/controller/registry/reconciler/grpc.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ func (c *GrpcRegistryReconciler) currentService(source grpcCatalogSourceDecorato
146146
return service
147147
}
148148

149+
func (c *GrpcRegistryReconciler) currentServiceAccount(source grpcCatalogSourceDecorator) *corev1.ServiceAccount {
150+
serviceAccountName := source.ServiceAccount().GetName()
151+
serviceAccount, err := c.Lister.CoreV1().ServiceAccountLister().ServiceAccounts(source.GetNamespace()).Get(serviceAccountName)
152+
if err != nil {
153+
logrus.WithField("service", serviceAccount).Debug("couldn't find service in cache")
154+
return nil
155+
}
156+
return serviceAccount
157+
}
158+
149159
func (c *GrpcRegistryReconciler) currentPods(source grpcCatalogSourceDecorator) []*corev1.Pod {
150160
pods, err := c.Lister.CoreV1().PodLister().Pods(source.GetNamespace()).List(source.Selector())
151161
if err != nil {
@@ -441,7 +451,7 @@ func (c *GrpcRegistryReconciler) CheckRegistryServer(catalogSource *v1alpha1.Cat
441451
// Check on registry resources
442452
// TODO: add gRPC health check
443453
if len(c.currentPodsWithCorrectImageAndSpec(source, source.ServiceAccount().GetName())) < 1 ||
444-
c.currentService(source) == nil {
454+
c.currentService(source) == nil || c.currentServiceAccount(source) == nil {
445455
healthy = false
446456
return
447457
}

pkg/controller/registry/reconciler/grpc_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,18 @@ func TestGrpcRegistryChecker(t *testing.T) {
484484
healthy: false,
485485
},
486486
},
487+
{
488+
testName: "Grpc/ExistingRegistry/Image/BadServiceAccount",
489+
in: in{
490+
cluster: cluster{
491+
k8sObjs: modifyObjName(objectsForCatalogSource(validGrpcCatalogSource("test-img", "")), &corev1.ServiceAccount{}, "badName"),
492+
},
493+
catsrc: validGrpcCatalogSource("test-img", ""),
494+
},
495+
out: out{
496+
healthy: false,
497+
},
498+
},
487499
{
488500
testName: "Grpc/ExistingRegistry/Image/BadPod",
489501
in: in{

0 commit comments

Comments
 (0)