|
| 1 | +/* |
| 2 | +Copyright 2025 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + |
| 22 | + clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" |
| 23 | + runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog" |
| 24 | +) |
| 25 | + |
| 26 | +// GenerateUpgradePlanRequest is the request of the GenerateUpgradePlan hook. |
| 27 | +// +kubebuilder:object:root=true |
| 28 | +type GenerateUpgradePlanRequest struct { |
| 29 | + metav1.TypeMeta `json:",inline"` |
| 30 | + |
| 31 | + // CommonRequest contains fields common to all request types. |
| 32 | + CommonRequest `json:",inline"` |
| 33 | + |
| 34 | + // cluster is the cluster ofject the lifecycle hook correspods to. |
| 35 | + // +required |
| 36 | + Cluster clusterv1beta1.Cluster `json:"cluster"` |
| 37 | + |
| 38 | + // fromControlPlaneKubernetesVersion is the current Kubernetes version of the control plane. |
| 39 | + // +required |
| 40 | + FromControlPlaneKubernetesVersion string `json:"fromControlPlaneKubernetesVersion"` |
| 41 | + |
| 42 | + // fromWorkersKubernetesVersion is the current Kubernetes version of the workers. |
| 43 | + // +optional |
| 44 | + FromWorkersKubernetesVersion string `json:"fromWorkersKubernetesVersion,omitempty"` |
| 45 | + |
| 46 | + // toKubernetesVersion is the target Kubernetes version for the upgrade. |
| 47 | + // +required |
| 48 | + ToKubernetesVersion string `json:"toKubernetesVersion"` |
| 49 | +} |
| 50 | + |
| 51 | +var _ ResponseObject = &GenerateUpgradePlanResponse{} |
| 52 | + |
| 53 | +// GenerateUpgradePlanResponse is the response of the GenerateUpgradePlan hook. |
| 54 | +// +kubebuilder:object:root=true |
| 55 | +type GenerateUpgradePlanResponse struct { |
| 56 | + metav1.TypeMeta `json:",inline"` |
| 57 | + |
| 58 | + // CommonResponse contains Status and Message fields common to all response types. |
| 59 | + CommonResponse `json:",inline"` |
| 60 | + |
| 61 | + // controlPlaneUpgrades is the list of version upgrade steps for the control plane. |
| 62 | + // Each entry represents an intermediate version that must be applied in sequence. |
| 63 | + // +optional |
| 64 | + // +listType=atomic |
| 65 | + // +kubebuilder:validation:MinItems=1 |
| 66 | + // +kubebuilder:validation:MaxItems=1000 |
| 67 | + ControlPlaneUpgrades []UpgradeStep `json:"controlPlaneUpgrades,omitempty"` |
| 68 | + |
| 69 | + // workersUpgrades is the list of version upgrade steps for the workers. |
| 70 | + // Each entry represents an intermediate version that must be applied in sequence. |
| 71 | + // +optional |
| 72 | + // +listType=atomic |
| 73 | + // +kubebuilder:validation:MinItems=1 |
| 74 | + // +kubebuilder:validation:MaxItems=1000 |
| 75 | + WorkersUpgrades []UpgradeStep `json:"workersUpgrades,omitempty"` |
| 76 | +} |
| 77 | + |
| 78 | +// UpgradeStep represents a single version upgrade step. |
| 79 | +type UpgradeStep struct { |
| 80 | + // version is the Kubernetes version for this upgrade step. |
| 81 | + // +required |
| 82 | + Version string `json:"version"` |
| 83 | +} |
| 84 | + |
| 85 | +// GenerateUpgradePlan is the hook that will be called to generate an upgrade plan |
| 86 | +// for a cluster. This hook allows runtime extensions to specify intermediate |
| 87 | +// Kubernetes versions that must be applied during an upgrade from the current |
| 88 | +// version to the target version. |
| 89 | +func GenerateUpgradePlan(*GenerateUpgradePlanRequest, *GenerateUpgradePlanResponse) {} |
| 90 | + |
| 91 | +func init() { |
| 92 | + catalogBuilder.RegisterHook(GenerateUpgradePlan, &runtimecatalog.HookMeta{ |
| 93 | + Tags: []string{"Chained Upgrade Hook"}, |
| 94 | + Summary: "Cluster API Runtime will call this hook to generate an upgrade plan for a cluster", |
| 95 | + Description: "Cluster API Runtime will call this hook to generate an upgrade plan for a cluster. " + |
| 96 | + "Runtime Extension implementers can use this hook to specify intermediate Kubernetes versions " + |
| 97 | + "that must be applied during an upgrade from the current version to the target version.\n" + |
| 98 | + "\n" + |
| 99 | + "For example, if upgrading from v1.29.0 to v1.33.0 requires intermediate versions v1.30.0, " + |
| 100 | + "v1.31.0, and v1.32.0, the hook should return these intermediate versions in the response.\n" + |
| 101 | + "\n" + |
| 102 | + "Notes:\n" + |
| 103 | + "- The response may include separate upgrade paths for control plane and workers\n" + |
| 104 | + "- Each upgrade step represents a version that must be applied in sequence", |
| 105 | + }) |
| 106 | +} |
0 commit comments