-
Notifications
You must be signed in to change notification settings - Fork 1.4k
✨ Add in-place update hooks to API #12343
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
Open
alexander-demicev
wants to merge
1
commit into
kubernetes-sigs:main
Choose a base branch
from
alexander-demicev:inplacehooks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+517
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
Copyright 2025 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog" | ||
) | ||
|
||
// CanUpdateMachineRequest is the request of the CanUpdateMachine hook. | ||
// This hook is called to determine if an extension can handle specific changes. | ||
// +kubebuilder:object:root=true | ||
type CanUpdateMachineRequest struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// CommonRequest contains fields common to all request types. | ||
CommonRequest `json:",inline"` | ||
|
||
// changes is a list of field paths that need to be updated on the machine. | ||
// Examples: ["spec.version", "spec.infrastructureRef.spec.memoryMiB"] | ||
// +required | ||
Changes []string `json:"changes"` | ||
} | ||
|
||
var _ ResponseObject = &CanUpdateMachineResponse{} | ||
|
||
// CanUpdateMachineResponse is the response of the CanUpdateMachine hook. | ||
// +kubebuilder:object:root=true | ||
type CanUpdateMachineResponse struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// CommonResponse contains Status and Message fields common to all response types. | ||
CommonResponse `json:",inline"` | ||
|
||
// acceptedChanges is the subset of requested changes that this extension can handle. | ||
// If empty, the extension cannot handle any of the requested changes. | ||
// +optional | ||
AcceptedChanges []string `json:"acceptedChanges,omitempty"` | ||
} | ||
|
||
// CanUpdateMachine is the hook that will be called to determine if an extension | ||
// can handle specific machine changes for in-place updates. | ||
func CanUpdateMachine(*CanUpdateMachineRequest, *CanUpdateMachineResponse) {} | ||
|
||
// UpdateMachineRequest is the request of the UpdateMachine hook. | ||
// This hook is called to perform the actual in-place update on a machine. | ||
// +kubebuilder:object:root=true | ||
type UpdateMachineRequest struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// CommonRequest contains fields common to all request types. | ||
CommonRequest `json:",inline"` | ||
|
||
// machineRef is a reference to the machine object the in-place update hook corresponds to. | ||
// Updaters should fetch the latest machine state using this reference. | ||
// +required | ||
MachineRef ObjectReference `json:"machineRef"` | ||
} | ||
|
||
var _ RetryResponseObject = &UpdateMachineResponse{} | ||
|
||
// UpdateMachineResponse is the response of the UpdateMachine hook. | ||
// The status of the update operation is determined by the CommonRetryResponse fields: | ||
// - Status=Success + RetryAfterSeconds > 0: update is in progress | ||
// - Status=Success + RetryAfterSeconds = 0: update completed successfully | ||
// - Status=Failure: update failed | ||
// +kubebuilder:object:root=true | ||
type UpdateMachineResponse struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// CommonRetryResponse contains Status, Message and RetryAfterSeconds fields. | ||
CommonRetryResponse `json:",inline"` | ||
} | ||
|
||
// ObjectReference represents a reference to a Kubernetes object. | ||
type ObjectReference struct { | ||
// name is the name of the referenced object. | ||
// +required | ||
Name string `json:"name"` | ||
|
||
// namespace is the namespace of the referenced object. | ||
// +required | ||
Namespace string `json:"namespace"` | ||
} | ||
|
||
// UpdateMachine is the hook that will be called to perform in-place updates on a machine. | ||
// This hook should be idempotent and can be called multiple times for the same machine | ||
// until it reports Done or Failed status. | ||
func UpdateMachine(*UpdateMachineRequest, *UpdateMachineResponse) {} | ||
|
||
func init() { | ||
catalogBuilder.RegisterHook(CanUpdateMachine, &runtimecatalog.HookMeta{ | ||
Tags: []string{"In-Place Update Hooks"}, | ||
Summary: "Cluster API Runtime will call this hook to determine if an extension can handle specific machine changes", | ||
Description: "Called during update planning to determine if an extension can handle machine changes. " + | ||
"The extension should respond with the subset of changes it can handle for in-place updates.\n" + | ||
"\n" + | ||
"Notes:\n" + | ||
"- This hook is called during the planning phase of updates\n" + | ||
"- The request contains a list of required changes (field paths)\n" + | ||
"- Extensions should return only the changes they can confidently handle\n" + | ||
"- If no extension can cover all changes, CAPI will fallback to rolling updates\n", | ||
}) | ||
|
||
catalogBuilder.RegisterHook(UpdateMachine, &runtimecatalog.HookMeta{ | ||
Tags: []string{"In-Place Update Hooks"}, | ||
Summary: "Cluster API Runtime will call this hook to perform in-place updates on a machine", | ||
Description: "Cluster API Runtime will call this hook to perform the actual in-place update on a machine. " + | ||
"The hook will be called repeatedly until it reports Done or Failed status.\n" + | ||
"\n" + | ||
"Notes:\n" + | ||
"- This hook must be idempotent - it can be called multiple times for the same machine\n" + | ||
"- Extensions should fetch the latest machine state using the provided reference\n" + | ||
"- The hook should return InProgress status while the update is ongoing\n" + | ||
"- Use RetryAfterSeconds to control polling frequency\n" + | ||
"- The hook should perform updates based on the current machine spec\n", | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We probably need to start working to a book page with this documentation, but considering there are still details to be figured out, I'm also ok to defer