From 69e7c1aa2227abf7762701d4e1b089845e5c322e Mon Sep 17 00:00:00 2001 From: Lena Garber Date: Mon, 8 Jul 2024 15:44:15 -0400 Subject: [PATCH] Placement Group affinity_type -> placement_group_type; is_strict -> placement_group_strictness --- go.work.sum | 26 +++++++++++++ instances.go | 8 ++-- placement_groups.go | 37 ++++++++++++------- .../fixtures/TestInstance_withPG.yaml | 8 ++-- .../TestPlacementGroup_assignment.yaml | 12 +++--- .../fixtures/TestPlacementGroup_basic.yaml | 10 ++--- test/integration/instances_test.go | 4 +- test/integration/main_test.go | 3 +- test/integration/placement_group_test.go | 16 ++++---- 9 files changed, 80 insertions(+), 44 deletions(-) diff --git a/go.work.sum b/go.work.sum index a8adae439..6c1d40342 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,20 +1,46 @@ +cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc= cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= +github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46 h1:lsxEuwrXEAokXB9qhlbKWPpo3KMLZQ5WB5WLQRW1uq0= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= +github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w= +github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= +github.com/kisielk/errcheck v1.5.0 h1:e8esj/e4R+SAOwFwN+n3zr0nYeCyeweozKfO23MvHzY= +github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= +github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= +github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8= github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 h1:8Q0qkMVC/MmWkpIdlvZgcv2o2jrlF6zqVOh7W5YHdMA= +github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= +github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 h1:pWEwq4Asjm4vjW7vcsmijwBhOr1/shsbSYiWXmNGlks= k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= diff --git a/instances.go b/instances.go index 086442f14..7d1044b20 100644 --- a/instances.go +++ b/instances.go @@ -108,10 +108,10 @@ type InstanceTransfer struct { // InstancePlacementGroup represents information about the placement group // this Linode is a part of. type InstancePlacementGroup struct { - ID int `json:"id"` - Label string `json:"label"` - AffinityType PlacementGroupAffinityType `json:"affinity_type"` - IsStrict bool `json:"is_strict"` + ID int `json:"id"` + Label string `json:"label"` + PlacementGroupType PlacementGroupType `json:"placement_group_type"` + PlacementGroupPolicy PlacementGroupPolicy `json:"placement_group_policy"` } // InstanceMetadataOptions specifies various Instance creation fields diff --git a/placement_groups.go b/placement_groups.go index 3987adca9..49e92584a 100644 --- a/placement_groups.go +++ b/placement_groups.go @@ -2,12 +2,21 @@ package linodego import "context" -// PlacementGroupAffinityType is an enum that determines the affinity policy +// PlacementGroupType is an enum that determines the affinity policy // for Linodes in a placement group. -type PlacementGroupAffinityType string +type PlacementGroupType string const ( - AffinityTypeAntiAffinityLocal PlacementGroupAffinityType = "anti_affinity:local" + PlacementGroupTypeAntiAffinityLocal PlacementGroupType = "anti_affinity:local" +) + +// PlacementGroupPolicy is an enum for the policy that determines whether a +// Linode can be assigned to a Placement Group. +type PlacementGroupPolicy string + +const ( + PlacementGroupPolicyStrict PlacementGroupPolicy = "strict" + PlacementGroupPolicyFlexible PlacementGroupPolicy = "flexible" ) // PlacementGroupMember represents a single Linode assigned to a @@ -20,22 +29,22 @@ type PlacementGroupMember struct { // PlacementGroup represents a Linode placement group. // NOTE: Placement Groups may not currently be available to all users. type PlacementGroup struct { - ID int `json:"id"` - Label string `json:"label"` - Region string `json:"region"` - AffinityType PlacementGroupAffinityType `json:"affinity_type"` - IsCompliant bool `json:"is_compliant"` - IsStrict bool `json:"is_strict"` - Members []PlacementGroupMember `json:"members"` + ID int `json:"id"` + Label string `json:"label"` + Region string `json:"region"` + PlacementGroupType PlacementGroupType `json:"placement_group_type"` + PlacementGroupPolicy PlacementGroupPolicy `json:"placement_group_policy"` + IsCompliant bool `json:"is_compliant"` + Members []PlacementGroupMember `json:"members"` } // PlacementGroupCreateOptions represents the options to use // when creating a placement group. type PlacementGroupCreateOptions struct { - Label string `json:"label"` - Region string `json:"region"` - AffinityType PlacementGroupAffinityType `json:"affinity_type"` - IsStrict bool `json:"is_strict"` + Label string `json:"label"` + Region string `json:"region"` + PlacementGroupType PlacementGroupType `json:"placement_group_type"` + PlacementGroupPolicy PlacementGroupPolicy `json:"placement_group_policy"` } // PlacementGroupUpdateOptions represents the options to use diff --git a/test/integration/fixtures/TestInstance_withPG.yaml b/test/integration/fixtures/TestInstance_withPG.yaml index 62b69821c..5b7c70051 100644 --- a/test/integration/fixtures/TestInstance_withPG.yaml +++ b/test/integration/fixtures/TestInstance_withPG.yaml @@ -317,7 +317,7 @@ interactions: code: 200 duration: "" - request: - body: '{"label":"linodego-test-1719609233973734000","region":"us-ord","affinity_type":"anti_affinity:local","is_strict":false}' + body: '{"label":"linodego-test-1719609233973734000","region":"us-ord","placement_group_type":"anti_affinity:local","placement_group_policy":"flexible"}' form: {} headers: Accept: @@ -330,7 +330,7 @@ interactions: method: POST response: body: '{"id": 1288, "label": "linodego-test-1719609233973734000", "region": "us-ord", - "affinity_type": "anti_affinity:local", "is_strict": false, "is_compliant": + "placement_group_type": "anti_affinity:local", "placement_group_policy": "flexible", "is_compliant": true, "members": []}' headers: Access-Control-Allow-Credentials: @@ -399,8 +399,8 @@ interactions: true, "available": false, "schedule": {"day": null, "window": null}, "last_successful": null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": [], "host_uuid": "a4dde4a930ee064d67f6ba03753d2aec98b0e75b", "has_user_data": false, "placement_group": - {"id": 1288, "label": "linodego-test-1719609233973734000", "affinity_type": - "anti_affinity:local", "is_strict": false}, "lke_cluster_id": null}' + {"id": 1288, "label": "linodego-test-1719609233973734000", "placement_group_type": + "anti_affinity:local", "placement_group_policy": "flexible"}, "lke_cluster_id": null}' headers: Access-Control-Allow-Credentials: - "true" diff --git a/test/integration/fixtures/TestPlacementGroup_assignment.yaml b/test/integration/fixtures/TestPlacementGroup_assignment.yaml index 449cbc77a..055e3e708 100644 --- a/test/integration/fixtures/TestPlacementGroup_assignment.yaml +++ b/test/integration/fixtures/TestPlacementGroup_assignment.yaml @@ -124,7 +124,7 @@ interactions: code: 200 duration: "" - request: - body: '{"label":"linodego-test-1718722972576732000","region":"us-east","affinity_type":"anti_affinity:local","is_strict":false}' + body: '{"label":"linodego-test-1718722972576732000","region":"us-east","placement_group_type":"anti_affinity:local","placement_group_policy":"flexible"}' form: {} headers: Accept: @@ -137,7 +137,7 @@ interactions: method: POST response: body: '{"id": 4020, "label": "linodego-test-1718722972576732000", "region": "us-east", - "affinity_type": "anti_affinity:local", "is_strict": false, "is_compliant": + "placement_group_type": "anti_affinity:local", "placement_group_policy": "flexible", "is_compliant": true, "members": []}' headers: Access-Control-Allow-Credentials: @@ -257,7 +257,7 @@ interactions: method: POST response: body: '{"id": 4020, "label": "linodego-test-1718722972576732000", "region": "us-east", - "affinity_type": "anti_affinity:local", "is_strict": false, "is_compliant": + "placement_group_type": "anti_affinity:local", "placement_group_policy": "flexible", "is_compliant": true, "members": [{"linode_id": 25195349, "is_compliant": true}]}' headers: Access-Control-Allow-Credentials: @@ -322,8 +322,8 @@ interactions: false, "available": false, "schedule": {"day": null, "window": null}, "last_successful": null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": [], "host_uuid": "53257e56e7692e143036a5fbf7daaf92b5350bf3", "has_user_data": false, "placement_group": - {"id": 4020, "label": "linodego-test-1718722972576732000", "affinity_type": - "anti_affinity:local", "is_strict": false}, "disk_encryption": "enabled", "lke_cluster_id": + {"id": 4020, "label": "linodego-test-1718722972576732000", "placement_group_type": + "anti_affinity:local", "placement_group_policy": "flexible"}, "disk_encryption": "enabled", "lke_cluster_id": null}' headers: Access-Control-Allow-Credentials: @@ -381,7 +381,7 @@ interactions: method: POST response: body: '{"id": 4020, "label": "linodego-test-1718722972576732000", "region": "us-east", - "affinity_type": "anti_affinity:local", "is_strict": false, "is_compliant": + "placement_group_type": "anti_affinity:local", "placement_group_policy": "flexible", "is_compliant": true, "members": []}' headers: Access-Control-Allow-Credentials: diff --git a/test/integration/fixtures/TestPlacementGroup_basic.yaml b/test/integration/fixtures/TestPlacementGroup_basic.yaml index 28a50ca90..e236a0c35 100644 --- a/test/integration/fixtures/TestPlacementGroup_basic.yaml +++ b/test/integration/fixtures/TestPlacementGroup_basic.yaml @@ -119,7 +119,7 @@ interactions: code: 200 duration: "" - request: - body: '{"label":"linodego-test-1712862362503240000","region":"eu-west","affinity_type":"anti_affinity:local","is_strict":false}' + body: '{"label":"linodego-test-1712862362503240000","region":"eu-west","placement_group_type":"anti_affinity:local","placement_group_policy": "flexible"}' form: {} headers: Accept: @@ -132,7 +132,7 @@ interactions: method: POST response: body: '{"id": 351, "label": "linodego-test-1712862362503240000", "region": "eu-west", - "affinity_type": "anti_affinity:local", "is_strict": false, "is_compliant": + "placement_group_type": "anti_affinity:local", "placement_group_policy": "flexible", "is_compliant": true, "members": []}' headers: Access-Control-Allow-Credentials: @@ -191,7 +191,7 @@ interactions: method: PUT response: body: '{"id": 351, "label": "linodego-test-1712862362503240000-updated", "region": - "eu-west", "affinity_type": "anti_affinity:local", "is_strict": false, "is_compliant": + "eu-west", "placement_group_type": "anti_affinity:local", "placement_group_policy": "flexible", "is_compliant": true, "members": []}' headers: Access-Control-Allow-Credentials: @@ -250,7 +250,7 @@ interactions: method: GET response: body: '{"id": 351, "label": "linodego-test-1712862362503240000-updated", "region": - "eu-west", "affinity_type": "anti_affinity:local", "is_strict": false, "is_compliant": + "eu-west", "placement_group_type": "anti_affinity:local", "placement_group_policy": "flexible", "is_compliant": true, "members": []}' headers: Access-Control-Allow-Credentials: @@ -313,7 +313,7 @@ interactions: method: GET response: body: '{"data": [{"id": 351, "label": "linodego-test-1712862362503240000-updated", - "region": "eu-west", "affinity_type": "anti_affinity:local", "is_strict": false, + "region": "eu-west", "placement_group_type": "anti_affinity:local", "placement_group_policy": "flexible", "is_compliant": true, "members": []}], "page": 1, "pages": 1, "results": 1}' headers: Access-Control-Allow-Credentials: diff --git a/test/integration/instances_test.go b/test/integration/instances_test.go index bb88015b5..35f59d61f 100644 --- a/test/integration/instances_test.go +++ b/test/integration/instances_test.go @@ -507,8 +507,8 @@ func TestInstance_withPG(t *testing.T) { require.NotNil(t, inst.PlacementGroup) require.Equal(t, inst.PlacementGroup.ID, pg.ID) require.Equal(t, inst.PlacementGroup.Label, pg.Label) - require.Equal(t, inst.PlacementGroup.AffinityType, pg.AffinityType) - require.Equal(t, inst.PlacementGroup.IsStrict, pg.IsStrict) + require.Equal(t, inst.PlacementGroup.PlacementGroupType, pg.PlacementGroupType) + require.Equal(t, inst.PlacementGroup.PlacementGroupPolicy, pg.PlacementGroupPolicy) } func createInstance(t *testing.T, client *linodego.Client, enableCloudFirewall bool, modifiers ...instanceModifier) (*linodego.Instance, error) { diff --git a/test/integration/main_test.go b/test/integration/main_test.go index 9f23c9c88..8596e5dd8 100644 --- a/test/integration/main_test.go +++ b/test/integration/main_test.go @@ -3,13 +3,14 @@ package integration import ( "context" "fmt" - "github.com/linode/linodego" "io" "log" "net/http" "os" "testing" "time" + + "github.com/linode/linodego" ) var ( diff --git a/test/integration/placement_group_test.go b/test/integration/placement_group_test.go index 7507f77ff..98e133417 100644 --- a/test/integration/placement_group_test.go +++ b/test/integration/placement_group_test.go @@ -28,8 +28,8 @@ func TestPlacementGroup_basic(t *testing.T) { require.NotEqual(t, pg.ID, 0) require.Contains(t, pg.Label, "linodego-test-") require.NotEmpty(t, pg.Label) - require.Equal(t, pg.AffinityType, linodego.AffinityTypeAntiAffinityLocal) - require.Equal(t, pg.IsStrict, false) + require.Equal(t, pg.PlacementGroupType, linodego.PlacementGroupTypeAntiAffinityLocal) + require.Equal(t, pg.PlacementGroupPolicy, linodego.PlacementGroupPolicyFlexible) require.Len(t, pg.Members, 0) updatedLabel := pg.Label + "-updated" @@ -97,8 +97,8 @@ func TestPlacementGroup_assignment(t *testing.T) { require.NotNil(t, inst.PlacementGroup) require.Equal(t, inst.PlacementGroup.ID, pg.ID) require.Equal(t, inst.PlacementGroup.Label, pg.Label) - require.Equal(t, inst.PlacementGroup.IsStrict, pg.IsStrict) - require.Equal(t, inst.PlacementGroup.AffinityType, pg.AffinityType) + require.Equal(t, inst.PlacementGroup.PlacementGroupPolicy, pg.PlacementGroupPolicy) + require.Equal(t, inst.PlacementGroup.PlacementGroupType, pg.PlacementGroupType) // Ensure unassignment works as expected pg, err = client.UnassignPlacementGroupLinodes( @@ -121,10 +121,10 @@ func createPlacementGroup( ) (*linodego.PlacementGroup, func(), error) { t.Helper() createOpts := linodego.PlacementGroupCreateOptions{ - Label: "linodego-test-" + getUniqueText(), - Region: getRegionsWithCaps(t, client, []string{"Placement Group"})[0], - AffinityType: linodego.AffinityTypeAntiAffinityLocal, - IsStrict: false, + Label: "linodego-test-" + getUniqueText(), + Region: getRegionsWithCaps(t, client, []string{"Placement Group"})[0], + PlacementGroupType: linodego.PlacementGroupTypeAntiAffinityLocal, + PlacementGroupPolicy: linodego.PlacementGroupPolicyFlexible, } for _, mod := range pgModifier {