Skip to content

Commit

Permalink
add a more generalized spec for modifying linode disks (#250)
Browse files Browse the repository at this point in the history
* add a more generalized spec for modifying linode disks

---------

Co-authored-by: Ashley Dumaine <[email protected]>
  • Loading branch information
eljohnson92 and AshleyDumaine authored Apr 16, 2024
1 parent 67bbd55 commit 4210732
Show file tree
Hide file tree
Showing 17 changed files with 647 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ linters-settings:
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: github.com/crossplane/provider-template
local-prefixes: github.com/linode/cluster-api-provider-linode

cyclop:
max-complexity: 15
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ lint: ## Run lint against code.

.PHONY: nilcheck
nilcheck: nilaway ## Run nil check against code.
go list ./... | xargs -I {} -d '\n' nilaway -include-pkgs {} ./...
go list ./... | xargs -I {} -d '\n' nilaway -include-pkgs {} -exclude-file-docstrings "ignore_autogenerated" ./...

.PHONY: vulncheck
vulncheck: govulncheck ## Run vulnerability check against code.
Expand Down
21 changes: 21 additions & 0 deletions api/v1alpha1/linodemachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha1
import (
"github.com/linode/linodego"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/errors"
Expand Down Expand Up @@ -64,6 +65,12 @@ type LinodeMachineSpec struct {
Tags []string `json:"tags,omitempty"`
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
FirewallID int `json:"firewallID,omitempty"`
// OSDisk is configuration for the root disk that includes the OS,
// if not specified this defaults to whatever space is not taken up by the DataDisks
OSDisk *InstanceDisk `json:"osDisk,omitempty"`
// DataDisks is a map of any additional disks to add to an instance,
// The sum of these disks + the OSDisk must not be more than allowed on a linodes plan
DataDisks map[string]*InstanceDisk `json:"dataDisks,omitempty"`

// CredentialsRef is a reference to a Secret that contains the credentials
// to use for provisioning this machine. If not supplied then these
Expand All @@ -75,6 +82,20 @@ type LinodeMachineSpec struct {
CredentialsRef *corev1.SecretReference `json:"credentialsRef,omitempty"`
}

// InstanceDisk defines a list of disks to use for an instance
type InstanceDisk struct {
// DiskID is the linode assigned ID of the disk
DiskID int `json:"diskID,omitempty"`
// Size of the disk in resource.Quantity notation
// +kubebuilder:validation:Required
Size resource.Quantity `json:"size"`
// Label for the instance disk, if nothing is provided it will match the device name
Label string `json:"label,omitempty"`
// Filesystem of disk to provision, the default disk filesystem is "ext4"
// +kubebuilder:validation:Enum=raw;swap;ext3;ext4;initrd
Filesystem string `json:"filesystem,omitempty"`
}

// InstanceMetadataOptions defines metadata of instance
type InstanceMetadataOptions struct {
// UserData expects a Base64-encoded string
Expand Down
37 changes: 37 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions cloud/scope/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type LinodeInstanceClient interface {
CreateInstance(ctx context.Context, opts linodego.InstanceCreateOptions) (*linodego.Instance, error)
BootInstance(ctx context.Context, linodeID int, configID int) error
ListInstanceConfigs(ctx context.Context, linodeID int, opts *linodego.ListOptions) ([]linodego.InstanceConfig, error)
UpdateInstanceConfig(ctx context.Context, linodeID int, configID int, opts linodego.InstanceConfigUpdateOptions) (*linodego.InstanceConfig, error)
GetInstanceDisk(ctx context.Context, linodeID int, diskID int) (*linodego.InstanceDisk, error)
ResizeInstanceDisk(ctx context.Context, linodeID int, diskID int, size int) error
CreateInstanceDisk(ctx context.Context, linodeID int, opts linodego.InstanceDiskCreateOptions) (*linodego.InstanceDisk, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,42 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
dataDisks:
additionalProperties:
description: InstanceDisk defines a list of disks to use for an
instance
properties:
diskID:
description: DiskID is the linode assigned ID of the disk
type: integer
filesystem:
description: Filesystem of disk to provision, the default disk
filesystem is "ext4"
enum:
- raw
- swap
- ext3
- ext4
- initrd
type: string
label:
description: Label for the instance disk, if nothing is provided
it will match the device name
type: string
size:
anyOf:
- type: integer
- type: string
description: Size of the disk in resource.Quantity notation
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
required:
- size
type: object
description: |-
DataDisks is a map of any additional disks to add to an instance,
The sum of these disks + the OSDisk must not be more than allowed on a linodes plan
type: object
firewallID:
type: integer
x-kubernetes-validations:
Expand Down Expand Up @@ -161,6 +197,38 @@ spec:
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
osDisk:
description: |-
OSDisk is configuration for the root disk that includes the OS,
if not specified this defaults to whatever space is not taken up by the DataDisks
properties:
diskID:
description: DiskID is the linode assigned ID of the disk
type: integer
filesystem:
description: Filesystem of disk to provision, the default disk
filesystem is "ext4"
enum:
- raw
- swap
- ext3
- ext4
- initrd
type: string
label:
description: Label for the instance disk, if nothing is provided
it will match the device name
type: string
size:
anyOf:
- type: integer
- type: string
description: Size of the disk in resource.Quantity notation
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
required:
- size
type: object
privateIP:
type: boolean
x-kubernetes-validations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,43 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
dataDisks:
additionalProperties:
description: InstanceDisk defines a list of disks to use
for an instance
properties:
diskID:
description: DiskID is the linode assigned ID of the
disk
type: integer
filesystem:
description: Filesystem of disk to provision, the default
disk filesystem is "ext4"
enum:
- raw
- swap
- ext3
- ext4
- initrd
type: string
label:
description: Label for the instance disk, if nothing
is provided it will match the device name
type: string
size:
anyOf:
- type: integer
- type: string
description: Size of the disk in resource.Quantity notation
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
required:
- size
type: object
description: |-
DataDisks is a map of any additional disks to add to an instance,
The sum of these disks + the OSDisk must not be more than allowed on a linodes plan
type: object
firewallID:
type: integer
x-kubernetes-validations:
Expand Down Expand Up @@ -150,6 +187,38 @@ spec:
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
osDisk:
description: |-
OSDisk is configuration for the root disk that includes the OS,
if not specified this defaults to whatever space is not taken up by the DataDisks
properties:
diskID:
description: DiskID is the linode assigned ID of the disk
type: integer
filesystem:
description: Filesystem of disk to provision, the default
disk filesystem is "ext4"
enum:
- raw
- swap
- ext3
- ext4
- initrd
type: string
label:
description: Label for the instance disk, if nothing is
provided it will match the device name
type: string
size:
anyOf:
- type: integer
- type: string
description: Size of the disk in resource.Quantity notation
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
required:
- size
type: object
privateIP:
type: boolean
x-kubernetes-validations:
Expand Down
Loading

0 comments on commit 4210732

Please sign in to comment.