linode / linodego

Go client for Linode REST v4 API
MIT License
138 stars 81 forks source link

ref: PG affinity_type -> placement_group_type; is_strict -> placement_group_policy #546

Closed lgarber-akamai closed 3 months ago

lgarber-akamai commented 3 months ago

📝 Description

This pull request implements the following upcoming breaking changes for the VM Placement GA:

NOTE: We will need communication around this breaking change in the release notes.

✔️ How to Test

The following test steps assume you have pulled down this PR locally and have pointed your local environment at an API instance where PGs are available:

export LINODE_URL=...
export LINODE_TOKEN=...

Integration Testing

make ARGS="-run TestPlacementGroup TestInstance_withPG" fixtures

Manual Testing

  1. In a linodego sandbox environment (e.g. dx-devenv), run the following:
package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/linode/linodego"
)

const targetRegion = "eu-west"

func main() {
    ctx := context.Background()

    client := linodego.NewClient(nil)
    client.SetToken(os.Getenv("LINODE_TOKEN"))

    // Create a PG
    pg, err := client.CreatePlacementGroup(ctx, linodego.PlacementGroupCreateOptions{
        Label:                "test-pg",
        Region:               targetRegion,
        PlacementGroupType:   linodego.PlacementGroupTypeAntiAffinityLocal,
        PlacementGroupPolicy: linodego.PlacementGroupPolicyStrict,
    })
    if err != nil {
        log.Fatal(err)
    }

    // Provision two instances assigned to the PG
    compliantOnly := true

    for i := 0; i < 2; i++ {
        _, err := client.CreateInstance(ctx, linodego.InstanceCreateOptions{
            Region: targetRegion,
            Type:   "g6-nanode-1",
            Label:  fmt.Sprintf("test-instance-%d", i),
            PlacementGroup: &linodego.InstanceCreatePlacementGroupOptions{
                ID:            pg.ID,
                CompliantOnly: &compliantOnly,
            },
        })
        if err != nil {
            log.Fatal(err)
        }
    }
}
  1. Navigate to Cloud Manager and ensure a new Placement Group has been created with two instances assigned to it.
  2. Modify this code with update logic, assignment logic, etc.
  3. Re-run the file and ensure everything works as expected.