Skip to content

Commit 115473c

Browse files
killianmuldoonykakarap
and
ykakarap
committed
Add lifecycle hook types
Co-authored-by: ykakarap <[email protected]> Signed-off-by: killianmuldoon <[email protected]>
1 parent 875d9e3 commit 115473c

File tree

3 files changed

+1098
-4
lines changed

3 files changed

+1098
-4
lines changed
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/*
2+
Copyright 2022 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+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23+
"sigs.k8s.io/cluster-api/internal/runtime/catalog"
24+
)
25+
26+
// BeforeClusterCreateRequest is the request of the BeforeClusterCreate hook.
27+
// +kubebuilder:object:root=true
28+
type BeforeClusterCreateRequest struct {
29+
metav1.TypeMeta `json:",inline"`
30+
31+
// The cluster object the lifecycle hook corresponds to.
32+
Cluster clusterv1.Cluster `json:"cluster"`
33+
}
34+
35+
// BeforeClusterCreateResponse is the response of BeforeClusterCreate hook.
36+
// +kubebuilder:object:root=true
37+
type BeforeClusterCreateResponse struct {
38+
metav1.TypeMeta `json:",inline"`
39+
40+
// Status of the call. One of "Success" or "Failure".
41+
Status ResponseStatus `json:"status"`
42+
43+
// RetryAfterSeconds when set to a non-zero signifies that the hook
44+
// will be called again at a future time.
45+
RetryAfterSeconds int `json:"retryAfterSeconds"`
46+
47+
// A human-readable description of the status of the call.
48+
Message string `json:"message"`
49+
}
50+
51+
// BeforeClusterCreate is the runtime hook that will be called right before a Cluster is created.
52+
func BeforeClusterCreate(*BeforeClusterCreateRequest, *BeforeClusterCreateResponse) {}
53+
54+
// AfterControlPlaneInitializedRequest is the request of AfterControlPlaneInitialized hook.
55+
// +kubebuilder:object:root=true
56+
type AfterControlPlaneInitializedRequest struct {
57+
metav1.TypeMeta `json:",inline"`
58+
59+
// The cluster object the lifecycle hook corresponds to.
60+
Cluster clusterv1.Cluster `json:"cluster"`
61+
}
62+
63+
// AfterControlPlaneInitializedResponse is the response of AfterControlPlaneInitialized hook.
64+
// +kubebuilder:object:root=true
65+
type AfterControlPlaneInitializedResponse struct {
66+
metav1.TypeMeta `json:",inline"`
67+
68+
// Status of the call. One of "Success" or "Failure".
69+
Status ResponseStatus `json:"status"`
70+
71+
// A human-readable description of the status of the call.
72+
Message string `json:"message"`
73+
}
74+
75+
// AfterControlPlaneInitialized is the runtime hook that will be called after the control plane is available for the first time.
76+
func AfterControlPlaneInitialized(*AfterControlPlaneInitializedRequest, *AfterControlPlaneInitializedResponse) {
77+
}
78+
79+
// BeforeClusterUpgradeRequest is the request of the hook.
80+
// +kubebuilder:object:root=true
81+
type BeforeClusterUpgradeRequest struct {
82+
metav1.TypeMeta `json:",inline"`
83+
84+
// The cluster object the lifecycle hook corresponds to.
85+
Cluster clusterv1.Cluster `json:"cluster"`
86+
87+
// The current Kubernetes version of the cluster.
88+
FromKubernetesVersion string `json:"fromKubernetesVersion"`
89+
// The target Kubernetes version of upgrade.
90+
ToKubernetesVersion string `json:"toKubernetesVersion"`
91+
}
92+
93+
// BeforeClusterUpgradeResponse is the response of BeforeClusterUpgrade hook.
94+
// +kubebuilder:object:root=true
95+
type BeforeClusterUpgradeResponse struct {
96+
metav1.TypeMeta `json:",inline"`
97+
98+
// Status of the call. One of "Success" or "Failure".
99+
Status ResponseStatus `json:"status"`
100+
101+
// RetryAfterSeconds when set to a non-zero signifies that the hook
102+
// needs to be retried at a future time.
103+
RetryAfterSeconds int `json:"retryAfterSeconds"`
104+
105+
// A human-readable description of the status of the call.
106+
Message string `json:"message"`
107+
}
108+
109+
// BeforeClusterUpgrade is the runtime hook that will be called after a cluster.spec.version is upgraded and
110+
// before the updated version is propagated to the underlying objects.
111+
func BeforeClusterUpgrade(*BeforeClusterUpgradeRequest, *BeforeClusterUpgradeResponse) {}
112+
113+
// AfterControlPlaneUpgradeRequest is the request of the hook.
114+
// +kubebuilder:object:root=true
115+
type AfterControlPlaneUpgradeRequest struct {
116+
metav1.TypeMeta `json:",inline"`
117+
118+
// The cluster object the lifecycle hook corresponds to.
119+
Cluster clusterv1.Cluster `json:"cluster"`
120+
121+
// The Kubernetes version after upgrade.
122+
KubernetesVersion string `json:"kubernetesVersion"`
123+
}
124+
125+
// AfterControlPlaneUpgradeResponse is the response of AfterControlPlaneUpgrade hook.
126+
// +kubebuilder:object:root=true
127+
type AfterControlPlaneUpgradeResponse struct {
128+
metav1.TypeMeta `json:",inline"`
129+
130+
// Status of the call. One of "Success" or "Failure".
131+
Status ResponseStatus `json:"status"`
132+
133+
// RetryAfterSeconds when set to a non-zero signifies that the hook
134+
// needs to be retried at a future time.
135+
RetryAfterSeconds int `json:"retryAfterSeconds"`
136+
137+
// A human-readable description of the status of the call.
138+
Message string `json:"message"`
139+
}
140+
141+
// AfterControlPlaneUpgrade is the runtime hook after the control plane is successfully upgraded to the target
142+
// kubernetes version and before the target version is propagated to the workload machines.
143+
func AfterControlPlaneUpgrade(*AfterControlPlaneUpgradeRequest, *AfterControlPlaneUpgradeResponse) {}
144+
145+
// AfterClusterUpgradeRequest is the request of the hook.
146+
// +kubebuilder:object:root=true
147+
type AfterClusterUpgradeRequest struct {
148+
metav1.TypeMeta `json:",inline"`
149+
150+
// The cluster object the lifecycle hook corresponds to.
151+
Cluster clusterv1.Cluster `json:"cluster"`
152+
153+
// The Kubernetes version after upgrade.
154+
KubernetesVersion string `json:"kubernetesVersion"`
155+
}
156+
157+
// AfterClusterUpgradeResponse is the response of AfterClusterUpgrade hook.
158+
// +kubebuilder:object:root=true
159+
type AfterClusterUpgradeResponse struct {
160+
metav1.TypeMeta `json:",inline"`
161+
162+
// Status of the call. One of "Success" or "Failure".
163+
Status ResponseStatus `json:"status"`
164+
165+
// A human-readable description of the status of the call.
166+
Message string `json:"message"`
167+
}
168+
169+
// AfterClusterUpgrade is the runtime hook that is called after all of the cluster is updated
170+
// to the target kubernetes version.
171+
func AfterClusterUpgrade(*AfterClusterUpgradeRequest, *AfterClusterUpgradeResponse) {}
172+
173+
// BeforeClusterDeleteRequest is the request of the hook.
174+
// +kubebuilder:object:root=true
175+
type BeforeClusterDeleteRequest struct {
176+
metav1.TypeMeta `json:",inline"`
177+
178+
// The cluster object the lifecycle hook corresponds to.
179+
Cluster clusterv1.Cluster `json:"cluster"`
180+
}
181+
182+
// BeforeClusterDeleteResponse is the response of BeforeClusterDelete hook.
183+
// +kubebuilder:object:root=true
184+
type BeforeClusterDeleteResponse struct {
185+
metav1.TypeMeta `json:",inline"`
186+
187+
// Status of the call. One of "Success" or "Failure".
188+
Status ResponseStatus `json:"status"`
189+
190+
// RetryAfterSeconds when set to a non-zero signifies that the hook
191+
// needs to be retried at a future time.
192+
RetryAfterSeconds int `json:"retryAfterSeconds"`
193+
194+
// A human-readable description of the status of the call.
195+
Message string `json:"message"`
196+
}
197+
198+
// BeforeClusterDelete is the runtime hook that is called after a delete is issued on a cluster
199+
// and before the cluster and its underlying objects are deleted.
200+
func BeforeClusterDelete(*BeforeClusterDeleteRequest, *BeforeClusterDeleteResponse) {}
201+
202+
func init() {
203+
catalogBuilder.RegisterHook(BeforeClusterCreate, &catalog.HookMeta{
204+
Tags: []string{"Lifecycle Hooks"},
205+
Summary: "Called before Cluster topology is created",
206+
Description: "This blocking hook is called after the Cluster is created by the user and immediately before all the objects which are part of a Cluster topology are going to be created",
207+
})
208+
209+
catalogBuilder.RegisterHook(AfterControlPlaneInitialized, &catalog.HookMeta{
210+
Tags: []string{"Lifecycle Hooks"},
211+
Summary: "Called after the Control Plane is available for the first time",
212+
Description: "This non-blocking hook is called after the ControlPlane for the Cluster is marked as available for the first time",
213+
})
214+
215+
catalogBuilder.RegisterHook(BeforeClusterUpgrade, &catalog.HookMeta{
216+
Tags: []string{"Lifecycle Hooks"},
217+
Summary: "Called before the Cluster begins upgrade",
218+
Description: "This hook is called after the Cluster object has been updated with a new spec.topology.version by the user, and immediately before the new version is propagated to the Control Plane",
219+
})
220+
221+
catalogBuilder.RegisterHook(AfterControlPlaneUpgrade, &catalog.HookMeta{
222+
Tags: []string{"Lifecycle Hooks"},
223+
Summary: "Called after the Control Plane finished upgrade",
224+
Description: "This blocking hook is called after the Control Plane has been upgraded to the version specified in spec.topology.version, and immediately before the new version is propagated to the MachineDeployments of the Cluster",
225+
})
226+
227+
catalogBuilder.RegisterHook(AfterClusterUpgrade, &catalog.HookMeta{
228+
Tags: []string{"Lifecycle Hooks"},
229+
Summary: "Called after the Cluster finished upgrade",
230+
Description: "This non-blocking hook is called after the Cluster, Control Plane and Workers have been upgraded to the version specified in spec.topology.version",
231+
})
232+
233+
catalogBuilder.RegisterHook(BeforeClusterDelete, &catalog.HookMeta{
234+
Tags: []string{"Lifecycle Hooks"},
235+
Summary: "Called before the Cluster is deleted",
236+
Description: "This blocking hook is called after the Cluster has been deleted by the user, and immediately before objects of the Cluster are going to be deleted",
237+
})
238+
}

0 commit comments

Comments
 (0)