Skip to content

Commit

Permalink
[Sync]: ODH to RHOAI 2.15: validation on namespace (red-hat-data-serv…
Browse files Browse the repository at this point in the history
…ices#376)

* fix(crd): adds validation pattern and max length for ns fields (opendatahub-io#1261)

This commit introduces a validation pattern and maximum length constraint
to the `Namespace` fields in our structs. We have missed it in the early
days.

Validation rules ensure that namespace names does not exceed max length
defined and are valid [RFC 1123 DNS labels](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#namespaces-and-dns).

(cherry picked from commit 5648ee9)

* update: add validation on application and monitoring namespace in DSCI (opendatahub-io#1263)

Signed-off-by: Wen Zhou <[email protected]>
(cherry picked from commit 0f382d5)

---------

Co-authored-by: Bartosz Majsak <[email protected]>
  • Loading branch information
zdtsw and bartoszmajsak authored Oct 17, 2024
1 parent ab08cac commit 7bea1fd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion apis/dscinitialization/v1/dscinitialization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type DSCInitializationSpec struct {
// Namespace for applications to be installed, non-configurable, default to "redhat-ods-applications"
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ApplicationsNamespace is immutable"
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=1
// +kubebuilder:validation:Pattern="^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$"
// +kubebuilder:validation:MaxLength=63
ApplicationsNamespace string `json:"applicationsNamespace"`
// Enable monitoring on specified namespace
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=2
Expand Down Expand Up @@ -68,8 +70,10 @@ type Monitoring struct {
// or if it is installed, the operator will try to remove it.
// +kubebuilder:validation:Enum=Managed;Removed
ManagementState operatorv1.ManagementState `json:"managementState,omitempty"`
// +kubebuilder:default=redhat-ods-monitoring
// Namespace for monitoring if it is enabled
// +kubebuilder:default=redhat-ods-monitoring
// +kubebuilder:validation:Pattern="^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$"
// +kubebuilder:validation:MaxLength=63
Namespace string `json:"namespace,omitempty"`
}

Expand Down
4 changes: 4 additions & 0 deletions apis/infrastructure/v1/servicemesh_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type ControlPlaneSpec struct {
Name string `json:"name,omitempty"`
// Namespace is a namespace where Service Mesh is deployed. Defaults to "istio-system".
// +kubebuilder:default=istio-system
// +kubebuilder:validation:Pattern="^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$"
// +kubebuilder:validation:MaxLength=63
Namespace string `json:"namespace,omitempty"`
// MetricsCollection specifies if metrics from components on the Mesh namespace
// should be collected. Setting the value to "Istio" will collect metrics from the
Expand All @@ -45,6 +47,8 @@ type GatewaySpec struct {
type AuthSpec struct {
// Namespace where it is deployed. If not provided, the default is to
// use '-auth-provider' suffix on the ApplicationsNamespace of the DSCI.
// +kubebuilder:validation:Pattern="^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$"
// +kubebuilder:validation:MaxLength=63
Namespace string `json:"namespace,omitempty"`
// Audiences is a list of the identifiers that the resource server presented
// with the token identifies as. Audience-aware token authenticators will verify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ spec:
default: redhat-ods-applications
description: Namespace for applications to be installed, non-configurable,
default to "redhat-ods-applications"
maxLength: 63
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
x-kubernetes-validations:
- message: ApplicationsNamespace is immutable
Expand Down Expand Up @@ -95,6 +97,8 @@ spec:
namespace:
default: redhat-ods-monitoring
description: Namespace for monitoring if it is enabled
maxLength: 63
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
type: object
serviceMesh:
Expand Down Expand Up @@ -126,6 +130,8 @@ spec:
description: |-
Namespace where it is deployed. If not provided, the default is to
use '-auth-provider' suffix on the ApplicationsNamespace of the DSCI.
maxLength: 63
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
type: object
controlPlane:
Expand All @@ -152,6 +158,8 @@ spec:
default: istio-system
description: Namespace is a namespace where Service Mesh is
deployed. Defaults to "istio-system".
maxLength: 63
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
type: object
managementState:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ spec:
default: redhat-ods-applications
description: Namespace for applications to be installed, non-configurable,
default to "redhat-ods-applications"
maxLength: 63
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
x-kubernetes-validations:
- message: ApplicationsNamespace is immutable
Expand Down Expand Up @@ -95,6 +97,8 @@ spec:
namespace:
default: redhat-ods-monitoring
description: Namespace for monitoring if it is enabled
maxLength: 63
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
type: object
serviceMesh:
Expand Down Expand Up @@ -126,6 +130,8 @@ spec:
description: |-
Namespace where it is deployed. If not provided, the default is to
use '-auth-provider' suffix on the ApplicationsNamespace of the DSCI.
maxLength: 63
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
type: object
controlPlane:
Expand All @@ -152,6 +158,8 @@ spec:
default: istio-system
description: Namespace is a namespace where Service Mesh is
deployed. Defaults to "istio-system".
maxLength: 63
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
type: object
managementState:
Expand Down
8 changes: 4 additions & 4 deletions docs/api-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ _Appears in:_

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `namespace` _string_ | Namespace where it is deployed. If not provided, the default is to<br />use '-auth-provider' suffix on the ApplicationsNamespace of the DSCI. | | |
| `namespace` _string_ | Namespace where it is deployed. If not provided, the default is to<br />use '-auth-provider' suffix on the ApplicationsNamespace of the DSCI. | | MaxLength: 63 <br />Pattern: `^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$` <br /> |
| `audiences` _string_ | Audiences is a list of the identifiers that the resource server presented<br />with the token identifies as. Audience-aware token authenticators will verify<br />that the token was intended for at least one of the audiences in this list.<br />If no audiences are provided, the audience will default to the audience of the<br />Kubernetes apiserver (kubernetes.default.svc). | [https://kubernetes.default.svc] | |


Expand Down Expand Up @@ -419,7 +419,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `name` _string_ | Name is a name Service Mesh Control Plane. Defaults to "data-science-smcp". | data-science-smcp | |
| `namespace` _string_ | Namespace is a namespace where Service Mesh is deployed. Defaults to "istio-system". | istio-system | |
| `namespace` _string_ | Namespace is a namespace where Service Mesh is deployed. Defaults to "istio-system". | istio-system | MaxLength: 63 <br />Pattern: `^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$` <br /> |
| `metricsCollection` _string_ | MetricsCollection specifies if metrics from components on the Mesh namespace<br />should be collected. Setting the value to "Istio" will collect metrics from the<br />control plane and any proxies on the Mesh namespace (like gateway pods). Setting<br />to "None" will disable metrics collection. | Istio | Enum: [Istio None] <br /> |


Expand Down Expand Up @@ -603,7 +603,7 @@ _Appears in:_

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `applicationsNamespace` _string_ | Namespace for applications to be installed, non-configurable, default to "redhat-ods-applications" | redhat-ods-applications | |
| `applicationsNamespace` _string_ | Namespace for applications to be installed, non-configurable, default to "redhat-ods-applications" | redhat-ods-applications | MaxLength: 63 <br />Pattern: `^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$` <br /> |
| `monitoring` _[Monitoring](#monitoring)_ | Enable monitoring on specified namespace | | |
| `serviceMesh` _[ServiceMeshSpec](#servicemeshspec)_ | Configures Service Mesh as networking layer for Data Science Clusters components.<br />The Service Mesh is a mandatory prerequisite for single model serving (KServe) and<br />you should review this configuration if you are planning to use KServe.<br />For other components, it enhances user experience; e.g. it provides unified<br />authentication giving a Single Sign On experience. | | |
| `trustedCABundle` _[TrustedCABundleSpec](#trustedcabundlespec)_ | When set to `Managed`, adds odh-trusted-ca-bundle Configmap to all namespaces that includes<br />cluster-wide Trusted CA Bundle in .data["ca-bundle.crt"].<br />Additionally, this fields allows admins to add custom CA bundles to the configmap using the .CustomCABundle field. | | |
Expand Down Expand Up @@ -662,7 +662,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `managementState` _[ManagementState](#managementstate)_ | Set to one of the following values:<br />- "Managed" : the operator is actively managing the component and trying to keep it active.<br /> It will only upgrade the component if it is safe to do so.<br />- "Removed" : the operator is actively managing the component and will not install it,<br /> or if it is installed, the operator will try to remove it. | | Enum: [Managed Removed] <br /> |
| `namespace` _string_ | Namespace for monitoring if it is enabled | redhat-ods-monitoring | |
| `namespace` _string_ | Namespace for monitoring if it is enabled | redhat-ods-monitoring | MaxLength: 63 <br />Pattern: `^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$` <br /> |


#### TrustedCABundleSpec
Expand Down

0 comments on commit 7bea1fd

Please sign in to comment.