Skip to content

Commit

Permalink
Add ingressClass CRD field (#79)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
thepetk authored Mar 6, 2024
1 parent a9f14a4 commit 29aef03
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/devfileregistry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/registry.devfile.io_devfileregistries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions pkg/registry/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
37 changes: 37 additions & 0 deletions pkg/registry/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}

0 comments on commit 29aef03

Please sign in to comment.