Skip to content

Commit c4e9ebf

Browse files
committed
Add IngressController .spec.domain API validation
This commit fixes OCPBUGS-55192. https://issues.redhat.com/browse/OCPBUGS-55192 Add ratcheting validation of the .spec.domain field of ingress controller. Domain must consist of lowercase alphanumeric characters '-' or '.', and each label must start and end with an alphanumeric character and not exceed 63 characters. * operator/v1/types_ingress.go (IngressControllerSpec): Add ratcheting validation of the Domain field. * operator/v1/tests/ingresscontrollers.operator.openshift.io/AAA_ungated.yaml Add test cases for the ingress controller .spec.domain field validation Generated files: * operator/v1/zz_generated.crd-manifests/0000_50_ingress_00_ingresscontrollers.crd.yaml * operator/v1/zz_generated.featuregated-crd-manifests/ingresscontrollers.operator.openshift.io/AAA_ungated.yaml * operator/v1/zz_generated.featuregated-crd-manifests/ingresscontrollers.operator.openshift.io/IngressControllerLBSubnetsAWS.yaml * operator/v1/zz_generated.featuregated-crd-manifests/ingresscontrollers.operator.openshift.io/SetEIPForNLBIngressController+IngressControllerLBSubnetsAWS.yaml * operator/v1/zz_generated.featuregated-crd-manifests/ingresscontrollers.operator.openshift.io/SetEIPForNLBIngressController.yaml
1 parent 9052dea commit c4e9ebf

File tree

7 files changed

+122
-0
lines changed

7 files changed

+122
-0
lines changed

operator/v1/tests/ingresscontrollers.operator.openshift.io/AAA_ungated.yaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,99 @@ tests:
565565
tuningOptions:
566566
connectTimeout: "4 s"
567567
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))+)$'"
568+
- name: Should be able to create an IngressController with valid domain
569+
initial: |
570+
apiVersion: operator.openshift.io/v1
571+
kind: IngressController
572+
metadata:
573+
name: ic-spec-domain-test
574+
namespace: openshift-ingress-operator
575+
spec:
576+
domain: "foo.com"
577+
expected: |
578+
apiVersion: operator.openshift.io/v1
579+
kind: IngressController
580+
metadata:
581+
name: ic-spec-domain-test
582+
namespace: openshift-ingress-operator
583+
spec:
584+
domain: "foo.com"
585+
- name: Should not be able to create an IngressController with invalid domain
586+
initial: |
587+
apiVersion: operator.openshift.io/v1
588+
kind: IngressController
589+
metadata:
590+
name: ic-spec-domain-test
591+
namespace: openshift-ingress-operator
592+
spec:
593+
domain: "*.foo.com"
594+
expectedError: "domain must consist of lowercase alphanumeric characters, '-' or '.', and each label must start and end with an alphanumeric character"
595+
onUpdate:
596+
- name: Should be able to update invalid domain to a valid domain
597+
initial: |
598+
apiVersion: operator.openshift.io/v1
599+
kind: IngressController
600+
metadata:
601+
name: ic-spec-domain-test
602+
namespace: openshift-ingress-operator
603+
spec:
604+
domain: "*.foo.com"
605+
updated: |
606+
apiVersion: operator.openshift.io/v1
607+
kind: IngressController
608+
metadata:
609+
name: ic-spec-domain-test
610+
namespace: openshift-ingress-operator
611+
spec:
612+
domain: "123-foo.com"
613+
expected: |
614+
apiVersion: operator.openshift.io/v1
615+
kind: IngressController
616+
metadata:
617+
name: ic-spec-domain-test
618+
namespace: openshift-ingress-operator
619+
spec:
620+
domain: "123-foo.com"
621+
- name: Should be able to retain already invalid domain when it is not modified on update
622+
initial: |
623+
apiVersion: operator.openshift.io/v1
624+
kind: IngressController
625+
metadata:
626+
name: ic-spec-domain-test
627+
namespace: openshift-ingress-operator
628+
spec:
629+
domain: "*.foo.com"
630+
updated: |
631+
apiVersion: operator.openshift.io/v1
632+
kind: IngressController
633+
metadata:
634+
name: ic-spec-domain-test
635+
namespace: openshift-ingress-operator
636+
spec:
637+
domain: "*.foo.com"
638+
expected: |
639+
apiVersion: operator.openshift.io/v1
640+
kind: IngressController
641+
metadata:
642+
name: ic-spec-domain-test
643+
namespace: openshift-ingress-operator
644+
spec:
645+
domain: "*.foo.com"
646+
- name: Should not be able to update already invalid domain to another invalid domain
647+
initial: |
648+
apiVersion: operator.openshift.io/v1
649+
kind: IngressController
650+
metadata:
651+
name: ic-spec-domain-test
652+
namespace: openshift-ingress-operator
653+
spec:
654+
domain: "*.foo.com"
655+
updated: |
656+
apiVersion: operator.openshift.io/v1
657+
kind: IngressController
658+
metadata:
659+
name: ic-spec-domain-test
660+
namespace: openshift-ingress-operator
661+
spec:
662+
domain: "foo.*.com"
663+
expectedError: "domain must consist of lowercase alphanumeric characters, '-' or '.', and each label must start and end with an alphanumeric character"

