Skip to content

Commit 5eb6c57

Browse files
awgreeneopenshift-cherrypick-robot
authored andcommitted
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]> Upstream-repository: operator-lifecycle-manager Upstream-commit: 7e8e9f77d08d1bf451ce61b7bb2610473e793ded
1 parent 1cb0c9a commit 5eb6c57

File tree

4 files changed

+35
-2
lines changed
  • staging/operator-lifecycle-manager/pkg/controller
  • vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler

4 files changed

+35
-2
lines changed

staging/operator-lifecycle-manager/pkg/controller/operators/catalog/operator_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ func TestSyncCatalogSources(t *testing.T) {
10391039
k8sObjs: []runtime.Object{
10401040
pod(*grpcCatalog),
10411041
service(grpcCatalog.GetName(), grpcCatalog.GetNamespace()),
1042+
serviceAccount(grpcCatalog.GetName(), grpcCatalog.GetNamespace(), "", objectReference("init secret")),
10421043
},
10431044
existingSources: []sourceAddress{
10441045
{

staging/operator-lifecycle-manager/pkg/controller/registry/reconciler/grpc.go

Lines changed: 11 additions & 1 deletion
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
}

staging/operator-lifecycle-manager/pkg/controller/registry/reconciler/grpc_test.go

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

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler/grpc.go

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)