-
Notifications
You must be signed in to change notification settings - Fork 1.4k
✨ Add types and hook for GenerateUpgradePlan #12823
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: main
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 | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,110 @@ | ||||||||||||||||||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||||||||||||||||||
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" | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" | ||||||||||||||||||||||||||||||||||||||||||
runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog" | ||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// GenerateUpgradePlanRequest is the request of the GenerateUpgradePlan hook. | ||||||||||||||||||||||||||||||||||||||||||
// +kubebuilder:object:root=true | ||||||||||||||||||||||||||||||||||||||||||
type GenerateUpgradePlanRequest struct { | ||||||||||||||||||||||||||||||||||||||||||
metav1.TypeMeta `json:",inline"` | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// CommonRequest contains fields common to all request types. | ||||||||||||||||||||||||||||||||||||||||||
CommonRequest `json:",inline"` | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// cluster is the cluster ofject the lifecycle hook correspods to. | ||||||||||||||||||||||||||||||||||||||||||
// +required | ||||||||||||||||||||||||||||||||||||||||||
Cluster clusterv1beta1.Cluster `json:"cluster,omitempty,omitzero"` | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// fromControlPlaneKubernetesVersion is the current Kubernetes version of the control plane. | ||||||||||||||||||||||||||||||||||||||||||
// +required | ||||||||||||||||||||||||||||||||||||||||||
// +kubebuilder:validation:MinLength=1 | ||||||||||||||||||||||||||||||||||||||||||
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. Not sure about all the @fabriziopandini WDYT? 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. For the request I think it is ok to have both +required and MinLength, because CAPI will always send a value for the fields that are currently marked as required (and the field that is marked optional will have lenght > 1 when set) For the response I think it makes sense to keep markers only what we are going enforcing when we are validating the response in
Accordingly, let's drop both listType and Min/MaxItems for both arrays. |
||||||||||||||||||||||||||||||||||||||||||
FromControlPlaneKubernetesVersion string `json:"fromControlPlaneKubernetesVersion,omitempty"` | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// fromWorkersKubernetesVersion is the current Kubernetes version of the workers. | ||||||||||||||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
// +optional | ||||||||||||||||||||||||||||||||||||||||||
// +kubebuilder:validation:MinLength=1 | ||||||||||||||||||||||||||||||||||||||||||
FromWorkersKubernetesVersion string `json:"fromWorkersKubernetesVersion,omitempty"` | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// toKubernetesVersion is the target Kubernetes version for the upgrade. | ||||||||||||||||||||||||||||||||||||||||||
// +required | ||||||||||||||||||||||||||||||||||||||||||
// +kubebuilder:validation:MinLength=1 | ||||||||||||||||||||||||||||||||||||||||||
ToKubernetesVersion string `json:"toKubernetesVersion,omitempty"` | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
var _ ResponseObject = &GenerateUpgradePlanResponse{} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// GenerateUpgradePlanResponse is the response of the GenerateUpgradePlan hook. | ||||||||||||||||||||||||||||||||||||||||||
// +kubebuilder:object:root=true | ||||||||||||||||||||||||||||||||||||||||||
type GenerateUpgradePlanResponse struct { | ||||||||||||||||||||||||||||||||||||||||||
metav1.TypeMeta `json:",inline"` | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// CommonResponse contains Status and Message fields common to all response types. | ||||||||||||||||||||||||||||||||||||||||||
CommonResponse `json:",inline"` | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// controlPlaneUpgrades is the list of version upgrade steps for the control plane. | ||||||||||||||||||||||||||||||||||||||||||
// Each entry represents an intermediate version that must be applied in sequence. | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+64
to
+65
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. Let's add some more details on the rules that applies to the upgrade plan
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
// +optional | ||||||||||||||||||||||||||||||||||||||||||
// +listType=atomic | ||||||||||||||||||||||||||||||||||||||||||
// +kubebuilder:validation:MinItems=1 | ||||||||||||||||||||||||||||||||||||||||||
// +kubebuilder:validation:MaxItems=1000 | ||||||||||||||||||||||||||||||||||||||||||
ControlPlaneUpgrades []UpgradeStep `json:"controlPlaneUpgrades,omitempty"` | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// workersUpgrades is the list of version upgrade steps for the workers. | ||||||||||||||||||||||||||||||||||||||||||
// Each entry represents an intermediate version that must be applied in sequence. | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+72
to
+73
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
// +optional | ||||||||||||||||||||||||||||||||||||||||||
// +listType=atomic | ||||||||||||||||||||||||||||||||||||||||||
// +kubebuilder:validation:MinItems=1 | ||||||||||||||||||||||||||||||||||||||||||
// +kubebuilder:validation:MaxItems=1000 | ||||||||||||||||||||||||||||||||||||||||||
WorkersUpgrades []UpgradeStep `json:"workersUpgrades,omitempty"` | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// UpgradeStep represents a single version upgrade step. | ||||||||||||||||||||||||||||||||||||||||||
type UpgradeStep struct { | ||||||||||||||||||||||||||||||||||||||||||
// version is the Kubernetes version for this upgrade step. | ||||||||||||||||||||||||||||||||||||||||||
// +required | ||||||||||||||||||||||||||||||||||||||||||
// +kubebuilder:validation:MinLength=1 | ||||||||||||||||||||||||||||||||||||||||||
Version string `json:"version,omitempty"` | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// GenerateUpgradePlan is the hook that will be called to generate an upgrade plan | ||||||||||||||||||||||||||||||||||||||||||
// for a cluster. This hook allows runtime extensions to specify intermediate | ||||||||||||||||||||||||||||||||||||||||||
// Kubernetes versions that must be applied during an upgrade from the current | ||||||||||||||||||||||||||||||||||||||||||
// version to the target version. | ||||||||||||||||||||||||||||||||||||||||||
func GenerateUpgradePlan(*GenerateUpgradePlanRequest, *GenerateUpgradePlanResponse) {} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
func init() { | ||||||||||||||||||||||||||||||||||||||||||
catalogBuilder.RegisterHook(GenerateUpgradePlan, &runtimecatalog.HookMeta{ | ||||||||||||||||||||||||||||||||||||||||||
Tags: []string{"Chained Upgrade Hook"}, | ||||||||||||||||||||||||||||||||||||||||||
Summary: "Cluster API Runtime will call this hook to generate an upgrade plan for a cluster", | ||||||||||||||||||||||||||||||||||||||||||
Description: "Cluster API Runtime will call this hook to generate an upgrade plan for a cluster. " + | ||||||||||||||||||||||||||||||||||||||||||
"Runtime Extension implementers can use this hook to specify intermediate Kubernetes versions " + | ||||||||||||||||||||||||||||||||||||||||||
"that must be applied during an upgrade from the current version to the target version.\n" + | ||||||||||||||||||||||||||||||||||||||||||
"\n" + | ||||||||||||||||||||||||||||||||||||||||||
"For example, if upgrading from v1.29.0 to v1.33.0 requires intermediate versions v1.30.0, " + | ||||||||||||||||||||||||||||||||||||||||||
"v1.31.0, and v1.32.0, the hook should return these intermediate versions in the response.\n" + | ||||||||||||||||||||||||||||||||||||||||||
"\n" + | ||||||||||||||||||||||||||||||||||||||||||
"Notes:\n" + | ||||||||||||||||||||||||||||||||||||||||||
"- The response may include separate upgrade paths for control plane and workers\n" + | ||||||||||||||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
"- Each upgrade step represents a version that must be applied in sequence", | ||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||
} |
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.
Let's go with v1beta2. I know the proposal says v1beta1, but we already decided for the in-place implementation to just directly go with v1beta2 to avoid conversion issues. I would do the same here
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.
+1 on using v1beta2 (sorry I forgot to update the comment with implementation details for this PR 😅)