Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [BREAKING] Treat ip_ranges as a pointer in config interface update options #464

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions instance_config_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ type InstanceConfigInterfaceCreateOptions struct {
}

type InstanceConfigInterfaceUpdateOptions struct {
Primary bool `json:"primary,omitempty"`
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
IPRanges []string `json:"ip_ranges,omitempty"`
Primary bool `json:"primary,omitempty"`
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
IPRanges *[]string `json:"ip_ranges,omitempty"`
}

type InstanceConfigInterfacesReorderOptions struct {
Expand Down Expand Up @@ -91,8 +91,13 @@ func (i InstanceConfigInterface) GetUpdateOptions() InstanceConfigInterfaceUpdat
}
}

if len(i.IPRanges) > 0 {
opts.IPRanges = i.IPRanges
if i.IPRanges != nil {
// Copy the slice to prevent accidental
// mutations
copiedIPRanges := make([]string, len(i.IPRanges))
copy(copiedIPRanges, i.IPRanges)

opts.IPRanges = &copiedIPRanges
}

return opts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Wed, 14 Feb 2024 18:09:14 GMT
- Mon, 04 Mar 2024 20:22:16 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand All @@ -254,7 +254,7 @@ interactions:
code: 200
duration: ""
- request:
body: '{"region":"us-iad","type":"g6-nanode-1","label":"go-test-ins-wo-disk-73be3u8uqn82","booted":false}'
body: '{"region":"us-iad","type":"g6-nanode-1","label":"go-test-ins-wo-disk-o27gv95tu35t","booted":false}'
form: {}
headers:
Accept:
Expand All @@ -266,15 +266,15 @@ interactions:
url: https://api.linode.com/v4beta/linode/instances
method: POST
response:
body: '{"id": 54933555, "label": "go-test-ins-wo-disk-73be3u8uqn82", "group":
body: '{"id": 55633797, "label": "go-test-ins-wo-disk-o27gv95tu35t", "group":
"", "status": "provisioning", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05",
"type": "g6-nanode-1", "ipv4": ["139.144.202.63"], "ipv6": "1234::5678/128",
"type": "g6-nanode-1", "ipv4": ["172.233.196.252"], "ipv6": "1234::5678/128",
"image": null, "region": "us-iad", "specs": {"disk": 25600, "memory": 1024,
"vcpus": 1, "gpus": 0, "transfer": 1000}, "alerts": {"cpu": 90, "network_in":
10, "network_out": 10, "transfer_quota": 80, "io": 10000}, "backups": {"enabled":
false, "available": false, "schedule": {"day": null, "window": null}, "last_successful":
null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": [], "host_uuid":
"069a01c443a4c034edaff10aeecdf8fb95ec66ba", "has_user_data": false}'
"bf7a891314cca054680070d406f60283ad2477aa", "has_user_data": false}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -291,13 +291,13 @@ interactions:
Connection:
- keep-alive
Content-Length:
- "737"
- "738"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Wed, 14 Feb 2024 18:09:15 GMT
- Mon, 04 Mar 2024 20:22:16 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand All @@ -321,7 +321,7 @@ interactions:
code: 200
duration: ""
- request:
body: '{"label":"go-test-conf-9iut07dbo832","devices":{},"interfaces":null}'
body: '{"label":"go-test-conf-tes2d3k1745m","devices":{},"interfaces":null}'
form: {}
headers:
Accept:
Expand All @@ -330,10 +330,10 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/54933555/configs
url: https://api.linode.com/v4beta/linode/instances/55633797/configs
method: POST
response:
body: '{"id": 58037972, "label": "go-test-conf-9iut07dbo832", "helpers": {"updatedb_disabled":
body: '{"id": 58758984, "label": "go-test-conf-tes2d3k1745m", "helpers": {"updatedb_disabled":
true, "distro": true, "modules_dep": true, "network": true, "devtmpfs_automount":
true}, "kernel": "linode/latest-64bit", "comments": "", "memory_limit": 0, "created":
"2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "root_device": "/dev/sda",
Expand Down Expand Up @@ -362,7 +362,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Wed, 14 Feb 2024 18:09:15 GMT
- Mon, 04 Mar 2024 20:22:16 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand All @@ -386,7 +386,7 @@ interactions:
code: 200
duration: ""
- request:
body: '{"label":"go-test-vpc-1707934155274221000","region":"us-iad","subnets":[{"label":"linodego-vpc-test-1707934155274261000","ipv4":"192.168.0.0/25"}]}'
body: '{"label":"go-test-vpc-1709583736746076000","region":"us-iad","subnets":[{"label":"linodego-vpc-test-1709583736746145000","ipv4":"192.168.0.0/25"}]}'
form: {}
headers:
Accept:
Expand All @@ -398,8 +398,8 @@ interactions:
url: https://api.linode.com/v4beta/vpcs
method: POST
response:
body: '{"id": 22685, "label": "go-test-vpc-1707934155274221000", "description":
"", "region": "us-iad", "subnets": [{"id": 23564, "label": "linodego-vpc-test-1707934155274261000",
body: '{"id": 26498, "label": "go-test-vpc-1709583736746076000", "description":
"", "region": "us-iad", "subnets": [{"id": 26749, "label": "linodego-vpc-test-1709583736746145000",
"ipv4": "192.168.0.0/25", "ipv6": null, "linodes": [], "created": "2018-01-02T03:04:05",
"updated": "2018-01-02T03:04:05"}], "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05"}'
Expand All @@ -425,7 +425,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Wed, 14 Feb 2024 18:09:15 GMT
- Mon, 04 Mar 2024 20:22:17 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand All @@ -449,7 +449,7 @@ interactions:
code: 200
duration: ""
- request:
body: '{"purpose":"vpc","subnet_id":23564}'
body: '{"purpose":"vpc","subnet_id":26749,"ip_ranges":["192.168.0.5/32"]}'
form: {}
headers:
Accept:
Expand All @@ -458,12 +458,12 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/54933555/configs/58037972/interfaces
url: https://api.linode.com/v4beta/linode/instances/55633797/configs/58758984/interfaces
method: POST
response:
body: '{"id": 1041200, "purpose": "vpc", "primary": false, "active": false, "ipam_address":
null, "label": null, "vpc_id": 22685, "subnet_id": 23564, "ipv4": {"vpc": "192.168.0.2",
"nat_1_1": null}, "ipv6": null, "ip_ranges": []}'
body: '{"id": 1149865, "purpose": "vpc", "primary": false, "active": false, "ipam_address":
null, "label": null, "vpc_id": 26498, "subnet_id": 26749, "ipv4": {"vpc": "192.168.0.2",
"nat_1_1": null}, "ipv6": null, "ip_ranges": ["192.168.0.5/32"]}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -480,13 +480,13 @@ interactions:
Connection:
- keep-alive
Content-Length:
- "222"
- "238"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Wed, 14 Feb 2024 18:09:15 GMT
- Mon, 04 Mar 2024 20:22:17 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand All @@ -510,7 +510,7 @@ interactions:
code: 200
duration: ""
- request:
body: '{"primary":true,"ipv4":{"vpc":"192.168.0.2"}}'
body: '{"primary":true,"ipv4":{"vpc":"192.168.0.2"},"ip_ranges":["192.168.0.5/32"]}'
form: {}
headers:
Accept:
Expand All @@ -519,12 +519,12 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/54933555/configs/58037972/interfaces/1041200
url: https://api.linode.com/v4beta/linode/instances/55633797/configs/58758984/interfaces/1149865
method: PUT
response:
body: '{"id": 1041200, "purpose": "vpc", "primary": true, "active": false, "ipam_address":
null, "label": null, "vpc_id": 22685, "subnet_id": 23564, "ipv4": {"vpc": "192.168.0.2",
"nat_1_1": null}, "ipv6": null, "ip_ranges": []}'
body: '{"id": 1149865, "purpose": "vpc", "primary": true, "active": false, "ipam_address":
null, "label": null, "vpc_id": 26498, "subnet_id": 26749, "ipv4": {"vpc": "192.168.0.2",
"nat_1_1": null}, "ipv6": null, "ip_ranges": ["192.168.0.5/32"]}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -541,13 +541,13 @@ interactions:
Connection:
- keep-alive
Content-Length:
- "221"
- "237"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Wed, 14 Feb 2024 18:09:15 GMT
- Mon, 04 Mar 2024 20:22:17 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand All @@ -571,7 +571,7 @@ interactions:
code: 200
duration: ""
- request:
body: '{"primary":true,"ipv4":{"vpc":"192.168.0.10","nat_1_1":"any"}}'
body: '{"primary":true,"ipv4":{"vpc":"192.168.0.10","nat_1_1":"any"},"ip_ranges":[]}'
form: {}
headers:
Accept:
Expand All @@ -580,12 +580,12 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/54933555/configs/58037972/interfaces/1041200
url: https://api.linode.com/v4beta/linode/instances/55633797/configs/58758984/interfaces/1149865
method: PUT
response:
body: '{"id": 1041200, "purpose": "vpc", "primary": true, "active": false, "ipam_address":
null, "label": null, "vpc_id": 22685, "subnet_id": 23564, "ipv4": {"vpc": "192.168.0.10",
"nat_1_1": "139.144.202.63"}, "ipv6": null, "ip_ranges": []}'
body: '{"id": 1149865, "purpose": "vpc", "primary": true, "active": false, "ipam_address":
null, "label": null, "vpc_id": 26498, "subnet_id": 26749, "ipv4": {"vpc": "192.168.0.10",
"nat_1_1": "172.233.196.252"}, "ipv6": null, "ip_ranges": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -602,13 +602,13 @@ interactions:
Connection:
- keep-alive
Content-Length:
- "234"
- "235"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Wed, 14 Feb 2024 18:09:16 GMT
- Mon, 04 Mar 2024 20:22:17 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down Expand Up @@ -641,7 +641,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/54933555
url: https://api.linode.com/v4beta/linode/instances/55633797
method: DELETE
response:
body: '{}'
Expand All @@ -667,7 +667,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Wed, 14 Feb 2024 18:09:16 GMT
- Mon, 04 Mar 2024 20:22:18 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down Expand Up @@ -700,7 +700,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/vpcs/22685
url: https://api.linode.com/v4beta/vpcs/26498
method: DELETE
response:
body: '{}'
Expand All @@ -726,7 +726,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Wed, 14 Feb 2024 18:09:17 GMT
- Mon, 04 Mar 2024 20:22:18 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down
13 changes: 12 additions & 1 deletion test/integration/instance_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func TestInstance_ConfigInterface_Update(t *testing.T) {
InstanceConfigInterfaceCreateOptions{
Purpose: InterfacePurposeVPC,
SubnetID: &vpcSubnet.ID,
IPRanges: []string{"192.168.0.5/32"},
},
)
if err != nil {
Expand All @@ -371,11 +372,18 @@ func TestInstance_ConfigInterface_Update(t *testing.T) {
if !(updatedIntfc.Primary == updateOpts.Primary) {
t.Errorf("updating interface %v didn't succeed", intfc.ID)
}

if updatedIntfc.IPRanges[0] != "192.168.0.5/32" {
t.Errorf("unexpected value for IPRanges: %s", updatedIntfc.IPRanges[0])
}

NAT1To1Any := "any"
updateOpts.IPv4 = &VPCIPv4{
VPC: "192.168.0.10",
NAT1To1: &NAT1To1Any,
}
newIPRanges := make([]string, 0)
updateOpts.IPRanges = &newIPRanges

updatedIntfc, err = client.UpdateInstanceConfigInterface(
context.Background(),
Expand All @@ -384,7 +392,6 @@ func TestInstance_ConfigInterface_Update(t *testing.T) {
intfc.ID,
updateOpts,
)

if err != nil {
t.Errorf("an error occurs when updating an interface in config %v", config.ID)
}
Expand All @@ -393,6 +400,10 @@ func TestInstance_ConfigInterface_Update(t *testing.T) {
updateOpts.IPv4.VPC == updatedIntfc.IPv4.VPC) {
t.Errorf("updating interface %v didn't succeed", intfc.ID)
}

if len(updatedIntfc.IPRanges) > 0 {
t.Errorf("expected IPRanges to be empty, got %d entries", len(updatedIntfc.IPRanges))
}
}

func TestInstance_Configs_List(t *testing.T) {
Expand Down