Skip to content
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

🌱 RuntimeSDK: Implement aggregateResponse for Runtime client #6581

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ type ResponseObject interface {
SetStatus(status ResponseStatus)
}

// RetryResponseObject is a ResponseObject which additionally defines the functionality
// for a response to signal a retry.
// +kubebuilder:object:generate=false
type RetryResponseObject interface {
ResponseObject
GetRetryAfterSeconds() int32
SetRetryAfterSeconds(retryAfterSeconds int32)
}

// CommonResponse is the data structure common to all response types.
type CommonResponse struct {
// Status of the call. One of "Success" or "Failure".
Expand Down Expand Up @@ -70,3 +79,24 @@ const (
// ResponseStatusFailure represents a failure response.
ResponseStatusFailure ResponseStatus = "Failure"
)

// CommonRetryResponse is the data structure which contains all
// common retry fields.
type CommonRetryResponse struct {
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
// 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 int32 `json:"retryAfterSeconds"`
}

// GetRetryAfterSeconds sets the RetryAfterSeconds value.
func (r *CommonRetryResponse) GetRetryAfterSeconds() int32 {
return r.RetryAfterSeconds
}

// SetRetryAfterSeconds returns the RetryAfterSeconds value.
func (r *CommonRetryResponse) SetRetryAfterSeconds(retryAfterSeconds int32) {
r.RetryAfterSeconds = retryAfterSeconds
}
45 changes: 21 additions & 24 deletions exp/runtime/hooks/api/v1alpha1/lifecyclehooks_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ type BeforeClusterCreateRequest struct {
Cluster clusterv1.Cluster `json:"cluster"`
}

var _ RetryResponseObject = &BeforeClusterCreateResponse{}

// 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"`
// CommonRetryResponse contains RetryAfterSeconds field common to all retry response types.
CommonRetryResponse `json:",inline"`
}

// BeforeClusterCreate is the runtime hook that will be called right before a Cluster is created.
Expand All @@ -57,6 +55,8 @@ type AfterControlPlaneInitializedRequest struct {
Cluster clusterv1.Cluster `json:"cluster"`
}

var _ ResponseObject = &AfterControlPlaneInitializedResponse{}

// AfterControlPlaneInitializedResponse is the response of the AfterControlPlaneInitialized hook.
// +kubebuilder:object:root=true
type AfterControlPlaneInitializedResponse struct {
Expand All @@ -80,21 +80,20 @@ type BeforeClusterUpgradeRequest struct {

// The current Kubernetes version of the cluster.
FromKubernetesVersion string `json:"fromKubernetesVersion"`

// The target Kubernetes version of upgrade.
ToKubernetesVersion string `json:"toKubernetesVersion"`
}

var _ RetryResponseObject = &BeforeClusterUpgradeResponse{}

// 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"`
// CommonRetryResponse contains RetryAfterSeconds field common to all retry response types.
CommonRetryResponse `json:",inline"`
}

// BeforeClusterUpgrade is the runtime hook that will be called after a cluster.spec.version is upgraded and
Expand All @@ -113,17 +112,15 @@ type AfterControlPlaneUpgradeRequest struct {
KubernetesVersion string `json:"kubernetesVersion"`
}

var _ RetryResponseObject = &AfterControlPlaneUpgradeResponse{}

// 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"`
// CommonRetryResponse contains RetryAfterSeconds field common to all retry response types.
CommonRetryResponse `json:",inline"`
}

// AfterControlPlaneUpgrade is the runtime hook called after the control plane is successfully upgraded to the target
Expand All @@ -142,6 +139,8 @@ type AfterClusterUpgradeRequest struct {
KubernetesVersion string `json:"kubernetesVersion"`
}

var _ ResponseObject = &AfterClusterUpgradeResponse{}

// AfterClusterUpgradeResponse is the response of the AfterClusterUpgrade hook.
// +kubebuilder:object:root=true
type AfterClusterUpgradeResponse struct {
Expand All @@ -164,17 +163,15 @@ type BeforeClusterDeleteRequest struct {
Cluster clusterv1.Cluster `json:"cluster"`
}

var _ RetryResponseObject = &BeforeClusterDeleteResponse{}

// 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"`
// CommonRetryResponse contains RetryAfterSeconds field common to all retry response types.
CommonRetryResponse `json:",inline"`
}

// BeforeClusterDelete is the runtime hook that is called after a delete is issued on a cluster
Expand Down
20 changes: 8 additions & 12 deletions exp/runtime/hooks/api/v1alpha1/topologymutation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,17 @@ type GeneratePatchesRequestItem struct {
Variables []Variable `json:"variables"`
}

var _ ResponseObject = &GeneratePatchesResponse{}

// GeneratePatchesResponse is the response of the GeneratePatches hook.
// NOTE: The patches in GeneratePatchesResponse will be applied in the order in which they are defined to the
// templates of the request. Thus applying changes consecutively when iterating through internal and external patches.
// +kubebuilder:object:root=true
type GeneratePatchesResponse struct {
metav1.TypeMeta `json:",inline"`

// Status of the call.
// One of: "Success" or "Failure".
Status ResponseStatus `json:"status"`

// A human-readable description of the status of the call.
Message string `json:"message,omitempty"`
// CommonResponse contains Status and Message fields common to all response types.
CommonResponse `json:",inline"`

// Items is the list of generated patches.
Items []GeneratePatchesResponseItem `json:"items"`
Expand Down Expand Up @@ -131,17 +129,15 @@ type ValidateTopologyRequestItem struct {
Variables []Variable `json:"variables"`
}

var _ ResponseObject = &ValidateTopologyResponse{}

// ValidateTopologyResponse is the response of the ValidateTopology hook.
// +kubebuilder:object:root=true
type ValidateTopologyResponse struct {
metav1.TypeMeta `json:",inline"`

// Status of the call.
// One of: "Success" or "Failure".
Status ResponseStatus `json:"status"`

// A human-readable description of the status of the call.
Message string `json:"message"`
// CommonResponse contains Status and Message fields common to all response types.
CommonResponse `json:",inline"`
}

// Variable represents a variable value.
Expand Down
26 changes: 22 additions & 4 deletions exp/runtime/hooks/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 46 additions & 6 deletions exp/runtime/hooks/api/v1alpha1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading