Skip to content

Commit 29aef03

Browse files
authored
Add ingressClass CRD field (#79)
* Add ingressClass field Signed-off-by: thepetk <[email protected]> * Update description for ingressClass Signed-off-by: thepetk <[email protected]> * Update defaults with k8s ingress class Signed-off-by: thepetk <[email protected]> --------- Signed-off-by: thepetk <[email protected]>
1 parent a9f14a4 commit 29aef03

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

api/v1alpha1/devfileregistry_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ type DevfileRegistrySpecK8sOnly struct {
122122
// Ingress domain for a Kubernetes cluster. This MUST be explicitly specified on Kubernetes. There are no defaults
123123
// +operator-sdk:csv:customresourcedefinitions:type=spec
124124
IngressDomain string `json:"ingressDomain,omitempty"`
125+
// Ingress class for a Kubernetes cluster. Defaults to nginx.
126+
// +operator-sdk:csv:customresourcedefinitions:type=spec
127+
IngressClass string `json:"ingressClass,omitempty"`
125128
}
126129

127130
// Telemetry defines the desired state for telemetry in the DevfileRegistry

config/crd/bases/registry.devfile.io_devfileregistries.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ spec:
7272
description: DevfileRegistrySpecK8sOnly defines the desired state
7373
of the kubernetes-only fields of the DevfileRegistry
7474
properties:
75+
ingressClass:
76+
description: Ingress class for a Kubernetes cluster. Defaults
77+
to nginx.
78+
type: string
7579
ingressDomain:
7680
description: Ingress domain for a Kubernetes cluster. This MUST
7781
be explicitly specified on Kubernetes. There are no defaults

pkg/registry/defaults.go

+12
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const (
5757
OCIMetricsPort = 5001
5858
OCIServerPort = 5000
5959
RegistryViewerPort = 3000
60+
61+
// Default kubernetes-only fields
62+
DefaultK8sIngressClass = "nginx"
6063
)
6164

6265
// 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
159162
return corev1.VolumeSource{}
160163
}
161164

165+
// GetK8sIngressClass returns ingress class used for the k8s ingress class field.
166+
// Default: "nginx"
167+
func GetK8sIngressClass(cr *registryv1alpha1.DevfileRegistry) string {
168+
if cr.Spec.K8s.IngressClass != "" {
169+
return cr.Spec.K8s.IngressClass
170+
}
171+
return DefaultK8sIngressClass
172+
}
173+
162174
// IsStorageEnabled returns true if storage.enabled is set in the DevfileRegistry CR
163175
// If it's not set, it returns false by default.
164176
func IsStorageEnabled(cr *registryv1alpha1.DevfileRegistry) bool {

pkg/registry/defaults_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,40 @@ func Test_getDevfileRegistrySpecContainer(t *testing.T) {
429429
})
430430
}
431431
}
432+
433+
func TestGetK8sIngressClass(t *testing.T) {
434+
tests := []struct {
435+
name string
436+
cr registryv1alpha1.DevfileRegistry
437+
want string
438+
}{
439+
{
440+
name: "Case 1: K8s ingress class set",
441+
cr: registryv1alpha1.DevfileRegistry{
442+
Spec: registryv1alpha1.DevfileRegistrySpec{
443+
K8s: registryv1alpha1.DevfileRegistrySpecK8sOnly{
444+
IngressClass: "test",
445+
},
446+
},
447+
},
448+
want: "test",
449+
},
450+
{
451+
name: "Case 2: K8s ingress class not set",
452+
cr: registryv1alpha1.DevfileRegistry{
453+
Spec: registryv1alpha1.DevfileRegistrySpec{
454+
Telemetry: registryv1alpha1.DevfileRegistrySpecTelemetry{},
455+
},
456+
},
457+
want: DefaultK8sIngressClass,
458+
},
459+
}
460+
for _, tt := range tests {
461+
t.Run(tt.name, func(t *testing.T) {
462+
result := GetK8sIngressClass(&tt.cr)
463+
if result != tt.want {
464+
t.Errorf("func TestGetK8sIngressClass(t *testing.T) {\n error: enablement value mismatch, expected: %v got: %v", tt.want, result)
465+
}
466+
})
467+
}
468+
}

0 commit comments

Comments
 (0)