|
| 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 | + // CommonResponse contains a Status and Message field common to all response types. |
| 41 | + CommonResponse |
| 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 | + |
| 48 | +// BeforeClusterCreate is the runtime hook that will be called right before a Cluster is created. |
| 49 | +func BeforeClusterCreate(*BeforeClusterCreateRequest, *BeforeClusterCreateResponse) {} |
| 50 | + |
| 51 | +// AfterControlPlaneInitializedRequest is the request of AfterControlPlaneInitialized hook. |
| 52 | +// +kubebuilder:object:root=true |
| 53 | +type AfterControlPlaneInitializedRequest struct { |
| 54 | + metav1.TypeMeta `json:",inline"` |
| 55 | + |
| 56 | + // The cluster object the lifecycle hook corresponds to. |
| 57 | + Cluster clusterv1.Cluster `json:"cluster"` |
| 58 | +} |
| 59 | + |
| 60 | +// AfterControlPlaneInitializedResponse is the response of AfterControlPlaneInitialized hook. |
| 61 | +// +kubebuilder:object:root=true |
| 62 | +type AfterControlPlaneInitializedResponse struct { |
| 63 | + metav1.TypeMeta `json:",inline"` |
| 64 | + |
| 65 | + // CommonResponse contains a Status and Message field common to all response types. |
| 66 | + CommonResponse |
| 67 | +} |
| 68 | + |
| 69 | +// AfterControlPlaneInitialized is the runtime hook that will be called after the control plane is available for the first time. |
| 70 | +func AfterControlPlaneInitialized(*AfterControlPlaneInitializedRequest, *AfterControlPlaneInitializedResponse) { |
| 71 | +} |
| 72 | + |
| 73 | +// BeforeClusterUpgradeRequest is the request of the hook. |
| 74 | +// +kubebuilder:object:root=true |
| 75 | +type BeforeClusterUpgradeRequest struct { |
| 76 | + metav1.TypeMeta `json:",inline"` |
| 77 | + |
| 78 | + // The cluster object the lifecycle hook corresponds to. |
| 79 | + Cluster clusterv1.Cluster `json:"cluster"` |
| 80 | + |
| 81 | + // The current Kubernetes version of the cluster. |
| 82 | + FromKubernetesVersion string `json:"fromKubernetesVersion"` |
| 83 | + // The target Kubernetes version of upgrade. |
| 84 | + ToKubernetesVersion string `json:"toKubernetesVersion"` |
| 85 | +} |
| 86 | + |
| 87 | +// BeforeClusterUpgradeResponse is the response of BeforeClusterUpgrade hook. |
| 88 | +// +kubebuilder:object:root=true |
| 89 | +type BeforeClusterUpgradeResponse struct { |
| 90 | + metav1.TypeMeta `json:",inline"` |
| 91 | + |
| 92 | + // CommonResponse contains a Status and Message field common to all response types. |
| 93 | + CommonResponse |
| 94 | + |
| 95 | + // RetryAfterSeconds when set to a non-zero signifies that the hook |
| 96 | + // needs to be retried at a future time. |
| 97 | + RetryAfterSeconds int `json:"retryAfterSeconds"` |
| 98 | +} |
| 99 | + |
| 100 | +// BeforeClusterUpgrade is the runtime hook that will be called after a cluster.spec.version is upgraded and |
| 101 | +// before the updated version is propagated to the underlying objects. |
| 102 | +func BeforeClusterUpgrade(*BeforeClusterUpgradeRequest, *BeforeClusterUpgradeResponse) {} |
| 103 | + |
| 104 | +// AfterControlPlaneUpgradeRequest is the request of the hook. |
| 105 | +// +kubebuilder:object:root=true |
| 106 | +type AfterControlPlaneUpgradeRequest struct { |
| 107 | + metav1.TypeMeta `json:",inline"` |
| 108 | + |
| 109 | + // The cluster object the lifecycle hook corresponds to. |
| 110 | + Cluster clusterv1.Cluster `json:"cluster"` |
| 111 | + |
| 112 | + // The Kubernetes version after upgrade. |
| 113 | + KubernetesVersion string `json:"kubernetesVersion"` |
| 114 | +} |
| 115 | + |
| 116 | +// AfterControlPlaneUpgradeResponse is the response of AfterControlPlaneUpgrade hook. |
| 117 | +// +kubebuilder:object:root=true |
| 118 | +type AfterControlPlaneUpgradeResponse struct { |
| 119 | + metav1.TypeMeta `json:",inline"` |
| 120 | + |
| 121 | + // CommonResponse contains a Status and Message field common to all response types. |
| 122 | + CommonResponse |
| 123 | + |
| 124 | + // RetryAfterSeconds when set to a non-zero signifies that the hook |
| 125 | + // needs to be retried at a future time. |
| 126 | + RetryAfterSeconds int `json:"retryAfterSeconds"` |
| 127 | +} |
| 128 | + |
| 129 | +// AfterControlPlaneUpgrade is the runtime hook after the control plane is successfully upgraded to the target |
| 130 | +// kubernetes version and before the target version is propagated to the workload machines. |
| 131 | +func AfterControlPlaneUpgrade(*AfterControlPlaneUpgradeRequest, *AfterControlPlaneUpgradeResponse) {} |
| 132 | + |
| 133 | +// AfterClusterUpgradeRequest is the request of the hook. |
| 134 | +// +kubebuilder:object:root=true |
| 135 | +type AfterClusterUpgradeRequest struct { |
| 136 | + metav1.TypeMeta `json:",inline"` |
| 137 | + |
| 138 | + // The cluster object the lifecycle hook corresponds to. |
| 139 | + Cluster clusterv1.Cluster `json:"cluster"` |
| 140 | + |
| 141 | + // The Kubernetes version after upgrade. |
| 142 | + KubernetesVersion string `json:"kubernetesVersion"` |
| 143 | +} |
| 144 | + |
| 145 | +// AfterClusterUpgradeResponse is the response of AfterClusterUpgrade hook. |
| 146 | +// +kubebuilder:object:root=true |
| 147 | +type AfterClusterUpgradeResponse struct { |
| 148 | + metav1.TypeMeta `json:",inline"` |
| 149 | + |
| 150 | + // CommonResponse contains a Status and Message field common to all response types. |
| 151 | + CommonResponse |
| 152 | +} |
| 153 | + |
| 154 | +// AfterClusterUpgrade is the runtime hook that is called after all of the cluster is updated |
| 155 | +// to the target kubernetes version. |
| 156 | +func AfterClusterUpgrade(*AfterClusterUpgradeRequest, *AfterClusterUpgradeResponse) {} |
| 157 | + |
| 158 | +// BeforeClusterDeleteRequest is the request of the hook. |
| 159 | +// +kubebuilder:object:root=true |
| 160 | +type BeforeClusterDeleteRequest struct { |
| 161 | + metav1.TypeMeta `json:",inline"` |
| 162 | + |
| 163 | + // The cluster object the lifecycle hook corresponds to. |
| 164 | + Cluster clusterv1.Cluster `json:"cluster"` |
| 165 | +} |
| 166 | + |
| 167 | +// BeforeClusterDeleteResponse is the response of BeforeClusterDelete hook. |
| 168 | +// +kubebuilder:object:root=true |
| 169 | +type BeforeClusterDeleteResponse struct { |
| 170 | + metav1.TypeMeta `json:",inline"` |
| 171 | + |
| 172 | + // CommonResponse contains a Status and Message field common to all response types. |
| 173 | + CommonResponse |
| 174 | + |
| 175 | + // RetryAfterSeconds when set to a non-zero signifies that the hook |
| 176 | + // needs to be retried at a future time. |
| 177 | + RetryAfterSeconds int `json:"retryAfterSeconds"` |
| 178 | +} |
| 179 | + |
| 180 | +// BeforeClusterDelete is the runtime hook that is called after a delete is issued on a cluster |
| 181 | +// and before the cluster and its underlying objects are deleted. |
| 182 | +func BeforeClusterDelete(*BeforeClusterDeleteRequest, *BeforeClusterDeleteResponse) {} |
| 183 | + |
| 184 | +func init() { |
| 185 | + catalogBuilder.RegisterHook(BeforeClusterCreate, &catalog.HookMeta{ |
| 186 | + Tags: []string{"Lifecycle Hooks"}, |
| 187 | + Summary: "Called before Cluster topology is created", |
| 188 | + 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", |
| 189 | + }) |
| 190 | + |
| 191 | + catalogBuilder.RegisterHook(AfterControlPlaneInitialized, &catalog.HookMeta{ |
| 192 | + Tags: []string{"Lifecycle Hooks"}, |
| 193 | + Summary: "Called after the Control Plane is available for the first time", |
| 194 | + Description: "This non-blocking hook is called after the ControlPlane for the Cluster is marked as available for the first time", |
| 195 | + }) |
| 196 | + |
| 197 | + catalogBuilder.RegisterHook(BeforeClusterUpgrade, &catalog.HookMeta{ |
| 198 | + Tags: []string{"Lifecycle Hooks"}, |
| 199 | + Summary: "Called before the Cluster begins upgrade", |
| 200 | + 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", |
| 201 | + }) |
| 202 | + |
| 203 | + catalogBuilder.RegisterHook(AfterControlPlaneUpgrade, &catalog.HookMeta{ |
| 204 | + Tags: []string{"Lifecycle Hooks"}, |
| 205 | + Summary: "Called after the Control Plane finished upgrade", |
| 206 | + 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", |
| 207 | + }) |
| 208 | + |
| 209 | + catalogBuilder.RegisterHook(AfterClusterUpgrade, &catalog.HookMeta{ |
| 210 | + Tags: []string{"Lifecycle Hooks"}, |
| 211 | + Summary: "Called after the Cluster finished upgrade", |
| 212 | + 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", |
| 213 | + }) |
| 214 | + |
| 215 | + catalogBuilder.RegisterHook(BeforeClusterDelete, &catalog.HookMeta{ |
| 216 | + Tags: []string{"Lifecycle Hooks"}, |
| 217 | + Summary: "Called before the Cluster is deleted", |
| 218 | + 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", |
| 219 | + }) |
| 220 | +} |
0 commit comments