Skip to content

Commit

Permalink
remove wait for disk call and add retry for busy error code
Browse files Browse the repository at this point in the history
  • Loading branch information
eljohnson92 committed Apr 23, 2024
1 parent f004a6f commit d833668
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 67 deletions.
1 change: 0 additions & 1 deletion cloud/scope/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type LinodeInstanceClient interface {
GetImage(ctx context.Context, imageID string) (*linodego.Image, error)
CreateStackscript(ctx context.Context, opts linodego.StackscriptCreateOptions) (*linodego.Stackscript, error)
ListStackscripts(ctx context.Context, opts *linodego.ListOptions) ([]linodego.Stackscript, error)
WaitForInstanceDiskStatus(ctx context.Context, instanceID int, diskID int, status linodego.DiskStatus, timeoutSeconds int) (*linodego.InstanceDisk, error)
}

// LinodeVPCClient defines the methods that a Linode client must have to interact with Linode's VPC service.
Expand Down
20 changes: 5 additions & 15 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ import (
)

const (
linodeBusyCode = 400
defaultDiskFilesystem = string(linodego.FilesystemExt4)
defaultResizeWaitSeconds = 5
linodeBusyCode = 400
defaultDiskFilesystem = string(linodego.FilesystemExt4)

// conditions for preflight instance creation
ConditionPreflightCreated clusterv1.ConditionType = "PreflightCreated"
Expand Down Expand Up @@ -413,7 +412,9 @@ func (r *LinodeMachineReconciler) createDisks(ctx context.Context, logger logr.L
},
)
if err != nil {
logger.Error(err, "Failed to create disk", "DiskLabel", label)
if !linodego.ErrHasStatus(err, linodeBusyCode) {
logger.Error(err, "Failed to create disk", "DiskLabel", label)
}

conditions.MarkFalse(
machineScope.LinodeMachine,
Expand Down Expand Up @@ -490,17 +491,6 @@ func (r *LinodeMachineReconciler) resizeRootDisk(
conditions.MarkTrue(machineScope.LinodeMachine, ConditionPreflightRootDiskResizing)
}

// wait for the disk to resize
if _, err := machineScope.LinodeClient.WaitForInstanceDiskStatus(ctx, linodeInstanceID, rootDiskID, linodego.DiskReady, defaultResizeWaitSeconds); err != nil {
logger.Info("Timed out resizing root disk",
"timeout", defaultResizeWaitSeconds,
"reqeue", true,
)
conditions.MarkFalse(machineScope.LinodeMachine, ConditionPreflightRootDiskResized, string(cerrs.CreateMachineError), clusterv1.ConditionSeverityWarning, err.Error())

return err
}

conditions.Delete(machineScope.LinodeMachine, ConditionPreflightRootDiskResizing)
conditions.MarkTrue(machineScope.LinodeMachine, ConditionPreflightRootDiskResized)

Expand Down
32 changes: 11 additions & 21 deletions controller/linodemachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,13 @@ var _ = Describe("create", Label("machine", "create"), func() {
ResizeInstanceDisk(ctx, 123, 100, 4262).
After(getInstDisk).
Return(nil)
waitForInstDisk := mockLinodeClient.EXPECT().
WaitForInstanceDiskStatus(ctx, 123, 100, linodego.DiskReady, defaultResizeWaitSeconds).
After(resizeInstDisk).
Return(nil, nil)
createEtcdDisk := mockLinodeClient.EXPECT().
CreateInstanceDisk(ctx, 123, linodego.InstanceDiskCreateOptions{
Label: "etcd-data",
Size: 10738,
Filesystem: string(linodego.FilesystemExt4),
}).
After(waitForInstDisk).
After(resizeInstDisk).
Return(&linodego.InstanceDisk{ID: 101}, nil)
listInstConfsForProfile := mockLinodeClient.EXPECT().
ListInstanceConfigs(ctx, 123, gomock.Any()).
Expand Down Expand Up @@ -398,10 +394,15 @@ var _ = Describe("create", Label("machine", "create"), func() {
ResizeInstanceDisk(ctx, 123, 100, 4262).
After(getInstDisk).
Return(nil)
mockLinodeClient.EXPECT().
WaitForInstanceDiskStatus(ctx, 123, 100, linodego.DiskReady, defaultResizeWaitSeconds).

createFailedEtcdDisk := mockLinodeClient.EXPECT().
CreateInstanceDisk(ctx, 123, linodego.InstanceDiskCreateOptions{
Label: "etcd-data",
Size: 10738,
Filesystem: string(linodego.FilesystemExt4),
}).
After(resizeInstDisk).
Return(nil, errors.New("Waiting for Instance 123 Disk 100 status ready: not yet"))
Return(nil, linodego.Error{Code: 400})

mScope := scope.MachineScope{
Client: k8sClient,
Expand All @@ -421,30 +422,19 @@ var _ = Describe("create", Label("machine", "create"), func() {

listInst = mockLinodeClient.EXPECT().
ListInstances(ctx, gomock.Any()).
After(createFailedEtcdDisk).
Return([]linodego.Instance{{
ID: 123,
IPv4: []*net.IP{ptr.To(net.IPv4(192, 168, 0, 2))},
Status: linodego.InstanceOffline,
}}, nil)
listInstConfs = mockLinodeClient.EXPECT().
ListInstanceConfigs(ctx, 123, gomock.Any()).
After(listInst).
Return([]linodego.InstanceConfig{{
Devices: &linodego.InstanceConfigDeviceMap{
SDA: &linodego.InstanceConfigDevice{DiskID: 100},
},
}}, nil)
waitForInstDisk := mockLinodeClient.EXPECT().
WaitForInstanceDiskStatus(ctx, 123, 100, linodego.DiskReady, defaultResizeWaitSeconds).
After(listInstConfs).
Return(nil, nil)
createEtcdDisk := mockLinodeClient.EXPECT().
CreateInstanceDisk(ctx, 123, linodego.InstanceDiskCreateOptions{
Label: "etcd-data",
Size: 10738,
Filesystem: string(linodego.FilesystemExt4),
}).
After(waitForInstDisk).
After(listInst).
Return(&linodego.InstanceDisk{ID: 101}, nil)
listInstConfsForProfile := mockLinodeClient.EXPECT().
ListInstanceConfigs(ctx, 123, gomock.Any()).
Expand Down
30 changes: 0 additions & 30 deletions mock/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d833668

Please sign in to comment.