diff --git a/pkg/controller/registry/reconciler/grpc.go b/pkg/controller/registry/reconciler/grpc.go index a73c9833c0..31e87bccb5 100644 --- a/pkg/controller/registry/reconciler/grpc.go +++ b/pkg/controller/registry/reconciler/grpc.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "hash/fnv" + "strings" "time" "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install" @@ -72,7 +73,7 @@ func (s *grpcCatalogSourceDecorator) Annotations() map[string]string { func (s *grpcCatalogSourceDecorator) Service() *corev1.Service { svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: s.GetName(), + Name: strings.ReplaceAll(s.GetName(), ".", "-"), Namespace: s.GetNamespace(), }, Spec: corev1.ServiceSpec{ diff --git a/pkg/controller/registry/reconciler/grpc_test.go b/pkg/controller/registry/reconciler/grpc_test.go index 7fa8da39d0..2a8d69a595 100644 --- a/pkg/controller/registry/reconciler/grpc_test.go +++ b/pkg/controller/registry/reconciler/grpc_test.go @@ -62,6 +62,13 @@ func grpcCatalogSourceWithAnnotations(annotations map[string]string) *v1alpha1.C return catsrc } +func grpcCatalogSourceWithName(name string) *v1alpha1.CatalogSource { + catsrc := validGrpcCatalogSource("image", "") + catsrc.SetName(name) + catsrc.ObjectMeta.Labels["olm.catalogSource"] = name + return catsrc +} + func TestGrpcRegistryReconciler(t *testing.T) { now := func() metav1.Time { return metav1.Date(2018, time.January, 26, 20, 40, 0, 0, time.UTC) } blockOwnerDeletion := true @@ -103,6 +110,21 @@ func TestGrpcRegistryReconciler(t *testing.T) { }, }, }, + { + testName: "Grpc/NoExistingRegistry/CreateSuccessful/CatalogSourceWithPeriodInNameCreatesValidServiceName", + in: in{ + catsrc: grpcCatalogSourceWithName("img.catalog"), + }, + out: out{ + status: &v1alpha1.RegistryServiceStatus{ + CreatedAt: now(), + Protocol: "grpc", + ServiceName: "img-catalog", + ServiceNamespace: testNamespace, + Port: "50051", + }, + }, + }, { testName: "Grpc/ExistingRegistry/CreateSuccessful", in: in{