Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling Missing Ingress Domain for Registry Operator #89

Merged
merged 9 commits into from
May 21, 2024
11 changes: 8 additions & 3 deletions controllers/devfileregistry_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,14 @@ func (r *DevfileRegistryReconciler) Reconcile(ctx context.Context, req ctrl.Requ
} else {
// Create/update the ingress for the devfile registry
hostname = registry.GetDevfileRegistryIngress(devfileRegistry)
result, err = r.ensure(ctx, devfileRegistry, &networkingv1.Ingress{}, labels, hostname)
if result != nil {
return *result, err

if devfileRegistry.Spec.K8s.IngressDomain != "" {
result, err = r.ensure(ctx, devfileRegistry, &networkingv1.Ingress{}, labels, hostname)
if result != nil {
return *result, err
}
} else {
log.Info("Ingress creation skipped due to missing IngressDomain field.")
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/registry/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
package registry

const maxTruncLength = 63

const localHostname = "http://localhost:8080"
Jdubrick marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions pkg/registry/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func GenerateIngress(cr *registryv1alpha1.DevfileRegistry, host string, scheme *
}

func GetDevfileRegistryIngress(cr *registryv1alpha1.DevfileRegistry) string {
if cr.Spec.K8s.IngressDomain == "" {
return localHostname
}
return GetHostname(cr) + "." + cr.Spec.K8s.IngressDomain
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/registry/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ func TestGetDevfileRegistryIngress(t *testing.T) {
}},
want: "test-name-devfile-registry-test-namespace.my-domain",
},
{
name: "Case 2: Unset Ingress",
cr: registryv1alpha1.DevfileRegistry{
ObjectMeta: metav1.ObjectMeta{
Name: "test-name",
Namespace: "test-namespace",
},
},
want: localHostname,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down