Skip to content

Commit

Permalink
Add field validations and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adriengentil committed Jun 12, 2023
1 parent 1974bb3 commit 3361940
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 4 deletions.
Expand Up @@ -597,15 +597,23 @@ spec:
description: CloudControllerManager contains settings specific to the external Cloud Controller Manager (a.k.a. CCM or CPI)
properties:
state:
default: ""
description: "state determines whether or not an external Cloud Controller Manager is expected to be installed within the cluster. https://kubernetes.io/docs/tasks/administer-cluster/running-cloud-controller/#running-cloud-controller-manager \n When set to \"External\", new nodes will be tainted as uninitialized when created, preventing them from running workloads until they are initialized by the cloud controller manager. When omitted or set to \"None\", new nodes will be not tainted and no extra initialization from the cloud controller manager is expected."
enum:
- ""
- External
- None
type: string
x-kubernetes-validations:
- message: state is immutable once set
rule: self == oldSelf
type: object
x-kubernetes-validations:
- message: state cannot be added or removed once set
rule: has(self.state) == has(oldSelf.state)
type: object
x-kubernetes-validations:
- message: cloudControllerManager added or removed once set
rule: has(self.cloudControllerManager) == has(oldSelf.cloudControllerManager)
gcp:
description: GCP contains settings specific to the Google Cloud Platform infrastructure provider.
properties:
Expand Down
Expand Up @@ -620,15 +620,23 @@ spec:
description: CloudControllerManager contains settings specific to the external Cloud Controller Manager (a.k.a. CCM or CPI)
properties:
state:
default: ""
description: "state determines whether or not an external Cloud Controller Manager is expected to be installed within the cluster. https://kubernetes.io/docs/tasks/administer-cluster/running-cloud-controller/#running-cloud-controller-manager \n When set to \"External\", new nodes will be tainted as uninitialized when created, preventing them from running workloads until they are initialized by the cloud controller manager. When omitted or set to \"None\", new nodes will be not tainted and no extra initialization from the cloud controller manager is expected."
enum:
- ""
- External
- None
type: string
x-kubernetes-validations:
- message: state is immutable once set
rule: self == oldSelf
type: object
x-kubernetes-validations:
- message: state cannot be added or removed once set
rule: has(self.state) == has(oldSelf.state)
type: object
x-kubernetes-validations:
- message: cloudControllerManager added or removed once set
rule: has(self.cloudControllerManager) == has(oldSelf.cloudControllerManager)
gcp:
description: GCP contains settings specific to the Google Cloud Platform infrastructure provider.
properties:
Expand Down
114 changes: 114 additions & 0 deletions config/v1/stable.infrastructure.testsuite.yaml
Expand Up @@ -56,6 +56,120 @@ tests:
external:
platformName: SomeOtherCoolplatformName
expectedError: " spec.platformSpec.external.platformName: Invalid value: \"string\": platform name cannot be changed once set"
- name: Should not be able to update External cloudControllerManager state once it was set
initial: |
apiVersion: config.openshift.io/v1
kind: Infrastructure
spec: {}
status:
platform: External
platformStatus:
type: External
external:
cloudControllerManager:
state: ""
updated: |
apiVersion: config.openshift.io/v1
kind: Infrastructure
spec: {}
status:
platform: External
platformStatus:
type: External
external:
cloudControllerManager:
state: External
expectedStatusError: " status.platformStatus.external.cloudControllerManager.state: Invalid value: \"string\": state is immutable once set"
- name: Should not be able to add External cloudControllerManager state once it was set
initial: |
apiVersion: config.openshift.io/v1
kind: Infrastructure
spec: {}
status:
platform: External
platformStatus:
type: External
external:
cloudControllerManager: {}
updated: |
apiVersion: config.openshift.io/v1
kind: Infrastructure
spec: {}
status:
platform: External
platformStatus:
type: External
external:
cloudControllerManager:
state: External
expectedStatusError: " status.platformStatus.external.cloudControllerManager: Invalid value: \"object\": state cannot be added or removed once set"
- name: Should not be able to remove External cloudControllerManager state once it was set
initial: |
apiVersion: config.openshift.io/v1
kind: Infrastructure
spec: {}
status:
platform: External
platformStatus:
type: External
external:
cloudControllerManager:
state: External
updated: |
apiVersion: config.openshift.io/v1
kind: Infrastructure
spec: {}
status:
platform: External
platformStatus:
type: External
external:
cloudControllerManager: {}
expectedStatusError: " status.platformStatus.external.cloudControllerManager: Invalid value: \"object\": state cannot be added or removed once set"
- name: Should not be able to add External cloudControllerManager once it was set
initial: |
apiVersion: config.openshift.io/v1
kind: Infrastructure
spec: {}
status:
platform: External
platformStatus:
type: External
external: {}
updated: |
apiVersion: config.openshift.io/v1
kind: Infrastructure
spec: {}
status:
platform: External
platformStatus:
type: External
external:
cloudControllerManager:
state: External
expectedStatusError: " status.platformStatus.external: Invalid value: \"object\": cloudControllerManager added or removed once set"
- name: Should not be able to remove cloudControllerManager once it was set
initial: |
apiVersion: config.openshift.io/v1
kind: Infrastructure
spec: {}
status:
platform: External
platformStatus:
type: External
external:
cloudControllerManager:
state: None
updated: |
apiVersion: config.openshift.io/v1
kind: Infrastructure
spec: {}
status:
platform: External
platformStatus:
type: External
external: {}
expectedStatusError: " status.platformStatus.external: Invalid value: \"object\": cloudControllerManager added or removed once set"
- name: Should not be able to modify an existing Azure ResourceTags Tag
initial: |
apiVersion: config.openshift.io/v1
Expand Down
5 changes: 3 additions & 2 deletions config/v1/types_infrastructure.go
Expand Up @@ -331,6 +331,7 @@ const (
)

// CloudControllerManagerStatus holds the state of Cloud Controller Manager (a.k.a. CCM or CPI) related settings
// +kubebuilder:validation:XValidation:rule="has(self.state) == has(oldSelf.state)",message="state cannot be added or removed once set"
type CloudControllerManagerStatus struct {
// state determines whether or not an external Cloud Controller Manager is expected to
// be installed within the cluster.
Expand All @@ -340,14 +341,14 @@ type CloudControllerManagerStatus struct {
// preventing them from running workloads until they are initialized by the cloud controller manager.
// When omitted or set to "None", new nodes will be not tainted
// and no extra initialization from the cloud controller manager is expected.
// +kubebuilder:default:=""
// +default=""
// +kubebuilder:validation:Enum="";External;None
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="state is immutable once set"
// +optional
State CloudControllerManagerState `json:"state"`
}

// ExternalPlatformStatus holds the current status of the generic External infrastructure provider.
// +kubebuilder:validation:XValidation:rule="has(self.cloudControllerManager) == has(oldSelf.cloudControllerManager)",message="cloudControllerManager added or removed once set"
type ExternalPlatformStatus struct {
// CloudControllerManager contains settings specific to the external Cloud Controller Manager (a.k.a. CCM or CPI)
// +optional
Expand Down

0 comments on commit 3361940

Please sign in to comment.