Skip to content

Add ingressClass CRD field #79

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

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
})
}
}