Skip to content

[WIP] OCPBUGS-55192: Add IngressController .spec.domain validation #2308

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,99 @@ tests:
tuningOptions:
connectTimeout: "4 s"
expectedError: "IngressController.operator.openshift.io \"default\" is invalid: spec.tuningOptions.connectTimeout: Invalid value: \"4 s\": spec.tuningOptions.connectTimeout in body should match '^(0|([0-9]+(\\.[0-9]+)?(ns|us|µs|μs|ms|s|m|h))+)$'"
- name: Should be able to create an IngressController with valid domain
initial: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "foo.com"
expected: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "foo.com"
- name: Should not be able to create an IngressController with invalid domain
initial: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "*.foo.com"
expectedError: "domain must consist of lowercase alphanumeric characters, '-' or '.', and each label must start and end with an alphanumeric character"
onUpdate:
- name: Should be able to update invalid domain to a valid domain
initial: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "*.foo.com"
updated: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "123-foo.com"
expected: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "123-foo.com"
- name: Should be able to retain already invalid domain when it is not modified on update
initial: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "*.foo.com"
updated: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "*.foo.com"
expected: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "*.foo.com"
- name: Should not be able to update already invalid domain to another invalid domain
initial: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "*.foo.com"
updated: |
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: ic-spec-domain-test
namespace: openshift-ingress-operator
spec:
domain: "foo.*.com"
expectedError: "domain must consist of lowercase alphanumeric characters, '-' or '.', and each label must start and end with an alphanumeric character"
1 change: 1 addition & 0 deletions operator/v1/types_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type IngressControllerSpec struct {
//
// If empty, defaults to ingress.config.openshift.io/cluster .spec.domain.
//
// +kubebuilder:validation:XValidation:rule="(has(oldSelf) && self == oldSelf) || self.matches('^([a-z0-9]+|[a-z0-9]+[a-z0-9\\-]*[a-z0-9]+)(\\.([a-z0-9]+|[a-z0-9]+[a-z0-9\\-]*[a-z0-9]+))*$')",message="domain must consist of lowercase alphanumeric characters, '-' or '.', and each label must start and end with an alphanumeric character"
// +optional
Domain string `json:"domain,omitempty"`

Expand Down