Skip to content

Commit

Permalink
Support missing fields in Instance and LKE ACL (linode#618)
Browse files Browse the repository at this point in the history
* add missing instances field

* typo

* add deprecation note

* nit
  • Loading branch information
yec-akamai authored Nov 19, 2024
1 parent d7dbe30 commit f1ff0b9
Show file tree
Hide file tree
Showing 7 changed files with 716 additions and 394 deletions.
43 changes: 40 additions & 3 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ type InstanceAlert struct {

// InstanceBackup represents backup settings for an instance
type InstanceBackup struct {
Available bool `json:"available,omitempty"` // read-only
Enabled bool `json:"enabled,omitempty"` // read-only
Schedule struct {
Available bool `json:"available,omitempty"` // read-only
Enabled bool `json:"enabled,omitempty"` // read-only
LastSuccessful *time.Time `json:"-"` // read-only
Schedule struct {
Day string `json:"day,omitempty"`
Window string `json:"window,omitempty"`
} `json:"schedule,omitempty"`
Expand Down Expand Up @@ -136,6 +137,7 @@ type InstancePlacementGroup struct {
Label string `json:"label"`
PlacementGroupType PlacementGroupType `json:"placement_group_type"`
PlacementGroupPolicy PlacementGroupPolicy `json:"placement_group_policy"`
MigratingTo string `json:"migrating_to"` // read-only
}

// InstanceMetadataOptions specifies various Instance creation fields
Expand Down Expand Up @@ -225,6 +227,26 @@ func (i *Instance) UnmarshalJSON(b []byte) error {
return nil
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (backup *InstanceBackup) UnmarshalJSON(b []byte) error {
type Mask InstanceBackup

p := struct {
*Mask
LastSuccessful *parseabletime.ParseableTime `json:"last_successful"`
}{
Mask: (*Mask)(backup),
}

if err := json.Unmarshal(b, &p); err != nil {
return err
}

backup.LastSuccessful = (*time.Time)(p.LastSuccessful)

return nil
}

// GetUpdateOptions converts an Instance to InstanceUpdateOptions for use in UpdateInstance
func (i *Instance) GetUpdateOptions() InstanceUpdateOptions {
return InstanceUpdateOptions{
Expand Down Expand Up @@ -448,11 +470,26 @@ func (c *Client) ShutdownInstance(ctx context.Context, id int) error {
return c.simpleInstanceAction(ctx, "shutdown", id)
}

// Deprecated: Please use UpgradeInstance instead.
// MutateInstance Upgrades a Linode to its next generation.
func (c *Client) MutateInstance(ctx context.Context, id int) error {
return c.simpleInstanceAction(ctx, "mutate", id)
}

// InstanceUpgradeOptions is a struct representing the options for upgrading a Linode
type InstanceUpgradeOptions struct {
// Automatically resize disks when resizing a Linode.
// When resizing down to a smaller plan your Linode's data must fit within the smaller disk size.
AllowAutoDiskResize bool `json:"allow_auto_disk_resize"`
}

// UpgradeInstance upgrades a Linode to its next generation.
func (c *Client) UpgradeInstance(ctx context.Context, linodeID int, opts InstanceUpgradeOptions) error {
e := formatAPIPath("linode/instances/%d/mutate", linodeID)
_, err := doPOSTRequest[Instance](ctx, c, e, opts)
return err
}

// MigrateInstance - Migrate an instance
func (c *Client) MigrateInstance(ctx context.Context, linodeID int, opts InstanceMigrateOptions) error {
e := formatAPIPath("linode/instances/%d/migrate", linodeID)
Expand Down
10 changes: 6 additions & 4 deletions lke_clusters_control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type LKEClusterControlPlaneACLAddresses struct {
// for an LKE cluster's control plane.
// NOTE: Control Plane ACLs may not currently be available to all users.
type LKEClusterControlPlaneACL struct {
Enabled bool `json:"enabled"`
Addresses *LKEClusterControlPlaneACLAddresses `json:"addresses"`
Enabled bool `json:"enabled"`
Addresses *LKEClusterControlPlaneACLAddresses `json:"addresses"`
RevisionID string `json:"revision_id,omitempty"`
}

// LKEClusterControlPlaneACLAddressesOptions are the options used to
Expand All @@ -33,8 +34,9 @@ type LKEClusterControlPlaneACLAddressesOptions struct {
// configuring an LKE cluster's control plane ACL policy.
// NOTE: Control Plane ACLs may not currently be available to all users.
type LKEClusterControlPlaneACLOptions struct {
Enabled *bool `json:"enabled,omitempty"`
Addresses *LKEClusterControlPlaneACLAddressesOptions `json:"addresses,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Addresses *LKEClusterControlPlaneACLAddressesOptions `json:"addresses,omitempty"`
RevisionID string `json:"revision_id"`
}

// LKEClusterControlPlaneOptions represents the options used when
Expand Down
Loading

0 comments on commit f1ff0b9

Please sign in to comment.