Skip to content

Commit 6878983

Browse files
killianmuldoonsbueringer
authored andcommitted
RuntimeSDK:implement aggregateResponse for Runtime client
Signed-off-by: killianmuldoon <[email protected]>
1 parent 496a1b2 commit 6878983

15 files changed

+877
-303
lines changed

exp/runtime/hooks/api/v1alpha1/common_types.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ type ResponseObject interface {
3030
SetStatus(status ResponseStatus)
3131
}
3232

33+
// RetryResponseObject is a ResponseObject which additionally defines the functionality
34+
// for a response to signal a retry.
35+
// +kubebuilder:object:generate=false
36+
type RetryResponseObject interface {
37+
ResponseObject
38+
GetRetryAfterSeconds() int32
39+
SetRetryAfterSeconds(retryAfterSeconds int32)
40+
}
41+
3342
// CommonResponse is the data structure common to all response types.
3443
type CommonResponse struct {
3544
// Status of the call. One of "Success" or "Failure".
@@ -70,3 +79,24 @@ const (
7079
// ResponseStatusFailure represents a failure response.
7180
ResponseStatusFailure ResponseStatus = "Failure"
7281
)
82+
83+
// CommonRetryResponse is the data structure which contains all
84+
// common retry fields.
85+
type CommonRetryResponse struct {
86+
// CommonResponse contains Status and Message fields common to all response types.
87+
CommonResponse `json:",inline"`
88+
89+
// RetryAfterSeconds when set to a non-zero value signifies that the hook
90+
// will be called again at a future time.
91+
RetryAfterSeconds int32 `json:"retryAfterSeconds"`
92+
}
93+
94+
// GetRetryAfterSeconds sets the RetryAfterSeconds value.
95+
func (r *CommonRetryResponse) GetRetryAfterSeconds() int32 {
96+
return r.RetryAfterSeconds
97+
}
98+
99+
// SetRetryAfterSeconds returns the RetryAfterSeconds value.
100+
func (r *CommonRetryResponse) SetRetryAfterSeconds(retryAfterSeconds int32) {
101+
r.RetryAfterSeconds = retryAfterSeconds
102+
}

exp/runtime/hooks/api/v1alpha1/lifecyclehooks_types.go

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ type BeforeClusterCreateRequest struct {
3232
Cluster clusterv1.Cluster `json:"cluster"`
3333
}
3434

35+
var _ RetryResponseObject = &BeforeClusterCreateResponse{}
36+
3537
// BeforeClusterCreateResponse is the response of the BeforeClusterCreate hook.
3638
// +kubebuilder:object:root=true
3739
type BeforeClusterCreateResponse struct {
3840
metav1.TypeMeta `json:",inline"`
3941

40-
// CommonResponse contains Status and Message fields common to all response types.
41-
CommonResponse `json:",inline"`
42-
43-
// RetryAfterSeconds when set to a non-zero value signifies that the hook
44-
// will be called again at a future time.
45-
RetryAfterSeconds int `json:"retryAfterSeconds"`
42+
// CommonRetryResponse contains RetryAfterSeconds field common to all retry response types.
43+
CommonRetryResponse `json:",inline"`
4644
}
4745

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

58+
var _ ResponseObject = &AfterControlPlaneInitializedResponse{}
59+
6060
// AfterControlPlaneInitializedResponse is the response of the AfterControlPlaneInitialized hook.
6161
// +kubebuilder:object:root=true
6262
type AfterControlPlaneInitializedResponse struct {
@@ -80,21 +80,20 @@ type BeforeClusterUpgradeRequest struct {
8080

8181
// The current Kubernetes version of the cluster.
8282
FromKubernetesVersion string `json:"fromKubernetesVersion"`
83+
8384
// The target Kubernetes version of upgrade.
8485
ToKubernetesVersion string `json:"toKubernetesVersion"`
8586
}
8687

88+
var _ RetryResponseObject = &BeforeClusterUpgradeResponse{}
89+
8790
// BeforeClusterUpgradeResponse is the response of the BeforeClusterUpgrade hook.
8891
// +kubebuilder:object:root=true
8992
type BeforeClusterUpgradeResponse struct {
9093
metav1.TypeMeta `json:",inline"`
9194

92-
// CommonResponse contains Status and Message fields common to all response types.
93-
CommonResponse `json:",inline"`
94-
95-
// RetryAfterSeconds when set to a non-zero value signifies that the hook
96-
// needs to be retried at a future time.
97-
RetryAfterSeconds int `json:"retryAfterSeconds"`
95+
// CommonRetryResponse contains RetryAfterSeconds field common to all retry response types.
96+
CommonRetryResponse `json:",inline"`
9897
}
9998

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

115+
var _ RetryResponseObject = &AfterControlPlaneUpgradeResponse{}
116+
116117
// AfterControlPlaneUpgradeResponse is the response of the AfterControlPlaneUpgrade hook.
117118
// +kubebuilder:object:root=true
118119
type AfterControlPlaneUpgradeResponse struct {
119120
metav1.TypeMeta `json:",inline"`
120121

121-
// CommonResponse contains Status and Message fields common to all response types.
122-
CommonResponse `json:",inline"`
123-
124-
// RetryAfterSeconds when set to a non-zero value signifies that the hook
125-
// needs to be retried at a future time.
126-
RetryAfterSeconds int `json:"retryAfterSeconds"`
122+
// CommonRetryResponse contains RetryAfterSeconds field common to all retry response types.
123+
CommonRetryResponse `json:",inline"`
127124
}
128125

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

142+
var _ ResponseObject = &AfterClusterUpgradeResponse{}
143+
145144
// AfterClusterUpgradeResponse is the response of the AfterClusterUpgrade hook.
146145
// +kubebuilder:object:root=true
147146
type AfterClusterUpgradeResponse struct {
@@ -164,17 +163,15 @@ type BeforeClusterDeleteRequest struct {
164163
Cluster clusterv1.Cluster `json:"cluster"`
165164
}
166165

166+
var _ RetryResponseObject = &BeforeClusterDeleteResponse{}
167+
167168
// BeforeClusterDeleteResponse is the response of the BeforeClusterDelete hook.
168169
// +kubebuilder:object:root=true
169170
type BeforeClusterDeleteResponse struct {
170171
metav1.TypeMeta `json:",inline"`
171172

172-
// CommonResponse contains Status and Message fields common to all response types.
173-
CommonResponse `json:",inline"`
174-
175-
// RetryAfterSeconds when set to a non-zero value signifies that the hook
176-
// needs to be retried at a future time.
177-
RetryAfterSeconds int `json:"retryAfterSeconds"`
173+
// CommonRetryResponse contains RetryAfterSeconds field common to all retry response types.
174+
CommonRetryResponse `json:",inline"`
178175
}
179176

180177
// BeforeClusterDelete is the runtime hook that is called after a delete is issued on a cluster

exp/runtime/hooks/api/v1alpha1/topologymutation_types.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,17 @@ type GeneratePatchesRequestItem struct {
5656
Variables []Variable `json:"variables"`
5757
}
5858

59+
var _ ResponseObject = &GeneratePatchesResponse{}
60+
5961
// GeneratePatchesResponse is the response of the GeneratePatches hook.
6062
// NOTE: The patches in GeneratePatchesResponse will be applied in the order in which they are defined to the
6163
// templates of the request. Thus applying changes consecutively when iterating through internal and external patches.
6264
// +kubebuilder:object:root=true
6365
type GeneratePatchesResponse struct {
6466
metav1.TypeMeta `json:",inline"`
6567

66-
// Status of the call.
67-
// One of: "Success" or "Failure".
68-
Status ResponseStatus `json:"status"`
69-
70-
// A human-readable description of the status of the call.
71-
Message string `json:"message,omitempty"`
68+
// CommonResponse contains Status and Message fields common to all response types.
69+
CommonResponse `json:",inline"`
7270

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

132+
var _ ResponseObject = &ValidateTopologyResponse{}
133+
134134
// ValidateTopologyResponse is the response of the ValidateTopology hook.
135135
// +kubebuilder:object:root=true
136136
type ValidateTopologyResponse struct {
137137
metav1.TypeMeta `json:",inline"`
138138

139-
// Status of the call.
140-
// One of: "Success" or "Failure".
141-
Status ResponseStatus `json:"status"`
142-
143-
// A human-readable description of the status of the call.
144-
Message string `json:"message"`
139+
// CommonResponse contains Status and Message fields common to all response types.
140+
CommonResponse `json:",inline"`
145141
}
146142

147143
// Variable represents a variable value.

exp/runtime/hooks/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 22 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/runtime/hooks/api/v1alpha1/zz_generated.openapi.go

Lines changed: 46 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)