Skip to content

Commit 74561c7

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 74561c7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-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

+21
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ func grpcCatalogSourceWithAnnotations(annotations map[string]string) *v1alpha1.C
6161
catsrc.ObjectMeta.Annotations = annotations
6262
return catsrc
6363
}
64+
func grpcCatalogSourceWithName(name string) *v1alpha1.CatalogSource {
65+
catsrc := validGrpcCatalogSource("image", "")
66+
catsrc.SetName(name)
67+
catsrc.ObjectMeta.Labels["olm.catalogSource"] = name
68+
return catsrc
69+
}
6470

6571
func TestGrpcRegistryReconciler(t *testing.T) {
6672
now := func() metav1.Time { return metav1.Date(2018, time.January, 26, 20, 40, 0, 0, time.UTC) }
@@ -103,6 +109,21 @@ func TestGrpcRegistryReconciler(t *testing.T) {
103109
},
104110
},
105111
},
112+
{
113+
testName: "Grpc/NoExistingRegistry/CreateSuccessful/CatalogSourceWithPeriodInName",
114+
in: in{
115+
catsrc: grpcCatalogSourceWithName("img.catalog"),
116+
},
117+
out: out{
118+
status: &v1alpha1.RegistryServiceStatus{
119+
CreatedAt: now(),
120+
Protocol: "grpc",
121+
ServiceName: "img-catalog",
122+
ServiceNamespace: testNamespace,
123+
Port: "50051",
124+
},
125+
},
126+
},
106127
{
107128
testName: "Grpc/ExistingRegistry/CreateSuccessful",
108129
in: in{

0 commit comments

Comments
 (0)