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 604762d
Show file tree
Hide file tree
Showing 2 changed files with 24 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
22 changes: 22 additions & 0 deletions pkg/controller/registry/reconciler/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 604762d

Please sign in to comment.