Skip to content

Commit d520f8b

Browse files
committed
fixup
1 parent cb6fc6e commit d520f8b

14 files changed

+312
-145
lines changed

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

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

33-
// Retryable defines the functionality for a hook response to be retryable.
33+
// RetryResponseObject is a ResponseObject which additionally defines the functionality
34+
// for a response to signal a retry.
3435
// +kubebuilder:object:generate=false
35-
type Retryable interface {
36+
type RetryResponseObject interface {
37+
ResponseObject
3638
GetRetryAfterSeconds() int32
3739
SetRetryAfterSeconds(retryAfterSeconds int32)
3840
}
@@ -78,18 +80,20 @@ const (
7880
ResponseStatusFailure ResponseStatus = "Failure"
7981
)
8082

81-
// RetryableResponse is a CommonResponse that is Retryable.
82-
type RetryableResponse struct {
83-
CommonResponse
84-
RetryAfterSeconds int32
83+
// CommonRetryResponse is the data structure which contains all
84+
// common retry fields.
85+
type CommonRetryResponse struct {
86+
// RetryAfterSeconds when set to a non-zero value signifies that the hook
87+
// will be called again at a future time.
88+
RetryAfterSeconds int32 `json:"retryAfterSeconds"`
8589
}
8690

8791
// GetRetryAfterSeconds sets the RetryAfterSeconds value.
88-
func (r *RetryableResponse) GetRetryAfterSeconds() int32 {
92+
func (r *CommonRetryResponse) GetRetryAfterSeconds() int32 {
8993
return r.RetryAfterSeconds
9094
}
9195

9296
// SetRetryAfterSeconds returns the RetryAfterSeconds value.
93-
func (r *RetryableResponse) SetRetryAfterSeconds(retryAfterSeconds int32) {
97+
func (r *CommonRetryResponse) SetRetryAfterSeconds(retryAfterSeconds int32) {
9498
r.RetryAfterSeconds = retryAfterSeconds
9599
}

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ 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 {
@@ -40,9 +42,8 @@ type BeforeClusterCreateResponse struct {
4042
// CommonResponse contains Status and Message fields common to all response types.
4143
CommonResponse `json:",inline"`
4244

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

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

61+
var _ ResponseObject = &AfterControlPlaneInitializedResponse{}
62+
6063
// AfterControlPlaneInitializedResponse is the response of the AfterControlPlaneInitialized hook.
6164
// +kubebuilder:object:root=true
6265
type AfterControlPlaneInitializedResponse struct {
@@ -80,10 +83,13 @@ type BeforeClusterUpgradeRequest struct {
8083

8184
// The current Kubernetes version of the cluster.
8285
FromKubernetesVersion string `json:"fromKubernetesVersion"`
86+
8387
// The target Kubernetes version of upgrade.
8488
ToKubernetesVersion string `json:"toKubernetesVersion"`
8589
}
8690

91+
var _ RetryResponseObject = &BeforeClusterUpgradeResponse{}
92+
8793
// BeforeClusterUpgradeResponse is the response of the BeforeClusterUpgrade hook.
8894
// +kubebuilder:object:root=true
8995
type BeforeClusterUpgradeResponse struct {
@@ -92,9 +98,8 @@ type BeforeClusterUpgradeResponse struct {
9298
// CommonResponse contains Status and Message fields common to all response types.
9399
CommonResponse `json:",inline"`
94100

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

100105
// BeforeClusterUpgrade is the runtime hook that will be called after a cluster.spec.version is upgraded and
@@ -113,6 +118,8 @@ type AfterControlPlaneUpgradeRequest struct {
113118
KubernetesVersion string `json:"kubernetesVersion"`
114119
}
115120

121+
var _ RetryResponseObject = &AfterControlPlaneUpgradeResponse{}
122+
116123
// AfterControlPlaneUpgradeResponse is the response of the AfterControlPlaneUpgrade hook.
117124
// +kubebuilder:object:root=true
118125
type AfterControlPlaneUpgradeResponse struct {
@@ -121,9 +128,8 @@ type AfterControlPlaneUpgradeResponse struct {
121128
// CommonResponse contains Status and Message fields common to all response types.
122129
CommonResponse `json:",inline"`
123130

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

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

151+
var _ ResponseObject = &AfterClusterUpgradeResponse{}
152+
145153
// AfterClusterUpgradeResponse is the response of the AfterClusterUpgrade hook.
146154
// +kubebuilder:object:root=true
147155
type AfterClusterUpgradeResponse struct {
@@ -164,6 +172,8 @@ type BeforeClusterDeleteRequest struct {
164172
Cluster clusterv1.Cluster `json:"cluster"`
165173
}
166174

175+
var _ RetryResponseObject = &BeforeClusterDeleteResponse{}
176+
167177
// BeforeClusterDeleteResponse is the response of the BeforeClusterDelete hook.
168178
// +kubebuilder:object:root=true
169179
type BeforeClusterDeleteResponse struct {
@@ -172,9 +182,8 @@ type BeforeClusterDeleteResponse struct {
172182
// CommonResponse contains Status and Message fields common to all response types.
173183
CommonResponse `json:",inline"`
174184

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

180189
// 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: 21 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/runtime/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ func aggregateSuccessfulResponses(aggregated runtimehooksv1.ResponseObject, resp
215215
aggregated.SetMessage("")
216216
aggregated.SetStatus(runtimehooksv1.ResponseStatusSuccess)
217217
for _, resp := range responses {
218-
if retryable, ok := resp.(runtimehooksv1.Retryable); ok {
219-
if aggregatedRetryable, aggregatedOK := aggregated.(runtimehooksv1.Retryable); aggregatedOK {
218+
if retryable, ok := resp.(runtimehooksv1.RetryResponseObject); ok {
219+
if aggregatedRetryable, aggregatedOK := aggregated.(runtimehooksv1.RetryResponseObject); aggregatedOK {
220220
aggregatedRetryable.SetRetryAfterSeconds(
221221
lowestNonZeroRetryAfterSeconds(aggregatedRetryable.GetRetryAfterSeconds(), retryable.GetRetryAfterSeconds()),
222222
)

internal/runtime/client/client_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,9 @@ func Test_client_CallAllExtensions(t *testing.T) {
670670
}{
671671
{
672672
name: "success calling one extension for hook",
673-
hook: fakev1alpha1.FakeRetryableHook,
674-
request: &fakev1alpha1.FakeRetryableRequest{},
675-
response: &fakev1alpha1.FakeRetryableResponse{},
673+
hook: fakev1alpha1.RetryableFakeHook,
674+
request: &fakev1alpha1.RetryableFakeRequest{},
675+
response: &fakev1alpha1.RetryableFakeResponse{},
676676
wantErr: false,
677677
},
678678
}
@@ -746,7 +746,7 @@ func Test_aggregateResponses(t *testing.T) {
746746
}
747747
for _, tt := range tests {
748748
t.Run(tt.name, func(t *testing.T) {
749-
response := &fakev1alpha1.FakeRetryableResponse{TypeMeta: metav1.TypeMeta{Kind: "FakeResponse", APIVersion: "v1alpha1"}}
749+
response := &fakev1alpha1.RetryableFakeResponse{TypeMeta: metav1.TypeMeta{Kind: "FakeResponse", APIVersion: "v1alpha1"}}
750750
aggregateSuccessfulResponses(response, tt.responses)
751751
if !reflect.DeepEqual(response, tt.want) {
752752
t.Errorf("aggregateSuccessfulResponses() got = %v, want %v", response, tt.want)
@@ -755,17 +755,17 @@ func Test_aggregateResponses(t *testing.T) {
755755
}
756756
}
757757

758-
func fakeResponse(retryAfterSeconds int32) *fakev1alpha1.FakeRetryableResponse {
759-
return &fakev1alpha1.FakeRetryableResponse{
758+
func fakeResponse(retryAfterSeconds int32) *fakev1alpha1.RetryableFakeResponse {
759+
return &fakev1alpha1.RetryableFakeResponse{
760760
TypeMeta: metav1.TypeMeta{
761761
Kind: "FakeResponse",
762762
APIVersion: "v1alpha1",
763763
},
764-
RetryableResponse: runtimehooksv1.RetryableResponse{
765-
CommonResponse: runtimehooksv1.CommonResponse{
766-
Message: "",
767-
Status: runtimehooksv1.ResponseStatusSuccess,
768-
},
764+
CommonResponse: runtimehooksv1.CommonResponse{
765+
Message: "",
766+
Status: runtimehooksv1.ResponseStatusSuccess,
767+
},
768+
CommonRetryResponse: runtimehooksv1.CommonRetryResponse{
769769
RetryAfterSeconds: retryAfterSeconds,
770770
},
771771
}

internal/runtime/test/v1alpha1/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package v1alpha1 contains types for catalog tests
17+
// Package v1alpha1 contains types for tests.
1818
// Note: they have to be in a separate package because otherwise it wouldn't
1919
// be possible to register different versions of the same hook.
2020
// +k8s:conversion-gen=sigs.k8s.io/cluster-api/internal/runtime/test/v1alpha2

0 commit comments

Comments
 (0)