diff --git a/api/v1alpha1/devfileregistry_types.go b/api/v1alpha1/devfileregistry_types.go index 7cae449..750e074 100644 --- a/api/v1alpha1/devfileregistry_types.go +++ b/api/v1alpha1/devfileregistry_types.go @@ -122,6 +122,9 @@ type DevfileRegistrySpecK8sOnly struct { // Ingress domain for a Kubernetes cluster. This MUST be explicitly specified on Kubernetes. There are no defaults // +operator-sdk:csv:customresourcedefinitions:type=spec IngressDomain string `json:"ingressDomain,omitempty"` + // Ingress class for a Kubernetes cluster. Defaults to nginx. + // +operator-sdk:csv:customresourcedefinitions:type=spec + IngressClass string `json:"ingressClass,omitempty"` } // Telemetry defines the desired state for telemetry in the DevfileRegistry diff --git a/config/crd/bases/registry.devfile.io_devfileregistries.yaml b/config/crd/bases/registry.devfile.io_devfileregistries.yaml index c201448..568044a 100644 --- a/config/crd/bases/registry.devfile.io_devfileregistries.yaml +++ b/config/crd/bases/registry.devfile.io_devfileregistries.yaml @@ -72,6 +72,10 @@ spec: description: DevfileRegistrySpecK8sOnly defines the desired state of the kubernetes-only fields of the DevfileRegistry properties: + ingressClass: + description: Ingress class for a Kubernetes cluster. Defaults + to nginx. + type: string ingressDomain: description: Ingress domain for a Kubernetes cluster. This MUST be explicitly specified on Kubernetes. There are no defaults diff --git a/pkg/registry/defaults.go b/pkg/registry/defaults.go index 5c3e10b..3341b41 100644 --- a/pkg/registry/defaults.go +++ b/pkg/registry/defaults.go @@ -57,6 +57,9 @@ const ( OCIMetricsPort = 5001 OCIServerPort = 5000 RegistryViewerPort = 3000 + + // Default kubernetes-only fields + DefaultK8sIngressClass = "nginx" ) // GetRegistryViewerImage returns the container image for the registry viewer to be deployed on the Devfile Registry. @@ -159,6 +162,15 @@ func GetDevfileRegistryVolumeSource(cr *registryv1alpha1.DevfileRegistry) corev1 return corev1.VolumeSource{} } +// GetK8sIngressClass returns ingress class used for the k8s ingress class field. +// Default: "nginx" +func GetK8sIngressClass(cr *registryv1alpha1.DevfileRegistry) string { + if cr.Spec.K8s.IngressClass != "" { + return cr.Spec.K8s.IngressClass + } + return DefaultK8sIngressClass +} + // IsStorageEnabled returns true if storage.enabled is set in the DevfileRegistry CR // If it's not set, it returns false by default. func IsStorageEnabled(cr *registryv1alpha1.DevfileRegistry) bool { diff --git a/pkg/registry/defaults_test.go b/pkg/registry/defaults_test.go index 20b73f3..246bd7c 100644 --- a/pkg/registry/defaults_test.go +++ b/pkg/registry/defaults_test.go @@ -429,3 +429,40 @@ func Test_getDevfileRegistrySpecContainer(t *testing.T) { }) } } + +func TestGetK8sIngressClass(t *testing.T) { + tests := []struct { + name string + cr registryv1alpha1.DevfileRegistry + want string + }{ + { + name: "Case 1: K8s ingress class set", + cr: registryv1alpha1.DevfileRegistry{ + Spec: registryv1alpha1.DevfileRegistrySpec{ + K8s: registryv1alpha1.DevfileRegistrySpecK8sOnly{ + IngressClass: "test", + }, + }, + }, + want: "test", + }, + { + name: "Case 2: K8s ingress class not set", + cr: registryv1alpha1.DevfileRegistry{ + Spec: registryv1alpha1.DevfileRegistrySpec{ + Telemetry: registryv1alpha1.DevfileRegistrySpecTelemetry{}, + }, + }, + want: DefaultK8sIngressClass, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := GetK8sIngressClass(&tt.cr) + if result != tt.want { + t.Errorf("func TestGetK8sIngressClass(t *testing.T) {\n error: enablement value mismatch, expected: %v got: %v", tt.want, result) + } + }) + } +}