Skip to content

Commit 558db4f

Browse files
committed
Add ClusterAPI observedRevisionGeneration
1 parent 275bc2c commit 558db4f

7 files changed

Lines changed: 275 additions & 4 deletions

File tree

openapi/generated_openapi/zz_generated.openapi.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/v1alpha1/tests/clusterapis.operator.openshift.io/ClusterAPIMachineManagement.yaml

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,3 +1070,221 @@ tests:
10701070
components:
10711071
- type: Image
10721072
expectedStatusError: "image is required when type is Image, and forbidden otherwise"
1073+
1074+
# observedRevisionGeneration validation tests
1075+
1076+
- name: Should reject observedGeneration less than 1
1077+
initial: |
1078+
apiVersion: operator.openshift.io/v1alpha1
1079+
kind: ClusterAPI
1080+
metadata:
1081+
name: cluster
1082+
spec: {}
1083+
updated: |
1084+
apiVersion: operator.openshift.io/v1alpha1
1085+
kind: ClusterAPI
1086+
metadata:
1087+
name: cluster
1088+
spec: {}
1089+
status:
1090+
observedRevisionGeneration: 0
1091+
desiredRevision: rev-1
1092+
revisions:
1093+
- name: rev-1
1094+
revision: 1
1095+
contentID: content-1
1096+
components:
1097+
- type: Image
1098+
image:
1099+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1100+
profile: default
1101+
expectedStatusError: "should be greater than or equal to 1"
1102+
1103+
- name: Should accept increasing observedGeneration
1104+
initial: |
1105+
apiVersion: operator.openshift.io/v1alpha1
1106+
kind: ClusterAPI
1107+
metadata:
1108+
name: cluster
1109+
spec: {}
1110+
status:
1111+
observedRevisionGeneration: 1
1112+
desiredRevision: rev-1
1113+
revisions:
1114+
- name: rev-1
1115+
revision: 1
1116+
contentID: content-1
1117+
components:
1118+
- type: Image
1119+
image:
1120+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1121+
profile: default
1122+
updated: |
1123+
apiVersion: operator.openshift.io/v1alpha1
1124+
kind: ClusterAPI
1125+
metadata:
1126+
name: cluster
1127+
spec: {}
1128+
status:
1129+
observedRevisionGeneration: 2
1130+
desiredRevision: rev-1
1131+
revisions:
1132+
- name: rev-1
1133+
revision: 1
1134+
contentID: content-1
1135+
components:
1136+
- type: Image
1137+
image:
1138+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1139+
profile: default
1140+
expected: |
1141+
apiVersion: operator.openshift.io/v1alpha1
1142+
kind: ClusterAPI
1143+
metadata:
1144+
name: cluster
1145+
spec: {}
1146+
status:
1147+
observedRevisionGeneration: 2
1148+
desiredRevision: rev-1
1149+
revisions:
1150+
- name: rev-1
1151+
revision: 1
1152+
contentID: content-1
1153+
components:
1154+
- type: Image
1155+
image:
1156+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1157+
profile: default
1158+
1159+
- name: Should accept keeping observedGeneration the same
1160+
initial: |
1161+
apiVersion: operator.openshift.io/v1alpha1
1162+
kind: ClusterAPI
1163+
metadata:
1164+
name: cluster
1165+
spec: {}
1166+
status:
1167+
observedRevisionGeneration: 1
1168+
desiredRevision: rev-1
1169+
revisions:
1170+
- name: rev-1
1171+
revision: 1
1172+
contentID: content-1
1173+
components:
1174+
- type: Image
1175+
image:
1176+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1177+
profile: default
1178+
updated: |
1179+
apiVersion: operator.openshift.io/v1alpha1
1180+
kind: ClusterAPI
1181+
metadata:
1182+
name: cluster
1183+
spec: {}
1184+
status:
1185+
observedRevisionGeneration: 1
1186+
desiredRevision: rev-1
1187+
revisions:
1188+
- name: rev-1
1189+
revision: 1
1190+
contentID: content-1
1191+
components:
1192+
- type: Image
1193+
image:
1194+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1195+
profile: default
1196+
expected: |
1197+
apiVersion: operator.openshift.io/v1alpha1
1198+
kind: ClusterAPI
1199+
metadata:
1200+
name: cluster
1201+
spec: {}
1202+
status:
1203+
observedRevisionGeneration: 1
1204+
desiredRevision: rev-1
1205+
revisions:
1206+
- name: rev-1
1207+
revision: 1
1208+
contentID: content-1
1209+
components:
1210+
- type: Image
1211+
image:
1212+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1213+
profile: default
1214+
1215+
- name: Should reject decreasing observedGeneration
1216+
initial: |
1217+
apiVersion: operator.openshift.io/v1alpha1
1218+
kind: ClusterAPI
1219+
metadata:
1220+
name: cluster
1221+
spec: {}
1222+
status:
1223+
observedRevisionGeneration: 5
1224+
desiredRevision: rev-1
1225+
revisions:
1226+
- name: rev-1
1227+
revision: 1
1228+
contentID: content-1
1229+
components:
1230+
- type: Image
1231+
image:
1232+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1233+
profile: default
1234+
updated: |
1235+
apiVersion: operator.openshift.io/v1alpha1
1236+
kind: ClusterAPI
1237+
metadata:
1238+
name: cluster
1239+
spec: {}
1240+
status:
1241+
observedRevisionGeneration: 3
1242+
desiredRevision: rev-1
1243+
revisions:
1244+
- name: rev-1
1245+
revision: 1
1246+
contentID: content-1
1247+
components:
1248+
- type: Image
1249+
image:
1250+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1251+
profile: default
1252+
expectedStatusError: "observedRevisionGeneration may not decrease"
1253+
1254+
- name: Should reject unsetting observedGeneration once set
1255+
initial: |
1256+
apiVersion: operator.openshift.io/v1alpha1
1257+
kind: ClusterAPI
1258+
metadata:
1259+
name: cluster
1260+
spec: {}
1261+
status:
1262+
observedRevisionGeneration: 1
1263+
desiredRevision: rev-1
1264+
revisions:
1265+
- name: rev-1
1266+
revision: 1
1267+
contentID: content-1
1268+
components:
1269+
- type: Image
1270+
image:
1271+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1272+
profile: default
1273+
updated: |
1274+
apiVersion: operator.openshift.io/v1alpha1
1275+
kind: ClusterAPI
1276+
metadata:
1277+
name: cluster
1278+
spec: {}
1279+
status:
1280+
desiredRevision: rev-1
1281+
revisions:
1282+
- name: rev-1
1283+
revision: 1
1284+
contentID: content-1
1285+
components:
1286+
- type: Image
1287+
image:
1288+
ref: quay.io/openshift/cluster-api@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1289+
profile: default
1290+
expectedStatusError: "observedRevisionGeneration may not be unset once set"

