Skip to content

Commit

Permalink
Use fieldPath and reason to provide better error output from CEL
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelSpeed committed Apr 24, 2024
1 parent fece3d3 commit 44d5634
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
@@ -0,0 +1,7 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
feature-gate.release.openshift.io/: "true"
include.release.openshift.io/self-managed-high-availability: "true"
name: machines.machine.openshift.io
@@ -0,0 +1,23 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
feature-gate.release.openshift.io/MachineAPIMigration: "true"
include.release.openshift.io/self-managed-high-availability: "true"
name: machines.machine.openshift.io
spec:
versions:
- name: v1beta1
schema:
openAPIV3Schema:
properties:
status:
x-kubernetes-validations:
- fieldPath: .synchronizedGeneration
message: synchronizedGeneration must not decrease unless authoritativeAPI
is transitioning from Migrating to another value
reason: FieldValueForbidden
rule: '!has(oldSelf.synchronizedGeneration) || (has(self.synchronizedGeneration)
&& self.synchronizedGeneration >= oldSelf.synchronizedGeneration)
|| (oldSelf.authoritativeAPI == ''Migrating'' && self.authoritativeAPI
!= ''Migrating'')'
@@ -0,0 +1,23 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
feature-gate.release.openshift.io/MachineAPIMigration: "true"
include.release.openshift.io/self-managed-high-availability: "true"
name: machinesets.machine.openshift.io
spec:
versions:
- name: v1beta1
schema:
openAPIV3Schema:
properties:
status:
x-kubernetes-validations:
- fieldPath: .synchronizedGeneration
message: synchronizedGeneration must not decrease unless authoritativeAPI
is transitioning from Migrating to another value
reason: FieldValueForbidden
rule: '!has(oldSelf.synchronizedGeneration) || (has(self.synchronizedGeneration)
&& self.synchronizedGeneration >= oldSelf.synchronizedGeneration)
|| (oldSelf.authoritativeAPI == ''Migrating'' && self.authoritativeAPI
!= ''Migrating'')'
Expand Up @@ -326,7 +326,7 @@ tests:
status:
authoritativeAPI: MachineAPI
synchronizedGeneration: 1
expectedStatusError: "status: Invalid value: \"object\": syncronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
expectedStatusError: "status.synchronizedGeneration: Forbidden: synchronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
- name: Should not allow decreasing the synchronizedGeneration while the Authoritative API is Migrating
initial: |
apiVersion: machine.openshift.io/v1beta1
Expand All @@ -344,7 +344,7 @@ tests:
status:
authoritativeAPI: Migrating
synchronizedGeneration: 1
expectedStatusError: "status: Invalid value: \"object\": syncronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
expectedStatusError: "status.synchronizedGeneration: Forbidden: syncronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
- name: Should not allow decreasing the synchronizedGeneration while the Authoritative API is ClusterAPI
initial: |
apiVersion: machine.openshift.io/v1beta1
Expand All @@ -362,7 +362,7 @@ tests:
status:
authoritativeAPI: ClusterAPI
synchronizedGeneration: 1
expectedStatusError: "status: Invalid value: \"object\": syncronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
expectedStatusError: "status.synchronizedGeneration: Forbidden: syncronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
- name: Should allow decreasing the synchronizedGeneration while the Authoritative API is moved from Migrating to MachineAPI
initial: |
apiVersion: machine.openshift.io/v1beta1
Expand Down
Expand Up @@ -339,7 +339,7 @@ tests:
status:
authoritativeAPI: MachineAPI
synchronizedGeneration: 1
expectedStatusError: "status: Invalid value: \"object\": syncronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
expectedStatusError: "status.synchronizedGeneration: Forbidden: synchronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
- name: Should not allow decreasing the synchronizedGeneration while the Authoritative API is Migrating
initial: |
apiVersion: machine.openshift.io/v1beta1
Expand All @@ -357,7 +357,7 @@ tests:
status:
authoritativeAPI: Migrating
synchronizedGeneration: 1
expectedStatusError: "status: Invalid value: \"object\": syncronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
expectedStatusError: "status.synchronizedGeneration: Forbidden: syncronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
- name: Should not allow decreasing the synchronizedGeneration while the Authoritative API is ClusterAPI
initial: |
apiVersion: machine.openshift.io/v1beta1
Expand All @@ -375,7 +375,7 @@ tests:
status:
authoritativeAPI: ClusterAPI
synchronizedGeneration: 1
expectedStatusError: "status: Invalid value: \"object\": syncronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
expectedStatusError: "status.synchronizedGeneration: Forbidden: syncronizedGeneration must not decrease unless authoritativeAPI is transitioning from Migrating to another value"
- name: Should allow decreasing the synchronizedGeneration while the Authoritative API is moved from Migrating to MachineAPI
initial: |
apiVersion: machine.openshift.io/v1beta1
Expand Down
Expand Up @@ -526,8 +526,10 @@ spec:
type: integer
type: object
x-kubernetes-validations:
- message: synchronizedGeneration must not decrease unless authoritativeAPI
- fieldPath: .synchronizedGeneration
message: synchronizedGeneration must not decrease unless authoritativeAPI
is transitioning from Migrating to another value
reason: FieldValueForbidden
rule: '!has(oldSelf.synchronizedGeneration) || (has(self.synchronizedGeneration)
&& self.synchronizedGeneration >= oldSelf.synchronizedGeneration)
|| (oldSelf.authoritativeAPI == ''Migrating'' && self.authoritativeAPI
Expand Down
Expand Up @@ -611,8 +611,10 @@ spec:
type: integer
type: object
x-kubernetes-validations:
- message: synchronizedGeneration must not decrease unless authoritativeAPI
- fieldPath: .synchronizedGeneration
message: synchronizedGeneration must not decrease unless authoritativeAPI
is transitioning from Migrating to another value
reason: FieldValueForbidden
rule: '!has(oldSelf.synchronizedGeneration) || (has(self.synchronizedGeneration)
&& self.synchronizedGeneration >= oldSelf.synchronizedGeneration)
|| (oldSelf.authoritativeAPI == ''Migrating'' && self.authoritativeAPI
Expand Down

0 comments on commit 44d5634

Please sign in to comment.