Skip to content

Commit

Permalink
half the root disk and make an etcd disk with it
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDumaine committed Feb 27, 2024
1 parent f8eaeda commit 8def323
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 110 deletions.
5 changes: 0 additions & 5 deletions api/v1alpha1/linodemachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ type LinodeMachineStatus struct {
// Addresses contains the Linode instance associated addresses.
Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`

// EtcdVolumeID contains the ID for the Linode volume associated the node
// (control plane nodes only)
// +optional
EtcdVolumeID int `json:"etcdVolumeID,omitempty"`

// InstanceState is the state of the Linode instance for this machine.
// +optional
InstanceState *linodego.InstanceStatus `json:"instanceState,omitempty"`
Expand Down
89 changes: 0 additions & 89 deletions cloud/services/volumes.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,6 @@ spec:
- type
type: object
type: array
etcdVolumeID:
description: |-
EtcdVolumeID contains the ID for the Linode volume associated the node
(control plane nodes only)
type: integer
failureMessage:
description: |-
FailureMessage will be set in the event that there is a terminal problem
Expand Down
47 changes: 37 additions & 10 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,47 @@ func (r *LinodeMachineReconciler) reconcileCreate(
return nil, err
}

volume, err := services.CreateEtcdVolume(ctx, linodeInstance.ID, logger, machineScope)
// get the default instance config
configs, err := machineScope.LinodeClient.ListInstanceConfigs(ctx, linodeInstance.ID, &linodego.ListOptions{})
if err != nil || len(configs) == 0 {
logger.Error(err, "Failed to list instance configs")

return nil, err
}
instanceConfig := configs[0]

// halve the root disk for etcd
rootDiskID := instanceConfig.Devices.SDA.DiskID
rootDisk, err := machineScope.LinodeClient.GetInstanceDisk(ctx, linodeInstance.ID, rootDiskID)

Check failure on line 356 in controller/linodemachine_controller.go

View workflow job for this annotation

GitHub Actions / go-analyse

ineffectual assignment to err (ineffassign)
etcdSize := rootDisk.Size / 2

Check failure on line 357 in controller/linodemachine_controller.go

View workflow job for this annotation

GitHub Actions / go-analyse

mnd: Magic number: 2, in <operation> detected (gomnd)
if err = machineScope.LinodeClient.ResizeInstanceDisk(ctx, linodeInstance.ID, rootDiskID, rootDisk.Size/2); err != nil {

Check failure on line 358 in controller/linodemachine_controller.go

View workflow job for this annotation

GitHub Actions / go-analyse

mnd: Magic number: 2, in <argument> detected (gomnd)
logger.Error(err, "Failed to resize root disk")

return nil, err
}

// create the etcd disk
etcdDisk, err := machineScope.LinodeClient.CreateInstanceDisk(
ctx,
linodeInstance.ID,
linodego.InstanceDiskCreateOptions{
Label: "etcd-data",
Size: etcdSize,
Filesystem: string(linodego.FilesystemExt4),
},
)
if err != nil {
logger.Error(err, "Failed to create etcd volume")
logger.Error(err, "Failed to create etcd disk")

return nil, err
}
if volume != nil {
machineScope.LinodeMachine.Status.EtcdVolumeID = volume.ID

instanceConfig.Devices.SDC = &linodego.InstanceConfigDevice{DiskID: etcdDisk.ID}
err = machineScope.LinodeClient.BootInstance(ctx, linodeInstance.ID, instanceConfig.ID)
if err != nil {
logger.Error(err, "Failed to boot instance")

return nil, err
}

default:
Expand Down Expand Up @@ -468,12 +501,6 @@ func (r *LinodeMachineReconciler) reconcileDelete(
return err
}

if err := services.DeleteEtcdVolume(ctx, logger, machineScope); err != nil {
logger.Error(err, "Failed to delete etcd volume")

return err
}

if err := machineScope.LinodeClient.DeleteInstance(ctx, *machineScope.LinodeMachine.Spec.InstanceID); err != nil {
if util.IgnoreLinodeAPIError(err, http.StatusNotFound) != nil {
logger.Error(err, "Failed to delete Linode machine instance")
Expand Down
4 changes: 3 additions & 1 deletion controller/linodemachine_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func (*LinodeMachineReconciler) newCreateConfig(ctx context.Context, machineScop

return nil, err
}

createConfig.Booted = util.Pointer(false)

createConfig.PrivateIP = true

bootstrapData, err := machineScope.GetBootstrapData(ctx)
Expand Down Expand Up @@ -87,7 +90,6 @@ func (*LinodeMachineReconciler) newCreateConfig(ctx context.Context, machineScop
if createConfig.Image == "" {
createConfig.Image = reconciler.DefaultMachineControllerLinodeImage
}

if createConfig.RootPass == "" {
createConfig.RootPass = uuid.NewString()
}
Expand Down

0 comments on commit 8def323

Please sign in to comment.