operator/v1/types_ingress.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type IngressControllerSpec struct {
6868
//
6969
// If empty, defaults to ingress.config.openshift.io/cluster .spec.domain.
7070
//
71+
// +kubebuilder:validation:XValidation:rule="(has(oldSelf) && self == oldSelf) || self.matches('^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)'+'(\\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*$')",message="domain must consist of lowercase alphanumeric characters, '-' or '.', and each label must start and end with an alphanumeric character"
7172
// +optional
7273
Domain string `json:"domain,omitempty"`
7374

operator/v1/zz_generated.crd-manifests/0000_50_ingress_00_ingresscontrollers.crd.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ spec:
165165
166166
If empty, defaults to ingress.config.openshift.io/cluster .spec.domain.
167167
type: string
168+
x-kubernetes-validations:
169+
- message: domain must consist of lowercase alphanumeric characters,
170+
'-' or '.', and each label must start and end with an alphanumeric
171+
character
172+
rule: (has(oldSelf) && self == oldSelf) || self.matches('^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)'+'(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*$')
168173
endpointPublishingStrategy:
169174
description: |-
170175
endpointPublishingStrategy is used to publish the ingress controller

operator/v1/zz_generated.featuregated-crd-manifests/ingresscontrollers.operator.openshift.io/AAA_ungated.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ spec:
166166
167167
If empty, defaults to ingress.config.openshift.io/cluster .spec.domain.
168168
type: string
169+
x-kubernetes-validations:
170+
- message: domain must consist of lowercase alphanumeric characters,
171+
'-' or '.', and each label must start and end with an alphanumeric
172+
character
173+
rule: (has(oldSelf) && self == oldSelf) || self.matches('^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)'+'(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*$')
169174
endpointPublishingStrategy:
170175
description: |-
171176
endpointPublishingStrategy is used to publish the ingress controller

operator/v1/zz_generated.featuregated-crd-manifests/ingresscontrollers.operator.openshift.io/IngressControllerLBSubnetsAWS.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ spec:
166166
167167
If empty, defaults to ingress.config.openshift.io/cluster .spec.domain.
168168
type: string
169+
x-kubernetes-validations:
170+
- message: domain must consist of lowercase alphanumeric characters,
171+
'-' or '.', and each label must start and end with an alphanumeric
172+
character
173+
rule: (has(oldSelf) && self == oldSelf) || self.matches('^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)'+'(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*$')
169174
endpointPublishingStrategy:
170175
description: |-
171176
endpointPublishingStrategy is used to publish the ingress controller

operator/v1/zz_generated.featuregated-crd-manifests/ingresscontrollers.operator.openshift.io/SetEIPForNLBIngressController+IngressControllerLBSubnetsAWS.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ spec:
167167
168168
If empty, defaults to ingress.config.openshift.io/cluster .spec.domain.
169169
type: string
170+
x-kubernetes-validations:
171+
- message: domain must consist of lowercase alphanumeric characters,
172+
'-' or '.', and each label must start and end with an alphanumeric
173+
character
174+
rule: (has(oldSelf) && self == oldSelf) || self.matches('^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)'+'(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*$')
170175
endpointPublishingStrategy:
171176
description: |-
172177
endpointPublishingStrategy is used to publish the ingress controller

operator/v1/zz_generated.featuregated-crd-manifests/ingresscontrollers.operator.openshift.io/SetEIPForNLBIngressController.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ spec:
166166
167167
If empty, defaults to ingress.config.openshift.io/cluster .spec.domain.
168168
type: string
169+
x-kubernetes-validations:
170+
- message: domain must consist of lowercase alphanumeric characters,
171+
'-' or '.', and each label must start and end with an alphanumeric
172+
character
173+
rule: (has(oldSelf) && self == oldSelf) || self.matches('^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)'+'(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*$')
169174
endpointPublishingStrategy:
170175
description: |-
171176
endpointPublishingStrategy is used to publish the ingress controller

0 commit comments

Comments
 (0)