operator/v1alpha1/types_clusterapi.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type RevisionName string
7878
// ClusterAPIStatus describes the current state of the capi-operator.
7979
// +kubebuilder:validation:XValidation:rule="self.revisions.exists(r, r.name == self.desiredRevision && self.revisions.all(s, s.revision <= r.revision))",message="desiredRevision must be the name of the revision with the highest revision number"
8080
// +kubebuilder:validation:XValidation:rule="!has(self.currentRevision) || self.revisions.exists(r, r.name == self.currentRevision)",message="currentRevision must correspond to an entry in the revisions list"
81+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.observedRevisionGeneration) || has(self.observedRevisionGeneration)",message="observedRevisionGeneration may not be unset once set"
8182
type ClusterAPIStatus struct {
8283
// currentRevision is the name of the most recently fully applied revision.
8384
// It is written by the installer controller. If it is absent, it indicates
@@ -111,6 +112,14 @@ type ClusterAPIStatus struct {
111112
// +kubebuilder:validation:XValidation:rule="self.all(new, oldSelf.exists(old, old.name == new.name) || oldSelf.all(old, new.revision > old.revision))",message="new revisions must have a revision number greater than all existing revisions"
112113
// +kubebuilder:validation:XValidation:rule="oldSelf.all(old, !self.exists(new, new.name == old.name) || self.exists(new, new == old))",message="existing revisions are immutable, but may be removed"
113114
Revisions []ClusterAPIInstallerRevision `json:"revisions,omitempty"`
115+
116+
// observedRevisionGeneration is the generation of the ClusterAPI object that was last observed by the revision controller.
117+
// If specified it must be greater than or equal to 1. It may not decrease or be unset once set.
118+
//
119+
// +optional
120+
// +kubebuilder:validation:Minimum=1
121+
// +kubebuilder:validation:XValidation:rule="self >= oldSelf",message="observedRevisionGeneration may not decrease"
122+
ObservedRevisionGeneration int64 `json:"observedRevisionGeneration,omitempty"`
114123
}
115124

116125
// +structType=atomic

operator/v1alpha1/zz_generated.crd-manifests/0000_30_cluster-api_01_clusterapis.crd.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ spec:
106106
maxLength: 255
107107
minLength: 1
108108
type: string
109+
observedRevisionGeneration:
110+
description: |-
111+
observedRevisionGeneration is the generation of the ClusterAPI object that was last observed by the revision controller.
112+
If specified it must be greater than or equal to 1. It may not decrease or be unset once set.
113+
format: int64
114+
minimum: 1
115+
type: integer
116+
x-kubernetes-validations:
117+
- message: observedRevisionGeneration may not decrease
118+
rule: self >= oldSelf
109119
revisions:
110120
description: |-
111121
revisions is a list of all currently active revisions. A revision is
@@ -312,6 +322,8 @@ spec:
312322
list
313323
rule: '!has(self.currentRevision) || self.revisions.exists(r, r.name
314324
== self.currentRevision)'
325+
- message: observedRevisionGeneration may not be unset once set
326+
rule: '!has(oldSelf.observedRevisionGeneration) || has(self.observedRevisionGeneration)'
315327
required:
316328
- metadata
317329
- spec

operator/v1alpha1/zz_generated.featuregated-crd-manifests/clusterapis.operator.openshift.io/ClusterAPIMachineManagement.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ spec:
107107
maxLength: 255
108108
minLength: 1
109109
type: string
110+
observedRevisionGeneration:
111+
description: |-
112+
observedRevisionGeneration is the generation of the ClusterAPI object that was last observed by the revision controller.
113+
If specified it must be greater than or equal to 1. It may not decrease or be unset once set.
114+
format: int64
115+
minimum: 1
116+
type: integer
117+
x-kubernetes-validations:
118+
- message: observedRevisionGeneration may not decrease
119+
rule: self >= oldSelf
110120
revisions:
111121
description: |-
112122
revisions is a list of all currently active revisions. A revision is
@@ -313,6 +323,8 @@ spec:
313323
list
314324
rule: '!has(self.currentRevision) || self.revisions.exists(r, r.name
315325
== self.currentRevision)'
326+
- message: observedRevisionGeneration may not be unset once set
327+
rule: '!has(oldSelf.observedRevisionGeneration) || has(self.observedRevisionGeneration)'
316328
required:
317329
- metadata
318330
- spec

operator/v1alpha1/zz_generated.swagger_doc_generated.go

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

payload-manifests/crds/0000_30_cluster-api_01_clusterapis.crd.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ spec:
106106
maxLength: 255
107107
minLength: 1
108108
type: string
109+
observedRevisionGeneration:
110+
description: |-
111+
observedRevisionGeneration is the generation of the ClusterAPI object that was last observed by the revision controller.
112+
If specified it must be greater than or equal to 1. It may not decrease or be unset once set.
113+
format: int64
114+
minimum: 1
115+
type: integer
116+
x-kubernetes-validations:
117+
- message: observedRevisionGeneration may not decrease
118+
rule: self >= oldSelf
109119
revisions:
110120
description: |-
111121
revisions is a list of all currently active revisions. A revision is
@@ -312,6 +322,8 @@ spec:
312322
list
313323
rule: '!has(self.currentRevision) || self.revisions.exists(r, r.name
314324
== self.currentRevision)'
325+
- message: observedRevisionGeneration may not be unset once set
326+
rule: '!has(oldSelf.observedRevisionGeneration) || has(self.observedRevisionGeneration)'
315327
required:
316328
- metadata
317329
- spec

0 commit comments

Comments
 (0)