Skip to content

Commit c3d0dc5

Browse files
committed
Change ExtensionConfig handler timeoutSeconds from *int32 to int32 and
add Minimum=1
1 parent a21ffb0 commit c3d0dc5

File tree

8 files changed

+27
-22
lines changed

8 files changed

+27
-22
lines changed

api/runtime/v1alpha1/conversion.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ func (dst *ExtensionConfig) ConvertFrom(srcRaw conversion.Hub) error {
4040
}
4141

4242
dropEmptyStringsExtensionConfig(dst)
43+
for i, h := range dst.Status.Handlers {
44+
if h.TimeoutSeconds != nil && *h.TimeoutSeconds == 0 {
45+
h.TimeoutSeconds = nil
46+
}
47+
dst.Status.Handlers[i] = h
48+
}
4349
return nil
4450
}
4551

api/runtime/v1alpha1/zz_generated.conversion.go

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

api/runtime/v1beta2/extensionconfig_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ type ExtensionHandler struct {
172172
RequestHook GroupVersionHook `json:"requestHook"`
173173

174174
// timeoutSeconds defines the timeout duration for client calls to the ExtensionHandler.
175-
// Defaults to 10 is not set.
175+
// Defaults to 10 if not set.
176176
// +optional
177-
TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty"`
177+
// +kubebuilder:validation:Minimum=1
178+
TimeoutSeconds int32 `json:"timeoutSeconds,omitempty"`
178179

179180
// failurePolicy defines how failures in calls to the ExtensionHandler should be handled by a client.
180181
// Defaults to Fail if not set.

api/runtime/v1beta2/zz_generated.deepcopy.go

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/runtime.cluster.x-k8s.io_extensionconfigs.yaml

Lines changed: 2 additions & 1 deletion
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (c *client) Discover(ctx context.Context, extensionConfig *runtimev1.Extens
141141
APIVersion: handler.RequestHook.APIVersion,
142142
Hook: handler.RequestHook.Hook,
143143
},
144-
TimeoutSeconds: handler.TimeoutSeconds,
144+
TimeoutSeconds: ptr.Deref(handler.TimeoutSeconds, 0),
145145
FailurePolicy: runtimev1.FailurePolicy(ptr.Deref(handler.FailurePolicy, "")),
146146
},
147147
)
@@ -305,8 +305,8 @@ func (c *client) CallExtension(ctx context.Context, hook runtimecatalog.Hook, fo
305305

306306
log.V(4).Info(fmt.Sprintf("Calling extension handler %q", name))
307307
timeoutDuration := runtimehooksv1.DefaultHandlersTimeoutSeconds * time.Second
308-
if registration.TimeoutSeconds != nil {
309-
timeoutDuration = time.Duration(*registration.TimeoutSeconds) * time.Second
308+
if registration.TimeoutSeconds != 0 {
309+
timeoutDuration = time.Duration(registration.TimeoutSeconds) * time.Second
310310
}
311311

312312
// Prepare the request by merging the settings in the registration with the settings in the request.

internal/runtime/client/client_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ func TestClient_CallExtension(t *testing.T) {
562562
APIVersion: fakev1alpha1.GroupVersion.String(),
563563
Hook: "FakeHook",
564564
},
565-
TimeoutSeconds: ptr.To[int32](1),
565+
TimeoutSeconds: 1,
566566
FailurePolicy: runtimev1.FailurePolicyFail,
567567
},
568568
},
@@ -587,7 +587,7 @@ func TestClient_CallExtension(t *testing.T) {
587587
APIVersion: fakev1alpha1.GroupVersion.String(),
588588
Hook: "FakeHook",
589589
},
590-
TimeoutSeconds: ptr.To[int32](1),
590+
TimeoutSeconds: 1,
591591
FailurePolicy: runtimev1.FailurePolicyIgnore,
592592
},
593593
},
@@ -956,7 +956,7 @@ func TestClient_CallAllExtensions(t *testing.T) {
956956
APIVersion: fakev1alpha1.GroupVersion.String(),
957957
Hook: "FakeHook",
958958
},
959-
TimeoutSeconds: ptr.To[int32](1),
959+
TimeoutSeconds: 1,
960960
FailurePolicy: runtimev1.FailurePolicyFail,
961961
},
962962
{
@@ -965,7 +965,7 @@ func TestClient_CallAllExtensions(t *testing.T) {
965965
APIVersion: fakev1alpha1.GroupVersion.String(),
966966
Hook: "FakeHook",
967967
},
968-
TimeoutSeconds: ptr.To[int32](1),
968+
TimeoutSeconds: 1,
969969
FailurePolicy: runtimev1.FailurePolicyFail,
970970
},
971971
{
@@ -974,7 +974,7 @@ func TestClient_CallAllExtensions(t *testing.T) {
974974
APIVersion: fakev1alpha1.GroupVersion.String(),
975975
Hook: "FakeHook",
976976
},
977-
TimeoutSeconds: ptr.To[int32](1),
977+
TimeoutSeconds: 1,
978978
FailurePolicy: runtimev1.FailurePolicyFail,
979979
},
980980
},

internal/runtime/registry/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type ExtensionRegistration struct {
7777
ClientConfig runtimev1.ClientConfig
7878

7979
// TimeoutSeconds is the timeout duration used for calls to the RuntimeExtension.
80-
TimeoutSeconds *int32
80+
TimeoutSeconds int32
8181

8282
// FailurePolicy defines how failures in calls to the RuntimeExtension should be handled by a client.
8383
FailurePolicy runtimev1.FailurePolicy

0 commit comments

Comments
 (0)