@@ -97,6 +97,28 @@ type BeforeClusterUpgradeRequest struct {
9797 // toKubernetesVersion is the target Kubernetes version of the upgrade.
9898 // +required
9999 ToKubernetesVersion string `json:"toKubernetesVersion"`
100+
101+ // controlPlaneUpgrades is the list of version upgrade steps for the control plane.
102+ // +optional
103+ // +listType=atomic
104+ // +kubebuilder:validation:MinItems=1
105+ // +kubebuilder:validation:MaxItems=1000
106+ ControlPlaneUpgrades []UpgradeStep `json:"controlPlaneUpgrades,omitempty"`
107+
108+ // workersUpgrades is the list of version upgrade steps for the workers.
109+ // +optional
110+ // +listType=atomic
111+ // +kubebuilder:validation:MinItems=1
112+ // +kubebuilder:validation:MaxItems=1000
113+ WorkersUpgrades []UpgradeStep `json:"workersUpgrades,omitempty"`
114+ }
115+
116+ // UpgradeStep represents a single version upgrade step.
117+ type UpgradeStep struct {
118+ // version is the Kubernetes version for this upgrade step.
119+ // +required
120+ // +kubebuilder:validation:MinLength=1
121+ Version string `json:"version,omitempty"`
100122}
101123
102124var _ RetryResponseObject = & BeforeClusterUpgradeResponse {}
@@ -114,6 +136,56 @@ type BeforeClusterUpgradeResponse struct {
114136// before the updated version is propagated to the underlying objects.
115137func BeforeClusterUpgrade (* BeforeClusterUpgradeRequest , * BeforeClusterUpgradeResponse ) {}
116138
139+ // BeforeControlPlaneUpgradeRequest is the request of the BeforeControlPlane hook.
140+ // +kubebuilder:object:root=true
141+ type BeforeControlPlaneUpgradeRequest struct {
142+ metav1.TypeMeta `json:",inline"`
143+
144+ // CommonRequest contains fields common to all request types.
145+ CommonRequest `json:",inline"`
146+
147+ // cluster is the cluster object the lifecycle hook corresponds to.
148+ // +required
149+ Cluster clusterv1beta1.Cluster `json:"cluster"`
150+
151+ // fromKubernetesVersion is the current Kubernetes version of the control plane for the next upgrade step.
152+ // +required
153+ FromKubernetesVersion string `json:"fromKubernetesVersion"`
154+
155+ // toKubernetesVersion is the target Kubernetes version of the control plane for the next upgrade step.
156+ // +required
157+ ToKubernetesVersion string `json:"toKubernetesVersion"`
158+
159+ // controlPlaneUpgrades is the list of the remaining version upgrade steps for the control plane, if any.
160+ // +optional
161+ // +listType=atomic
162+ // +kubebuilder:validation:MinItems=1
163+ // +kubebuilder:validation:MaxItems=1000
164+ ControlPlaneUpgrades []UpgradeStep `json:"controlPlaneUpgrades,omitempty"`
165+
166+ // workersUpgrades is the list of the remaining version upgrade steps for workers, if any.
167+ // +optional
168+ // +listType=atomic
169+ // +kubebuilder:validation:MinItems=1
170+ // +kubebuilder:validation:MaxItems=1000
171+ WorkersUpgrades []UpgradeStep `json:"workersUpgrades,omitempty"`
172+ }
173+
174+ var _ RetryResponseObject = & BeforeControlPlaneUpgradeResponse {}
175+
176+ // BeforeControlPlaneUpgradeResponse is the response of the BeforeControlPlaneUpgrade hook.
177+ // +kubebuilder:object:root=true
178+ type BeforeControlPlaneUpgradeResponse struct {
179+ metav1.TypeMeta `json:",inline"`
180+
181+ // CommonRetryResponse contains Status, Message and RetryAfterSeconds fields.
182+ CommonRetryResponse `json:",inline"`
183+ }
184+
185+ // BeforeControlPlaneUpgrade is the hook that will be called before a new version is propagated to the control plane object.
186+ func BeforeControlPlaneUpgrade (* BeforeControlPlaneUpgradeRequest , * BeforeControlPlaneUpgradeResponse ) {
187+ }
188+
117189// AfterControlPlaneUpgradeRequest is the request of the AfterControlPlaneUpgrade hook.
118190// +kubebuilder:object:root=true
119191type AfterControlPlaneUpgradeRequest struct {
@@ -126,9 +198,23 @@ type AfterControlPlaneUpgradeRequest struct {
126198 // +required
127199 Cluster clusterv1beta1.Cluster `json:"cluster"`
128200
129- // kubernetesVersion is the Kubernetes version of the Control Plane after the upgrade.
201+ // kubernetesVersion is the Kubernetes version of the control plane after an upgrade step .
130202 // +required
131203 KubernetesVersion string `json:"kubernetesVersion"`
204+
205+ // controlPlaneUpgrades is the list of the remaining version upgrade steps for the control plane, if any.
206+ // +optional
207+ // +listType=atomic
208+ // +kubebuilder:validation:MinItems=1
209+ // +kubebuilder:validation:MaxItems=1000
210+ ControlPlaneUpgrades []UpgradeStep `json:"controlPlaneUpgrades,omitempty"`
211+
212+ // workersUpgrades is the list of the remaining version upgrade steps for workers, if any.
213+ // +optional
214+ // +listType=atomic
215+ // +kubebuilder:validation:MinItems=1
216+ // +kubebuilder:validation:MaxItems=1000
217+ WorkersUpgrades []UpgradeStep `json:"workersUpgrades,omitempty"`
132218}
133219
134220var _ RetryResponseObject = & AfterControlPlaneUpgradeResponse {}
@@ -146,6 +232,102 @@ type AfterControlPlaneUpgradeResponse struct {
146232// Kubernetes version and before the target version is propagated to the workload machines.
147233func AfterControlPlaneUpgrade (* AfterControlPlaneUpgradeRequest , * AfterControlPlaneUpgradeResponse ) {}
148234
235+ // BeforeWorkersUpgradeRequest is the request of the BeforeWorkersUpgrade hook.
236+ // +kubebuilder:object:root=true
237+ type BeforeWorkersUpgradeRequest struct {
238+ metav1.TypeMeta `json:",inline"`
239+
240+ // CommonRequest contains fields common to all request types.
241+ CommonRequest `json:",inline"`
242+
243+ // cluster is the cluster object the lifecycle hook corresponds to.
244+ // +required
245+ Cluster clusterv1beta1.Cluster `json:"cluster"`
246+
247+ // fromKubernetesVersion is the current Kubernetes version of the workers for the next upgrade step.
248+ // +required
249+ FromKubernetesVersion string `json:"fromKubernetesVersion"`
250+
251+ // toKubernetesVersion is the target Kubernetes version of the workers for the next upgrade step.
252+ // +required
253+ ToKubernetesVersion string `json:"toKubernetesVersion"`
254+
255+ // controlPlaneUpgrades is the list of the remaining version upgrade steps for the control plane, if any.
256+ // +optional
257+ // +listType=atomic
258+ // +kubebuilder:validation:MinItems=1
259+ // +kubebuilder:validation:MaxItems=1000
260+ ControlPlaneUpgrades []UpgradeStep `json:"controlPlaneUpgrades,omitempty"`
261+
262+ // workersUpgrades is the list of the remaining version upgrade steps for workers, if any.
263+ // +optional
264+ // +listType=atomic
265+ // +kubebuilder:validation:MinItems=1
266+ // +kubebuilder:validation:MaxItems=1000
267+ WorkersUpgrades []UpgradeStep `json:"workersUpgrades,omitempty"`
268+ }
269+
270+ var _ RetryResponseObject = & BeforeWorkersUpgradeResponse {}
271+
272+ // BeforeWorkersUpgradeResponse is the response of the BeforeWorkersUpgrade hook.
273+ // +kubebuilder:object:root=true
274+ type BeforeWorkersUpgradeResponse struct {
275+ metav1.TypeMeta `json:",inline"`
276+
277+ // CommonRetryResponse contains Status, Message and RetryAfterSeconds fields.
278+ CommonRetryResponse `json:",inline"`
279+ }
280+
281+ // BeforeWorkersUpgrade is the hook that will be called before a new version is propagated to workers.
282+ func BeforeWorkersUpgrade (* BeforeWorkersUpgradeRequest , * BeforeWorkersUpgradeResponse ) {
283+ }
284+
285+ // AfterWorkersUpgradeRequest is the request of the AfterWorkersUpgrade hook.
286+ // +kubebuilder:object:root=true
287+ type AfterWorkersUpgradeRequest struct {
288+ metav1.TypeMeta `json:",inline"`
289+
290+ // CommonRequest contains fields common to all request types.
291+ CommonRequest `json:",inline"`
292+
293+ // cluster is the cluster object the lifecycle hook corresponds to.
294+ // +required
295+ Cluster clusterv1beta1.Cluster `json:"cluster"`
296+
297+ // kubernetesVersion is the Kubernetes version of the workers after an upgrade step.
298+ // +required
299+ KubernetesVersion string `json:"kubernetesVersion"`
300+
301+ // controlPlaneUpgrades is the list of the remaining version upgrade steps for the control plane, if any.
302+ // +optional
303+ // +listType=atomic
304+ // +kubebuilder:validation:MinItems=1
305+ // +kubebuilder:validation:MaxItems=1000
306+ ControlPlaneUpgrades []UpgradeStep `json:"controlPlaneUpgrades,omitempty"`
307+
308+ // workersUpgrades is the list of the remaining version upgrade steps for workers, if any.
309+ // +optional
310+ // +listType=atomic
311+ // +kubebuilder:validation:MinItems=1
312+ // +kubebuilder:validation:MaxItems=1000
313+ WorkersUpgrades []UpgradeStep `json:"workersUpgrades,omitempty"`
314+ }
315+
316+ var _ RetryResponseObject = & AfterWorkersUpgradeResponse {}
317+
318+ // AfterWorkersUpgradeResponse is the response of the AfterWorkersUpgrade hook.
319+ // +kubebuilder:object:root=true
320+ type AfterWorkersUpgradeResponse struct {
321+ metav1.TypeMeta `json:",inline"`
322+
323+ // CommonRetryResponse contains Status, Message and RetryAfterSeconds fields.
324+ CommonRetryResponse `json:",inline"`
325+ }
326+
327+ // AfterWorkersUpgrade is the hook called after the control plane is successfully upgraded to the target
328+ // Kubernetes version and before the target version is propagated to the workload machines.
329+ func AfterWorkersUpgrade (* AfterWorkersUpgradeRequest , * AfterWorkersUpgradeResponse ) {}
330+
149331// AfterClusterUpgradeRequest is the request of the AfterClusterUpgrade hook.
150332// +kubebuilder:object:root=true
151333type AfterClusterUpgradeRequest struct {
@@ -243,18 +425,56 @@ func init() {
243425 "tasks before the new version is propagated to the control plane" ,
244426 })
245427
428+ catalogBuilder .RegisterHook (BeforeControlPlaneUpgrade , & runtimecatalog.HookMeta {
429+ Tags : []string {"Lifecycle Hooks" },
430+ Summary : "Cluster API Runtime will call this hook before the control plane is upgraded" ,
431+ Description : "This hook is called before a new version is propagated to the control plane object.\n " +
432+ "\n " +
433+ "Notes:\n " +
434+ "- When an upgrade is starting, BeforeControlPlaneUpgrade will be called after BeforeClusterUpgrade is completed\n " +
435+ "- When an upgrade is in progress BeforeControlPlaneUpgrade will be called for each intermediate version that will be applied " +
436+ "to the control plane (instead BeforeClusterUpgrade will be called only once at the beginning of the upgrade)" +
437+ "- This is a blocking hook; Runtime Extension implementers can use this hook to execute " +
438+ "tasks before the new version is propagated to the control plane" ,
439+ })
440+
246441 catalogBuilder .RegisterHook (AfterControlPlaneUpgrade , & runtimecatalog.HookMeta {
247442 Tags : []string {"Lifecycle Hooks" },
248443 Summary : "Cluster API Runtime will call this hook after the control plane is upgraded" ,
249444 Description : "Cluster API Runtime will call this hook after the a cluster's control plane has been upgraded to the version specified " +
250- "in spec.topology.version, and immediately before the new version is going to be propagated to the MachineDeployments. " +
445+ "in spec.topology.version or to an intermediate version in the upgrade plan. " +
251446 "A control plane upgrade is completed when all the machines in the control plane have been upgraded.\n " +
252447 "\n " +
253448 "Notes:\n " +
254449 "- This hook will be called only for Clusters with a managed topology\n " +
255450 "- The call's request contains the Cluster object and the Kubernetes version we upgraded to\n " +
256451 "- This is a blocking hook; Runtime Extension implementers can use this hook to execute " +
257- "tasks before the new version is propagated to the MachineDeployments" ,
452+ "tasks before the new version is propagated to the MachineDeployments and Machine Pools" ,
453+ })
454+
455+ catalogBuilder .RegisterHook (BeforeWorkersUpgrade , & runtimecatalog.HookMeta {
456+ Tags : []string {"Lifecycle Hooks" },
457+ Summary : "Cluster API Runtime will call this hook before the workers are upgraded" ,
458+ Description : "This hook is called before a new version is propagated to workers.\n " +
459+ "\n " +
460+ "Notes:\n " +
461+ "- This hook will be called only if workers upgrade must be performed for an intermediate version of " +
462+ "a chained upgrade or when upgrading to the target spec.topology.version.\n " +
463+ "- This is a blocking hook; Runtime Extension implementers can use this hook to execute " +
464+ "tasks before the new version is propagated to the MachineDeployments and Machine Pools" ,
465+ })
466+
467+ catalogBuilder .RegisterHook (AfterWorkersUpgrade , & runtimecatalog.HookMeta {
468+ Tags : []string {"Lifecycle Hooks" },
469+ Summary : "Cluster API Runtime will call this hook after workers are upgraded" ,
470+ Description : "This hook is called after all the workers have been upgraded to the version specified in spec.topology.version " +
471+ "or to an intermediate version in the upgrade plan.\n " +
472+ "\n " +
473+ "Notes:\n " +
474+ "- This hook will be called only for Clusters with a managed topology\n " +
475+ "- The call's request contains the Cluster object, the current Kubernetes version and the Kubernetes version we are upgrading to\n " +
476+ "- This is a blocking hook; Runtime Extension implementers can use this hook to execute " +
477+ "tasks before the upgrade plan continues, or when already at the target spec.topology.version, before AfterClusterUpgrade is called.\n " ,
258478 })
259479
260480 catalogBuilder .RegisterHook (AfterClusterUpgrade , & runtimecatalog.HookMeta {
0 commit comments