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

[Bug]: unable to empty ip_ranges for VPC interface once set #462

Closed
rahulait opened this issue Mar 2, 2024 · 1 comment · Fixed by #464
Closed

[Bug]: unable to empty ip_ranges for VPC interface once set #462

rahulait opened this issue Mar 2, 2024 · 1 comment · Fixed by #464

Comments

@rahulait
Copy link

rahulait commented Mar 2, 2024

go Version

go version go1.21.7 linux/amd64

API Wrapper Version

github.com/linode/linodego v1.29.0

Code Snippet

package main

import (
	"context"
	"fmt"

	"github.com/linode/linodego"
	"golang.org/x/oauth2"

	"log"
	"net/http"
	"os"
)

func main() {
	apiKey, ok := os.LookupEnv("LINODE_TOKEN")
	if !ok {
		log.Fatal("Could not find LINODE_TOKEN, please assert it is set.")
	}
	tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: apiKey})

	oauth2Client := &http.Client{
		Transport: &oauth2.Transport{
			Source: tokenSource,
		},
	}

	linodeClient := linodego.NewClient(oauth2Client)
	linodeClient.SetDebug(true)

	// Get instance configs
	instance, _ := linodeClient.GetInstance(context.Background(), 55519453)
	configs, err := linodeClient.ListInstanceConfigs(context.Background(), instance.ID, &linodego.ListOptions{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%v", configs[0].Interfaces)

	// Try clearing ip_ranges
	interfaceUpdateOptions := linodego.InstanceConfigInterfaceUpdateOptions{
		IPRanges: []string{},
	}

	// Set empty ip_ranges for VPC interface
	for _, iface := range configs[0].Interfaces {
		if iface.VPCID != nil && iface.IPv4.VPC != "" {
			resp, err := linodeClient.UpdateInstanceConfigInterface(context.Background(), instance.ID, configs[0].ID, iface.ID, interfaceUpdateOptions)
			if err != nil {
				log.Fatal(err)
			}
			fmt.Printf("Deleted routes. New output: %v", resp)
			if len(resp.IPRanges) > 0 {
				log.Printf("\nFailed to empty ip_ranges")
			}
		}
	}
}

Expected Behavior

ip_ranges should be set to empty:

{
   "ip_ranges": []
}

Actual Behavior

ip_ranges of interface connected to VPC never gets cleared.

Output sample:

Initial instance state:

==============================================================================
2024/03/02 05:23:05.324915 DEBUG RESTY 
==============================================================================
~~~ REQUEST ~~~
GET  /v4/linode/instances/55519453/configs  HTTP/1.1
HOST   : api.linode.com
HEADERS:
        Accept: application/json
        Content-Type: application/json
        User-Agent: linodego/v1.29.0 https://github.com/linode/linodego
BODY   :
***** NO CONTENT *****
------------------------------------------------------------------------------
~~~ RESPONSE ~~~
STATUS       : 200 OK
PROTO        : HTTP/1.1
RECEIVED AT  : 2024-03-02T05:23:05.324753224Z
TIME DURATION: 126.797914ms
BODY         :
{
   "data": [
      {
         "id": 58641324,
         "label": "My Ubuntu 22.04 LTS Disk Profile",
         "helpers": {
            "updatedb_disabled": true,
            "distro": true,
            "modules_dep": true,
            "network": true,
            "devtmpfs_automount": true
         },
         "kernel": "linode/grub2",
         "comments": "",
         "memory_limit": 0,
         "created": "2024-03-01T19:14:27",
         "updated": "2024-03-01T19:14:27",
         "root_device": "/dev/sda",
         "devices": {
            "sda": {
               "disk_id": 109845040,
               "volume_id": null
            },
            "sdb": {
               "disk_id": 109845041,
               "volume_id": null
            },
            "sdc": null,
            "sdd": null,
            "sde": null,
            "sdf": null,
            "sdg": null,
            "sdh": null
         },
         "initrd": null,
         "run_level": "default",
         "virt_mode": "paravirt",
         "interfaces": [
            {
               "id": 1137088,
               "purpose": "public",
               "primary": true,
               "active": true,
               "ipam_address": null,
               "label": null,
               "vpc_id": null,
               "subnet_id": null,
               "ipv4": null,
               "ipv6": null,
               "ip_ranges": null
            },
            {
               "id": 1137089,
               "purpose": "vpc",
               "primary": false,
               "active": true,
               "ipam_address": null,
               "label": null,
               "vpc_id": 26186,
               "subnet_id": 26443,
               "ipv4": {
                  "vpc": "10.0.0.5",
                  "nat_1_1": null
               },
               "ipv6": null,
               "ip_ranges": [
                  "10.192.3.0/24"
               ]
            }
         ]
      }
   ],
   "page": 1,
   "pages": 1,
   "results": 1
}

Logs of request sent to set ip_ranges to empty:

==============================================================================
~~~ REQUEST ~~~
PUT  /v4/linode/instances/55519453/configs/58641324/interfaces/1137089  HTTP/1.1
HOST   : api.linode.com
HEADERS:
        Accept: application/json
        Content-Type: application/json
        User-Agent: linodego/v1.29.0 https://github.com/linode/linodego
BODY   :
{}
------------------------------------------------------------------------------
~~~ RESPONSE ~~~
STATUS       : 200 OK
PROTO        : HTTP/1.1
RECEIVED AT  : 2024-03-02T05:23:05.495718273Z
TIME DURATION: 170.160593ms
BODY         :
{
   "id": 1137089,
   "purpose": "vpc",
   "primary": false,
   "active": true,
   "ipam_address": null,
   "label": null,
   "vpc_id": 26186,
   "subnet_id": 26443,
   "ipv4": {
      "vpc": "10.0.0.5",
      "nat_1_1": null
   },
   "ipv6": null,
   "ip_ranges": [
      "10.192.3.0/24"
   ]
}

Ideally, in the end when we call linodeClient.UpdateInstanceConfigInterface() with empty ip_ranges, it should have set ip_ranges to empty and response should not contain ip_ranges still set.

I can delete an item from ip_ranges if there are more than 1 entries, its just that I am unable to set it to empty.

Steps to Reproduce

  1. Bring up a linode in VPC.
  2. Try setting ip_ranges for the VPC interface.
  3. Once set, try clearing the ip_ranges.

If one has a linode in VPC, they can use the above script to reproduce the issue. Just change the instance id with your instance id and set atleast one ip subnet in ip_ranges.

@rahulait rahulait added the bug label Mar 2, 2024
@rahulait rahulait changed the title [Bug]: unable to set ip_ranges to empty of VPC interface once set [Bug]: unable to empty ip_ranges for VPC interface once set Mar 2, 2024
@lgarber-akamai
Copy link
Contributor

Thank you for the bug report!

It looks like omitempty is excluding explicitly empty list values from the interface update request body.

I've created a ticket in our internal tracker to correct this functionality and will let you know once it's been resolved 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants