-
Notifications
You must be signed in to change notification settings - Fork 584
OCPCLOUD-2998: Add synchronizedAPI to Machine and MachineSet status #2642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,6 +185,16 @@ const ( | |
| MachineAuthorityMigrating MachineAuthority = "Migrating" | ||
| ) | ||
|
|
||
| type SynchronizedAPI string | ||
|
|
||
| const ( | ||
| // MachineAPISynchronized indicates that the Machine API is the last synchronized API. | ||
| MachineAPISynchronized SynchronizedAPI = "MachineAPI" | ||
|
|
||
| // ClusterAPISynchronized indicates that the Cluster API is the last synchronized API. | ||
| ClusterAPISynchronized SynchronizedAPI = "ClusterAPI" | ||
| ) | ||
|
|
||
| // +genclient | ||
| // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
|
||
|
|
@@ -402,10 +412,22 @@ type MachineStatus struct { | |
| // When set to Migrating, the migration controller is currently performing the handover of authority from one API to the other. | ||
| // +kubebuilder:validation:Enum=MachineAPI;ClusterAPI;Migrating | ||
| // +kubebuilder:validation:XValidation:rule="self == 'Migrating' || self == oldSelf || oldSelf == 'Migrating'",message="The authoritativeAPI field must not transition directly from MachineAPI to ClusterAPI or vice versa. It must transition through Migrating." | ||
| // +kubebuilder:validation:XValidation:rule="oldSelf == ''|| self != ''",message="The authoritativeAPI field must not be set empty once it has a value." | ||
| // +openshift:enable:FeatureGate=MachineAPIMigration | ||
| // +optional | ||
| AuthoritativeAPI MachineAuthority `json:"authoritativeAPI,omitempty"` | ||
|
|
||
| // synchronizedAPI represents the API that is currently in sync with the state of the resource. | ||
| // Valid values are "MachineAPI" and "ClusterAPI". | ||
| // When omitted (empty value), the resource has not yet been reconciled by the migration controller. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Omitted doesn't actually mean an empty value, it means the key isn't present |
||
| // The migration controller sets `status.synchronizedAPI` to the value of the `status.authoritativeAPI` before it transitions to "Migrating". | ||
| // It is used to determine the source API of the migration. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Source of the last successful synchronization wasn't it? |
||
| // +kubebuilder:validation:XValidation:rule="oldSelf == ''|| self != ''",message="The synchronizedAPI field must not be set empty once it has a value." | ||
| // +kubebuilder:validation:Enum=MachineAPI;ClusterAPI | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably better to add this on the type itself |
||
| // +openshift:enable:FeatureGate=MachineAPIMigration | ||
| // +optional | ||
| SynchronizedAPI SynchronizedAPI `json:"synchronizedAPI,omitempty"` | ||
|
|
||
| // synchronizedGeneration is the generation of the authoritative resource that the non-authoritative resource is synchronised with. | ||
| // This field is set when the authoritative resource is updated and the sync controller has updated the non-authoritative resource to match. | ||
| // +kubebuilder:validation:Minimum=0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,6 +168,16 @@ type MachineSetStatus struct { | |
| // +optional | ||
| AuthoritativeAPI MachineAuthority `json:"authoritativeAPI,omitempty"` | ||
|
|
||
| // synchronizedAPI represents the API that is currently in sync with the state of the resource. | ||
| // Valid values are "MachineAPI" and "ClusterAPI". | ||
| // When omitted (empty value), the resource has not yet been reconciled by the migration controller. | ||
| // The migration controller sets `status.synchronizedAPI` to the value of the `status.authoritativeAPI` before it transitions to "Migrating". | ||
| // It is used to determine the source API of the migration. | ||
| // +kubebuilder:validation:Enum=MachineAPI;ClusterAPI | ||
| // +openshift:enable:FeatureGate=MachineAPIMigration | ||
| // +optional | ||
| SynchronizedAPI SynchronizedAPI `json:"synchronizedAPI,omitempty"` | ||
|
Comment on lines
+171
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's look at the full MachineSetStatus struct around the synchronizedAPI field
fd -e "types_machineset.go" --type f | head -1 | xargs wc -lRepository: openshift/api Length of output: 58 🏁 Script executed: # Get context around the synchronizedAPI field and check for validation rules
cat -n machine/v1beta1/types_machineset.go | sed -n '110,190p'Repository: openshift/api Length of output: 5548 🏁 Script executed: # Search for all XValidation rules in the MachineSetStatus area
rg -nP 'XValidation|Validation' machine/v1beta1/types_machineset.go -B 2 -A 2Repository: openshift/api Length of output: 1219 🏁 Script executed: # Check the Machine CRD (types_machine.go) for synchronizedAPI immutability patterns
fd -e "types_machine.go" --type f | head -1 | xargs wc -lRepository: openshift/api Length of output: 58 🏁 Script executed: # Search for synchronizedAPI in Machine CRD with validation context
rg -nP 'synchronizedAPI' machine/v1beta1/types_machine.go -B 5 -A 5Repository: openshift/api Length of output: 1597 Add immutability validation to prevent clearing synchronizedAPI (and authoritativeAPI) once set. The The same is true for the 🤖 Prompt for AI Agents🧩 Analysis chain🏁 Script executed: #!/bin/bash
# First, let's find the files containing MachineStatus and MachineSetStatus
echo "=== Finding type definition files ==="
fd -e go -x grep -l "type MachineStatus struct\|type MachineSetStatus struct" {} \;
# Let's look for the synchronizedAPI field in both types
echo -e "\n=== Searching for synchronizedAPI field ==="
rg -n "SynchronizedAPI" --type=go -B 5 -A 1
# Check specifically in the types files
echo -e "\n=== Checking MachineSet status file ==="
cat -n machine/v1beta1/types_machineset.go | sed -n '165,185p'
# Find and check the Machine status file
echo -e "\n=== Finding Machine status file ==="
fd -e go "types_machine.go" -x cat -n {} \; | head -100Repository: openshift/api Length of output: 9581 Add XValidation rule to match MachineStatus field validation. The This rule prevents the field from being unset once it has been assigned a value. Add this XValidation rule to MachineSetStatus to maintain consistency and enforce the same state transition constraints across both types. 🤖 Prompt for AI Agents |
||
|
|
||
| // synchronizedGeneration is the generation of the authoritative resource that the non-authoritative resource is synchronised with. | ||
| // This field is set when the authoritative resource is updated and the sync controller has updated the non-authoritative resource to match. | ||
| // +kubebuilder:validation:Minimum=0 | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the motivation on this one? Empty isn't actually a valid value so it would be rejected anyway?
Were you trying to make sure it cannot be removed once set? If so, you need a CEL rule on the parent struct, not on the field itself