diff --git a/pkg/controller/registry/reconciler/grpc.go b/pkg/controller/registry/reconciler/grpc.go index 3cea3472c9..f8f296a960 100644 --- a/pkg/controller/registry/reconciler/grpc.go +++ b/pkg/controller/registry/reconciler/grpc.go @@ -98,6 +98,9 @@ func (s *grpcCatalogSourceDecorator) ServiceAccount() *corev1.ServiceAccount { blockOwnerDeletion := true isController := true for _, secretName := range s.CatalogSource.Spec.Secrets { + if secretName == "" { + continue + } secrets = append(secrets, corev1.LocalObjectReference{Name: secretName}) } return &corev1.ServiceAccount{ diff --git a/pkg/controller/registry/reconciler/grpc_test.go b/pkg/controller/registry/reconciler/grpc_test.go index a5926f681f..5418832219 100644 --- a/pkg/controller/registry/reconciler/grpc_test.go +++ b/pkg/controller/registry/reconciler/grpc_test.go @@ -33,7 +33,7 @@ func validGrpcCatalogSource(image, address string) *v1alpha1.CatalogSource { } } -func grpcCatalogSourceWithSecret(secretName string) *v1alpha1.CatalogSource { +func grpcCatalogSourceWithSecret(secretNames []string) *v1alpha1.CatalogSource { return &v1alpha1.CatalogSource{ ObjectMeta: metav1.ObjectMeta{ Name: "private-catalog", @@ -45,7 +45,7 @@ func grpcCatalogSourceWithSecret(secretName string) *v1alpha1.CatalogSource { Image: "private-image", Address: "", SourceType: v1alpha1.SourceTypeGrpc, - Secrets: []string{secretName}, + Secrets: secretNames, }, } } @@ -61,6 +61,10 @@ func TestGrpcRegistryReconciler(t *testing.T) { blockOwnerDeletion := true isController := true + // We expect the empty string secret name should not be set + // on the service account + testSecrets := []string{"test-secret", ""} + type cluster struct { k8sObjs []runtime.Object } @@ -225,7 +229,7 @@ func TestGrpcRegistryReconciler(t *testing.T) { }, }, }, - catsrc: grpcCatalogSourceWithSecret("test-secret"), + catsrc: grpcCatalogSourceWithSecret(testSecrets), }, out: out{ status: &v1alpha1.RegistryServiceStatus{