Skip to content

Commit c3cea74

Browse files
committed
Add CEL validation to prevent stale timestamp updates
- Add XValidation rule on PacemakerClusterStatus to reject updates where lastUpdated < oldSelf.lastUpdated - Prevents race conditions when multiple collector jobs run concurrently (Replace or Allow concurrency policy) - Server-side enforcement ensures stale updates are rejected by API server
1 parent 8c8680a commit c3cea74

File tree

6 files changed

+642
-106940
lines changed

6 files changed

+642
-106940
lines changed

etcd/v1alpha1/types_pacemakercluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ type PacemakerClusterSpec struct {
189189
}
190190

191191
// PacemakerClusterStatus contains the actual pacemaker cluster status information
192+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.lastUpdated) || !has(self.lastUpdated) || self.lastUpdated >= oldSelf.lastUpdated",message="lastUpdated cannot be set to an earlier timestamp than the current value"
192193
type PacemakerClusterStatus struct {
193194
// lastUpdated is the timestamp when this status was last updated
194195
// When present, it must be a valid timestamp in RFC3339 format.

etcd/v1alpha1/zz_generated.crd-manifests/0000_25_etcd_01_pacemakerclusters.crd.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ spec:
408408
type: integer
409409
type: object
410410
type: object
411+
x-kubernetes-validations:
412+
- message: lastUpdated cannot be set to an earlier timestamp than the
413+
current value
414+
rule: '!has(oldSelf.lastUpdated) || !has(self.lastUpdated) || self.lastUpdated
415+
>= oldSelf.lastUpdated'
411416
type: object
412417
served: true
413418
storage: true

etcd/v1alpha1/zz_generated.featuregated-crd-manifests/pacemakerclusters.etcd.openshift.io/AAA_ungated.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ spec:
409409
type: integer
410410
type: object
411411
type: object
412+
x-kubernetes-validations:
413+
- message: lastUpdated cannot be set to an earlier timestamp than the
414+
current value
415+
rule: '!has(oldSelf.lastUpdated) || !has(self.lastUpdated) || self.lastUpdated
416+
>= oldSelf.lastUpdated'
412417
type: object
413418
served: true
414419
storage: true

0 commit comments

Comments
 (0)