Skip to content

Commit

Permalink
fixup! don't allow setting revisions
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Palmer <[email protected]>
  • Loading branch information
everettraven committed Feb 20, 2025
1 parent 46fc4d5 commit ce61d0a
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 274 deletions.
4 changes: 2 additions & 2 deletions openapi/generated_openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -30740,7 +30740,7 @@
],
"properties": {
"currentRevision": {
"description": "currentRevision is the generation of the most recently successful deployment. If set on creation of a nodeStatus, it must be set to 0. Updates must only increase the value.",
"description": "currentRevision is the generation of the most recently successful deployment. Can not be set on creation of a nodeStatus. Updates must only increase the value.",
"type": "integer",
"format": "int32"
},
Expand Down Expand Up @@ -30782,7 +30782,7 @@
"default": ""
},
"targetRevision": {
"description": "targetRevision is the generation of the deployment we're trying to apply. If set on creation of a nodeStatus, it must be set to 0.",
"description": "targetRevision is the generation of the deployment we're trying to apply. Can not be set on creation of a nodeStatus.",
"type": "integer",
"format": "int32"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ tests:
operatorLogLevel: Normal
onUpdate:
- name: Should reject multiple nodes with nonzero target revisions
initialCRDPatches:
- op: remove
path: /spec/versions/0/schema/openAPIV3Schema/properties/status/properties/nodeStatuses/items/x-kubernetes-validations/2
initial: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
Expand Down Expand Up @@ -43,22 +46,25 @@ tests:
- nodeName: d
expectedStatusError: "status.nodeStatuses: Invalid value: \"array\": no more than 1 node status may have a nonzero targetRevision"
- name: Should reject decreasing currentRevision
initialCRDPatches:
- op: remove
path: /spec/versions/0/schema/openAPIV3Schema/properties/status/properties/nodeStatuses/items/x-kubernetes-validations/1
initial: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
spec: {} # No spec is required for a KubeAPIServer
status:
nodeStatuses:
- nodeName: a
currentRevision: 0
currentRevision: 3
updated: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
spec: {} # No spec is required for a KubeAPIServer
status:
nodeStatuses:
- nodeName: a
currentRevision: -1
currentRevision: 2
expectedStatusError: "status.nodeStatuses[0].currentRevision: Invalid value: \"integer\": must only increase"
- name: Should reject clearing currentRevision
initialCRDPatches:
Expand All @@ -80,7 +86,7 @@ tests:
nodeStatuses:
- nodeName: a
expectedStatusError: "status.nodeStatuses[0].currentRevision: Invalid value: \"object\": cannot be unset once set"
- name: Should reject setting new nodeStatus with a non-zero currentRevision
- name: Should reject setting new nodeStatus with a currentRevision
initial: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
Expand All @@ -94,9 +100,9 @@ tests:
status:
nodeStatuses:
- nodeName: a
currentRevision: 3
expectedStatusError: "status.nodeStatuses[0]: Invalid value: \"object\": when specified on creation of a nodeStatus, currentRevision must be set to 0"
- name: Should reject setting new nodeStatus with a non-zero targetRevision
currentRevision: 0
expectedStatusError: "status.nodeStatuses[0]: Invalid value: \"object\": currentRevision can not be set on creation of a nodeStatus"
- name: Should reject setting new nodeStatus with a targetRevision
initial: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
Expand All @@ -110,8 +116,8 @@ tests:
status:
nodeStatuses:
- nodeName: a
targetRevision: 3
expectedStatusError: "status.nodeStatuses[0]: Invalid value: \"object\": when specified on creation of a nodeStatus, targetRevision must be set to 0"
targetRevision: 0
expectedStatusError: "status.nodeStatuses[0]: Invalid value: \"object\": targetRevision can not be set on creation of a nodeStatus"
- name: Should allow adding nodes with name only
initial: |
apiVersion: operator.openshift.io/v1
Expand All @@ -138,61 +144,7 @@ tests:
nodeStatuses:
- nodeName: a
- nodeName: b
- name: Should allow updating currentRevision of existing nodeStatus that specified a currentRevision on creation
initial: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
spec: {} # No spec is required for a KubeAPIServer
status:
nodeStatuses:
- nodeName: a
currentRevision: 0
updated: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
spec: {} # No spec is required for a KubeAPIServer
status:
nodeStatuses:
- nodeName: a
currentRevision: 1
expected: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
spec:
logLevel: Normal
operatorLogLevel: Normal
status:
nodeStatuses:
- nodeName: a
currentRevision: 1
- name: Should allow updating targetRevision of existing nodeStatus that specified a targetRevision on creation
initial: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
spec: {} # No spec is required for a KubeAPIServer
status:
nodeStatuses:
- nodeName: a
targetRevision: 0
updated: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
spec: {} # No spec is required for a KubeAPIServer
status:
nodeStatuses:
- nodeName: a
targetRevision: 1
expected: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
spec:
logLevel: Normal
operatorLogLevel: Normal
status:
nodeStatuses:
- nodeName: a
targetRevision: 1
- name: Should allow updating currentRevision of existing nodeStatus that did not specify a currentRevision on creation
- name: Should allow updating currentRevision of existing nodeStatus
initial: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
Expand All @@ -218,7 +170,7 @@ tests:
nodeStatuses:
- nodeName: a
currentRevision: 1
- name: Should allow updating targetRevision of existing nodeStatus that did not specify a targetRevision on creation
- name: Should allow updating targetRevision of existing nodeStatus
initial: |
apiVersion: operator.openshift.io/v1
kind: KubeAPIServer
Expand Down
8 changes: 4 additions & 4 deletions operator/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,20 @@ type StaticPodOperatorStatus struct {

// NodeStatus provides information about the current state of a particular node managed by this operator.
// +kubebuilder:validation:XValidation:rule="has(self.currentRevision) || !has(oldSelf.currentRevision)",message="cannot be unset once set",fieldPath=".currentRevision"
// +kubebuilder:validation:XValidation:rule="oldSelf.hasValue() || (has(self.currentRevision) ? self.currentRevision == 0 : true) ",message="when specified on creation of a nodeStatus, currentRevision must be set to 0",optionalOldSelf=true
// +kubebuilder:validation:XValidation:rule="oldSelf.hasValue() || (has(self.targetRevision) ? self.targetRevision == 0 : true) ",message="when specified on creation of a nodeStatus, targetRevision must be set to 0",optionalOldSelf=true
// +kubebuilder:validation:XValidation:rule="oldSelf.hasValue() || !has(self.currentRevision)",message="currentRevision can not be set on creation of a nodeStatus",optionalOldSelf=true
// +kubebuilder:validation:XValidation:rule="oldSelf.hasValue() || !has(self.targetRevision)",message="targetRevision can not be set on creation of a nodeStatus",optionalOldSelf=true
type NodeStatus struct {
// nodeName is the name of the node
// +required
NodeName string `json:"nodeName"`

// currentRevision is the generation of the most recently successful deployment.
// If set on creation of a nodeStatus, it must be set to 0. Updates must only increase the value.
// Can not be set on creation of a nodeStatus. Updates must only increase the value.
// +kubebuilder:validation:XValidation:rule="self >= oldSelf",message="must only increase"
// +optional
CurrentRevision int32 `json:"currentRevision,omitempty"`
// targetRevision is the generation of the deployment we're trying to apply.
// If set on creation of a nodeStatus, it must be set to 0.
// Can not be set on creation of a nodeStatus.
// +optional
TargetRevision int32 `json:"targetRevision,omitempty"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ spec:
currentRevision:
description: |-
currentRevision is the generation of the most recently successful deployment.
If set on creation of a nodeStatus, it must be set to 0. Updates must only increase the value.
Can not be set on creation of a nodeStatus. Updates must only increase the value.
format: int32
type: integer
x-kubernetes-validations:
Expand Down Expand Up @@ -295,7 +295,7 @@ spec:
targetRevision:
description: |-
targetRevision is the generation of the deployment we're trying to apply.
If set on creation of a nodeStatus, it must be set to 0.
Can not be set on creation of a nodeStatus.
format: int32
type: integer
required:
Expand All @@ -305,16 +305,12 @@ spec:
- fieldPath: .currentRevision
message: cannot be unset once set
rule: has(self.currentRevision) || !has(oldSelf.currentRevision)
- message: when specified on creation of a nodeStatus, currentRevision
must be set to 0
- message: currentRevision can not be set on creation of a nodeStatus
optionalOldSelf: true
rule: 'oldSelf.hasValue() || (has(self.currentRevision) ? self.currentRevision
== 0 : true) '
- message: when specified on creation of a nodeStatus, targetRevision
must be set to 0
rule: oldSelf.hasValue() || !has(self.currentRevision)
- message: targetRevision can not be set on creation of a nodeStatus
optionalOldSelf: true
rule: 'oldSelf.hasValue() || (has(self.targetRevision) ? self.targetRevision
== 0 : true) '
rule: oldSelf.hasValue() || !has(self.targetRevision)
type: array
x-kubernetes-list-map-keys:
- nodeName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ spec:
currentRevision:
description: |-
currentRevision is the generation of the most recently successful deployment.
If set on creation of a nodeStatus, it must be set to 0. Updates must only increase the value.
Can not be set on creation of a nodeStatus. Updates must only increase the value.
format: int32
type: integer
x-kubernetes-validations:
Expand Down Expand Up @@ -282,7 +282,7 @@ spec:
targetRevision:
description: |-
targetRevision is the generation of the deployment we're trying to apply.
If set on creation of a nodeStatus, it must be set to 0.
Can not be set on creation of a nodeStatus.
format: int32
type: integer
required:
Expand All @@ -292,16 +292,12 @@ spec:
- fieldPath: .currentRevision
message: cannot be unset once set
rule: has(self.currentRevision) || !has(oldSelf.currentRevision)
- message: when specified on creation of a nodeStatus, currentRevision
must be set to 0
- message: currentRevision can not be set on creation of a nodeStatus
optionalOldSelf: true
rule: 'oldSelf.hasValue() || (has(self.currentRevision) ? self.currentRevision
== 0 : true) '
- message: when specified on creation of a nodeStatus, targetRevision
must be set to 0
rule: oldSelf.hasValue() || !has(self.currentRevision)
- message: targetRevision can not be set on creation of a nodeStatus
optionalOldSelf: true
rule: 'oldSelf.hasValue() || (has(self.targetRevision) ? self.targetRevision
== 0 : true) '
rule: oldSelf.hasValue() || !has(self.targetRevision)
type: array
x-kubernetes-list-map-keys:
- nodeName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ spec:
currentRevision:
description: |-
currentRevision is the generation of the most recently successful deployment.
If set on creation of a nodeStatus, it must be set to 0. Updates must only increase the value.
Can not be set on creation of a nodeStatus. Updates must only increase the value.
format: int32
type: integer
x-kubernetes-validations:
Expand Down Expand Up @@ -295,7 +295,7 @@ spec:
targetRevision:
description: |-
targetRevision is the generation of the deployment we're trying to apply.
If set on creation of a nodeStatus, it must be set to 0.
Can not be set on creation of a nodeStatus.
format: int32
type: integer
required:
Expand All @@ -305,16 +305,12 @@ spec:
- fieldPath: .currentRevision
message: cannot be unset once set
rule: has(self.currentRevision) || !has(oldSelf.currentRevision)
- message: when specified on creation of a nodeStatus, currentRevision
must be set to 0
- message: currentRevision can not be set on creation of a nodeStatus
optionalOldSelf: true
rule: 'oldSelf.hasValue() || (has(self.currentRevision) ? self.currentRevision
== 0 : true) '
- message: when specified on creation of a nodeStatus, targetRevision
must be set to 0
rule: oldSelf.hasValue() || !has(self.currentRevision)
- message: targetRevision can not be set on creation of a nodeStatus
optionalOldSelf: true
rule: 'oldSelf.hasValue() || (has(self.targetRevision) ? self.targetRevision
== 0 : true) '
rule: oldSelf.hasValue() || !has(self.targetRevision)
type: array
x-kubernetes-list-map-keys:
- nodeName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ spec:
currentRevision:
description: |-
currentRevision is the generation of the most recently successful deployment.
If set on creation of a nodeStatus, it must be set to 0. Updates must only increase the value.
Can not be set on creation of a nodeStatus. Updates must only increase the value.
format: int32
type: integer
x-kubernetes-validations:
Expand Down Expand Up @@ -295,7 +295,7 @@ spec:
targetRevision:
description: |-
targetRevision is the generation of the deployment we're trying to apply.
If set on creation of a nodeStatus, it must be set to 0.
Can not be set on creation of a nodeStatus.
format: int32
type: integer
required:
Expand All @@ -305,16 +305,12 @@ spec:
- fieldPath: .currentRevision
message: cannot be unset once set
rule: has(self.currentRevision) || !has(oldSelf.currentRevision)
- message: when specified on creation of a nodeStatus, currentRevision
must be set to 0
- message: currentRevision can not be set on creation of a nodeStatus
optionalOldSelf: true
rule: 'oldSelf.hasValue() || (has(self.currentRevision) ? self.currentRevision
== 0 : true) '
- message: when specified on creation of a nodeStatus, targetRevision
must be set to 0
rule: oldSelf.hasValue() || !has(self.currentRevision)
- message: targetRevision can not be set on creation of a nodeStatus
optionalOldSelf: true
rule: 'oldSelf.hasValue() || (has(self.targetRevision) ? self.targetRevision
== 0 : true) '
rule: oldSelf.hasValue() || !has(self.targetRevision)
type: array
x-kubernetes-list-map-keys:
- nodeName
Expand Down
Loading

0 comments on commit ce61d0a

Please sign in to comment.