Skip to content

Commit 604762d

Browse files
committed
Valid service from catsrc with periods in name
Problem: Creating a catalogSource with a period in the name is valid as the Kuberenetes API catalogSources to adhere to the following naing conventions: - Start and end with a lower case alphanumeric character - Consist only of alphanumeric characters, `.`, or `-` Unfortunately, the service created by OLM for the catalogSource must adhere to the following naming conventions: - Start and end with a lower case alphanumeric character - Consist only of alphanumeric characters or `-` This causes OLM to constantly recreate the catalogSource as the service it attempts to create is rejected from the Kubernetes API service due to the `.` in the name. Solution: When naming the service, replace all instances of `.` in the name with `-`. Signed-off-by: Alexander Greene <[email protected]>
1 parent 9e7031f commit 604762d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pkg/controller/registry/reconciler/grpc.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"hash/fnv"
7+
"strings"
78
"time"
89

910
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
@@ -72,7 +73,7 @@ func (s *grpcCatalogSourceDecorator) Annotations() map[string]string {
7273
func (s *grpcCatalogSourceDecorator) Service() *corev1.Service {
7374
svc := &corev1.Service{
7475
ObjectMeta: metav1.ObjectMeta{
75-
Name: s.GetName(),
76+
Name: strings.ReplaceAll(s.GetName(), ".", "-"),
7677
Namespace: s.GetNamespace(),
7778
},
7879
Spec: corev1.ServiceSpec{

pkg/controller/registry/reconciler/grpc_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ func grpcCatalogSourceWithAnnotations(annotations map[string]string) *v1alpha1.C
6262
return catsrc
6363
}
6464

65+
func grpcCatalogSourceWithName(name string) *v1alpha1.CatalogSource {
66+
catsrc := validGrpcCatalogSource("image", "")
67+
catsrc.SetName(name)
68+
catsrc.ObjectMeta.Labels["olm.catalogSource"] = name
69+
return catsrc
70+
}
71+
6572
func TestGrpcRegistryReconciler(t *testing.T) {
6673
now := func() metav1.Time { return metav1.Date(2018, time.January, 26, 20, 40, 0, 0, time.UTC) }
6774
blockOwnerDeletion := true
@@ -103,6 +110,21 @@ func TestGrpcRegistryReconciler(t *testing.T) {
103110
},
104111
},
105112
},
113+
{
114+
testName: "Grpc/NoExistingRegistry/CreateSuccessful/CatalogSourceWithPeriodInNameCreatesValidServiceName",
115+
in: in{
116+
catsrc: grpcCatalogSourceWithName("img.catalog"),
117+
},
118+
out: out{
119+
status: &v1alpha1.RegistryServiceStatus{
120+
CreatedAt: now(),
121+
Protocol: "grpc",
122+
ServiceName: "img-catalog",
123+
ServiceNamespace: testNamespace,
124+
Port: "50051",
125+
},
126+
},
127+
},
106128
{
107129
testName: "Grpc/ExistingRegistry/CreateSuccessful",
108130
in: in{

0 commit comments

Comments
 (0)