Skip to content

Commit

Permalink
RuntimeSDK:implement aggregateResponse for Runtime client
Browse files Browse the repository at this point in the history
Signed-off-by: killianmuldoon <[email protected]>
  • Loading branch information
killianmuldoon authored and sbueringer committed Jun 2, 2022
1 parent 496a1b2 commit dce7674
Show file tree
Hide file tree
Showing 15 changed files with 858 additions and 287 deletions.
27 changes: 27 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,21 @@ const (
// ResponseStatusFailure represents a failure response.
ResponseStatusFailure ResponseStatus = "Failure"
)

// CommonRetryResponse is the data structure which contains all
// common retry fields.
type CommonRetryResponse struct {
// 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
}
33 changes: 21 additions & 12 deletions exp/runtime/hooks/api/v1alpha1/lifecyclehooks_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ 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 {
Expand All @@ -40,9 +42,8 @@ type BeforeClusterCreateResponse struct {
// 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 +58,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,10 +83,13 @@ 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 {
Expand All @@ -92,9 +98,8 @@ type BeforeClusterUpgradeResponse struct {
// 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,6 +118,8 @@ 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 {
Expand All @@ -121,9 +128,8 @@ type AfterControlPlaneUpgradeResponse struct {
// 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 +148,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,6 +172,8 @@ 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 {
Expand All @@ -172,9 +182,8 @@ type BeforeClusterDeleteResponse struct {
// 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
21 changes: 21 additions & 0 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.

36 changes: 30 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

0 comments on commit dce7674

Please sign in to comment.