Skip to content

Commit 2c82a98

Browse files
committed
capi: add timeout when provisioning
Adds a 15m timeout to the infrastructure provisioning and machine provisioning stages of CAPI, so that the controllers do not spin indefinitely in the case of a failure. 15m is an arbitrary value, but the criteria for the timeout should be based on the balance of ample time to provision the resources with not making users wait too long if something goes wrong.
1 parent a70f3aa commit 2c82a98

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/infrastructure/clusterapi/clusterapi.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ import (
4040
// interface the installer uses to call this provider.
4141
var _ infrastructure.Provider = (*InfraProvider)(nil)
4242

43+
// timeout for each provisioning step.
44+
const timeout = 15 * time.Minute
45+
4346
// InfraProvider implements common Cluster API logic and
4447
// contains the platform CAPI provider, which is called
4548
// in the lifecycle defined by the Provider interface.
@@ -159,6 +162,7 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
159162
Duration: time.Second * 10,
160163
Factor: float64(1.5),
161164
Steps: 32,
165+
Cap: timeout,
162166
}, func(ctx context.Context) (bool, error) {
163167
c := &clusterv1.Cluster{}
164168
if err := cl.Get(ctx, client.ObjectKey{
@@ -173,7 +177,7 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
173177
cluster = c
174178
return cluster.Status.InfrastructureReady, nil
175179
}); err != nil {
176-
return fileList, err
180+
return fileList, fmt.Errorf("infrastructure was not ready within %v: %w", timeout, err)
177181
}
178182
if cluster == nil {
179183
return fileList, fmt.Errorf("error occurred during load balancer ready check")
@@ -243,6 +247,7 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
243247
Duration: time.Second * 10,
244248
Factor: float64(1.5),
245249
Steps: 32,
250+
Cap: timeout,
246251
}, func(ctx context.Context) (bool, error) {
247252
for i := int64(0); i < masterCount; i++ {
248253
machine := &clusterv1.Machine{}
@@ -266,7 +271,7 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
266271
}
267272
return true, nil
268273
}); err != nil {
269-
return fileList, err
274+
return fileList, fmt.Errorf("machines were not provisioned within %v: %w", timeout, err)
270275
}
271276
}
272277

0 commit comments

Comments
 (0)