-
Notifications
You must be signed in to change notification settings - Fork 1.4k
🌱 Add lifecycle hook types #6537
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
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:main
from
killianmuldoon:runtimeSDK/lifecycle-hooks-types
Jun 1, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
/* | ||
Copyright 2022 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" | ||
|
||
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" | ||
runtimecatalog "sigs.k8s.io/cluster-api/internal/runtime/catalog" | ||
) | ||
|
||
// BeforeClusterCreateRequest is the request of the BeforeClusterCreate hook. | ||
// +kubebuilder:object:root=true | ||
type BeforeClusterCreateRequest struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// The cluster object the lifecycle hook corresponds to. | ||
Cluster clusterv1.Cluster `json:"cluster"` | ||
} | ||
|
||
// BeforeClusterCreateResponse is the response of the BeforeClusterCreate hook. | ||
// +kubebuilder:object:root=true | ||
type BeforeClusterCreateResponse struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// CommonResponse contains Status and Message fields common to all response types. | ||
CommonResponse `json:",inline"` | ||
|
||
// RetryAfterSeconds when set to a non-zero value signifies that the hook | ||
// will be called again at a future time. | ||
RetryAfterSeconds int `json:"retryAfterSeconds"` | ||
} | ||
|
||
// BeforeClusterCreate is the runtime hook that will be called right before a Cluster is created. | ||
func BeforeClusterCreate(*BeforeClusterCreateRequest, *BeforeClusterCreateResponse) {} | ||
|
||
// AfterControlPlaneInitializedRequest is the request of the AfterControlPlaneInitialized hook. | ||
// +kubebuilder:object:root=true | ||
type AfterControlPlaneInitializedRequest struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// The cluster object the lifecycle hook corresponds to. | ||
Cluster clusterv1.Cluster `json:"cluster"` | ||
} | ||
|
||
// AfterControlPlaneInitializedResponse is the response of the AfterControlPlaneInitialized hook. | ||
// +kubebuilder:object:root=true | ||
type AfterControlPlaneInitializedResponse struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// CommonResponse contains Status and Message fields common to all response types. | ||
CommonResponse `json:",inline"` | ||
} | ||
|
||
// AfterControlPlaneInitialized is the runtime hook that will be called after the control plane is available for the first time. | ||
func AfterControlPlaneInitialized(*AfterControlPlaneInitializedRequest, *AfterControlPlaneInitializedResponse) { | ||
} | ||
|
||
// BeforeClusterUpgradeRequest is the request of the BeforeClusterUpgrade hook. | ||
// +kubebuilder:object:root=true | ||
type BeforeClusterUpgradeRequest struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// The cluster object the lifecycle hook corresponds to. | ||
Cluster clusterv1.Cluster `json:"cluster"` | ||
|
||
// The current Kubernetes version of the cluster. | ||
FromKubernetesVersion string `json:"fromKubernetesVersion"` | ||
// The target Kubernetes version of upgrade. | ||
ToKubernetesVersion string `json:"toKubernetesVersion"` | ||
} | ||
|
||
// BeforeClusterUpgradeResponse is the response of the BeforeClusterUpgrade hook. | ||
// +kubebuilder:object:root=true | ||
type BeforeClusterUpgradeResponse struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// CommonResponse contains Status and Message fields common to all response types. | ||
CommonResponse `json:",inline"` | ||
|
||
// RetryAfterSeconds when set to a non-zero value signifies that the hook | ||
// needs to be retried at a future time. | ||
RetryAfterSeconds int `json:"retryAfterSeconds"` | ||
} | ||
|
||
// BeforeClusterUpgrade is the runtime hook that will be called after a cluster.spec.version is upgraded and | ||
// before the updated version is propagated to the underlying objects. | ||
func BeforeClusterUpgrade(*BeforeClusterUpgradeRequest, *BeforeClusterUpgradeResponse) {} | ||
|
||
// AfterControlPlaneUpgradeRequest is the request of the AfterControlPlaneUpgrade hook. | ||
// +kubebuilder:object:root=true | ||
type AfterControlPlaneUpgradeRequest struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// The cluster object the lifecycle hook corresponds to. | ||
Cluster clusterv1.Cluster `json:"cluster"` | ||
|
||
// The Kubernetes version after upgrade. | ||
KubernetesVersion string `json:"kubernetesVersion"` | ||
} | ||
|
||
// AfterControlPlaneUpgradeResponse is the response of the AfterControlPlaneUpgrade hook. | ||
// +kubebuilder:object:root=true | ||
type AfterControlPlaneUpgradeResponse struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// CommonResponse contains Status and Message fields common to all response types. | ||
CommonResponse `json:",inline"` | ||
|
||
// RetryAfterSeconds when set to a non-zero value signifies that the hook | ||
// needs to be retried at a future time. | ||
RetryAfterSeconds int `json:"retryAfterSeconds"` | ||
} | ||
|
||
// AfterControlPlaneUpgrade is the runtime hook called after the control plane is successfully upgraded to the target | ||
// Kubernetes version and before the target version is propagated to the workload machines. | ||
func AfterControlPlaneUpgrade(*AfterControlPlaneUpgradeRequest, *AfterControlPlaneUpgradeResponse) {} | ||
|
||
// AfterClusterUpgradeRequest is the request of the AfterClusterUpgrade hook. | ||
// +kubebuilder:object:root=true | ||
type AfterClusterUpgradeRequest struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// The cluster object the lifecycle hook corresponds to. | ||
Cluster clusterv1.Cluster `json:"cluster"` | ||
|
||
// The Kubernetes version after upgrade. | ||
KubernetesVersion string `json:"kubernetesVersion"` | ||
} | ||
|
||
// AfterClusterUpgradeResponse is the response of the AfterClusterUpgrade hook. | ||
// +kubebuilder:object:root=true | ||
type AfterClusterUpgradeResponse struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// CommonResponse contains Status and Message fields common to all response types. | ||
CommonResponse `json:",inline"` | ||
} | ||
|
||
// AfterClusterUpgrade is the runtime hook that is called after all of the cluster is updated | ||
// to the target kubernetes version. | ||
func AfterClusterUpgrade(*AfterClusterUpgradeRequest, *AfterClusterUpgradeResponse) {} | ||
|
||
// BeforeClusterDeleteRequest is the request of the BeforeClusterDelete hook. | ||
// +kubebuilder:object:root=true | ||
type BeforeClusterDeleteRequest struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// The cluster object the lifecycle hook corresponds to. | ||
Cluster clusterv1.Cluster `json:"cluster"` | ||
} | ||
|
||
// BeforeClusterDeleteResponse is the response of the BeforeClusterDelete hook. | ||
// +kubebuilder:object:root=true | ||
type BeforeClusterDeleteResponse struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// CommonResponse contains Status and Message fields common to all response types. | ||
CommonResponse `json:",inline"` | ||
|
||
// RetryAfterSeconds when set to a non-zero value signifies that the hook | ||
// needs to be retried at a future time. | ||
RetryAfterSeconds int `json:"retryAfterSeconds"` | ||
} | ||
|
||
// BeforeClusterDelete is the runtime hook that is called after a delete is issued on a cluster | ||
// and before the cluster and its underlying objects are deleted. | ||
func BeforeClusterDelete(*BeforeClusterDeleteRequest, *BeforeClusterDeleteResponse) {} | ||
|
||
func init() { | ||
catalogBuilder.RegisterHook(BeforeClusterCreate, &runtimecatalog.HookMeta{ | ||
Tags: []string{"Lifecycle Hooks"}, | ||
Summary: "Called before Cluster topology is created", | ||
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", | ||
}) | ||
|
||
catalogBuilder.RegisterHook(AfterControlPlaneInitialized, &runtimecatalog.HookMeta{ | ||
Tags: []string{"Lifecycle Hooks"}, | ||
Summary: "Called after the Control Plane is available for the first time", | ||
Description: "This non-blocking hook is called after the ControlPlane for the Cluster is marked as available for the first time", | ||
}) | ||
|
||
catalogBuilder.RegisterHook(BeforeClusterUpgrade, &runtimecatalog.HookMeta{ | ||
Tags: []string{"Lifecycle Hooks"}, | ||
Summary: "Called before the Cluster begins upgrade", | ||
Description: "This blocking 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", | ||
}) | ||
|
||
catalogBuilder.RegisterHook(AfterControlPlaneUpgrade, &runtimecatalog.HookMeta{ | ||
Tags: []string{"Lifecycle Hooks"}, | ||
Summary: "Called after the Control Plane finished upgrade", | ||
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", | ||
}) | ||
|
||
catalogBuilder.RegisterHook(AfterClusterUpgrade, &runtimecatalog.HookMeta{ | ||
Tags: []string{"Lifecycle Hooks"}, | ||
Summary: "Called after the Cluster finished upgrade", | ||
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", | ||
}) | ||
|
||
catalogBuilder.RegisterHook(BeforeClusterDelete, &runtimecatalog.HookMeta{ | ||
Tags: []string{"Lifecycle Hooks"}, | ||
Summary: "Called before the Cluster is deleted", | ||
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", | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.