Skip to content

Commit

Permalink
Valid service from catsrc with periods in name
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
awgreene committed Aug 31, 2023
1 parent 9e7031f commit 74561c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/controller/registry/reconciler/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"hash/fnv"
"strings"
"time"

"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
Expand Down Expand Up @@ -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{
Expand Down
21 changes: 21 additions & 0 deletions pkg/controller/registry/reconciler/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func grpcCatalogSourceWithAnnotations(annotations map[string]string) *v1alpha1.C
catsrc.ObjectMeta.Annotations = annotations
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) }
Expand Down Expand Up @@ -103,6 +109,21 @@ func TestGrpcRegistryReconciler(t *testing.T) {
},
},
},
{
testName: "Grpc/NoExistingRegistry/CreateSuccessful/CatalogSourceWithPeriodInName",
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{
Expand Down

0 comments on commit 74561c7

Please sign in to comment.