Skip to content

Commit 9a9eb85

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 9a9eb85

File tree

7 files changed

+132
-0
lines changed

7 files changed

+132
-0
lines changed

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

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,109 @@ 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 and not exceed 63 characters"
595+
- name: Should not be able to create an IngressController with domain label exceeding 63 characters
596+
initial: |
597+
apiVersion: operator.openshift.io/v1
598+
kind: IngressController
599+
metadata:
600+
name: ic-spec-domain-test
601+
namespace: openshift-ingress-operator
602+
spec:
603+
domain: "foo.1aaaaaaaaa2bbbbbbbbb3ccccccccc4ddddddddd5eeeeeeeee6fffffffff7gggg.com"
604+
expectedError: "domain must consist of lowercase alphanumeric characters, '-' or '.', and each label must start and end with an alphanumeric character and not exceed 63 characters"
605+
onUpdate:
606+
- name: Should be able to update invalid domain to a valid domain
607+
initial: |
608+
apiVersion: operator.openshift.io/v1
609+
kind: IngressController
610+
metadata:
611+
name: ic-spec-domain-test
612+
namespace: openshift-ingress-operator
613+
spec:
614+
domain: "*.foo.com"
615+
updated: |
616+
apiVersion: operator.openshift.io/v1
617+
kind: IngressController
618+
metadata:
619+
name: ic-spec-domain-test
620+
namespace: openshift-ingress-operator
621+
spec:
622+
domain: "123-foo.com"
623+
expected: |
624+
apiVersion: operator.openshift.io/v1
625+
kind: IngressController
626+
metadata:
627+
name: ic-spec-domain-test
628+
namespace: openshift-ingress-operator
629+
spec:
630+
domain: "123-foo.com"
631+
- name: Should be able to retain already invalid domain when it is not modified on update
632+
initial: |
633+
apiVersion: operator.openshift.io/v1
634+
kind: IngressController
635+
metadata:
636+
name: ic-spec-domain-test
637+
namespace: openshift-ingress-operator
638+
spec:
639+
domain: "*.foo.com"
640+
updated: |
641+
apiVersion: operator.openshift.io/v1
642+
kind: IngressController
643+
metadata:
644+
name: ic-spec-domain-test
645+
namespace: openshift-ingress-operator
646+
spec:
647+
domain: "*.foo.com"
648+
expected: |
649+
apiVersion: operator.openshift.io/v1
650+
kind: IngressController
651+
metadata:
652+
name: ic-spec-domain-test
653+
namespace: openshift-ingress-operator
654+
spec:
655+
domain: "*.foo.com"
656+
- name: Should not be able to update already invalid domain to another invalid domain
657+
initial: |
658+
apiVersion: operator.openshift.io/v1
659+
kind: IngressController
660+
metadata:
661+
name: ic-spec-domain-test
662+
namespace: openshift-ingress-operator
663+
spec:
664+
domain: "*.foo.com"
665+
updated: |
666+
apiVersion: operator.openshift.io/v1
667+
kind: IngressController
668+
metadata:
669+
name: ic-spec-domain-test
670+
namespace: openshift-ingress-operator
671+
spec:
672+
domain: "foo.*.com"
673+
expectedError: "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

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 and not exceed 63 characters"
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 and not exceed 63 characters
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 and not exceed 63 characters
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 and not exceed 63 characters
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 and not exceed 63 characters
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 and not exceed 63 characters
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)