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

Add support for NodeBalancers UDP #630

Open
wants to merge 9 commits into
base: proj/nb-udp
Choose a base branch
from

Conversation

lgarber-akamai
Copy link
Contributor

@lgarber-akamai lgarber-akamai commented Nov 22, 2024

📝 Description

This pull request adds support for UDP NodeBalancer configs as well as the corresponding tests.

✔️ How to Test

The following test steps assume you have pulled down this PR locally.

NOTE: See the comments of TPT-3375 for instructions on configuring your account for UDP NodeBalancers.

Unit Testing

make testunit

Integration Testing

make ARGS="-run TestNodeBalancer" fixtures

Manual Testing

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

import (
	"context"
	"log"
	"os"

	"github.com/linode/linodego"

	"github.com/davecgh/go-spew/spew"
)

func main() {
	client := linodego.NewClient(nil)
	client.SetToken(os.Getenv("LINODE_TOKEN"))
	client.SetAPIVersion("v4beta")

	nodebalancer, err := client.CreateNodeBalancer(
		context.Background(),
		linodego.NodeBalancerCreateOptions{
			Label:              linodego.Pointer("linodego-test-nb"),
			Region:             "us-mia",
			ClientConnThrottle: linodego.Pointer(5),
		},
	)
	if err != nil {
		log.Fatal(err)
	}

	spew.Dump(nodebalancer)

	config, err := client.CreateNodeBalancerConfig(
		context.Background(),
		nodebalancer.ID,
		linodego.NodeBalancerConfigCreateOptions{
			Port:          1234,
			Protocol:      linodego.ProtocolUDP,
			UDPCheckPort:  linodego.Pointer(4321),
			Algorithm:     linodego.AlgorithmRingHash,
			CheckInterval: 60,
		},
	)
	if err != nil {
		log.Fatal(err)
	}

	spew.Dump(config)
}
  1. Ensure the output looks similar to the following:
(*linodego.NodeBalancer)(0x1400018c1b0)({
 ID: (int) 1176274,
 Label: (*string)(0x14000010140)((len=16) "linodego-test-nb"),
 Region: (string) (len=6) "us-mia",
 Hostname: (*string)(0x14000010150)((len=40) "172-233-167-150.ip.linodeusercontent.com"),
 IPv4: (*string)(0x14000010160)((len=15) "172.233.167.150"),
 IPv6: (*string)(0x14000010170)((len=22) "2a01:7e04:1::ace9:a796"),
 ClientConnThrottle: (int) 5,
 ClientUDPSessThrottle: (int) 0,
 Transfer: (linodego.NodeBalancerTransfer) {
  Total: (*float64)(<nil>),
  Out: (*float64)(<nil>),
  In: (*float64)(<nil>)
 },
 Tags: ([]string) {
 },
 Created: (*time.Time)(0x1400000c120)(2025-01-07 16:28:14 +0000 UTC),
 Updated: (*time.Time)(0x1400000c138)(2025-01-07 16:28:14 +0000 UTC)
})

(*linodego.NodeBalancerConfig)(0x14000000360)({
 ID: (int) 1941508,
 Port: (int) 1234,
 Protocol: (linodego.ConfigProtocol) (len=3) "udp",
 ProxyProtocol: (linodego.ConfigProxyProtocol) (len=4) "none",
 Algorithm: (linodego.ConfigAlgorithm) (len=9) "ring_hash",
 Stickiness: (linodego.ConfigStickiness) (len=7) "session",
 Check: (linodego.ConfigCheck) (len=4) "none",
 CheckInterval: (int) 60,
 CheckAttempts: (int) 3,
 CheckPath: (string) "",
 CheckBody: (string) "",
 CheckPassive: (bool) false,
 CheckTimeout: (int) 30,
 UDPCheckPort: (int) 4321,
 UDPSessionTimeout: (int) 16,
 CipherSuite: (linodego.ConfigCipher) (len=4) "none",
 NodeBalancerID: (int) 1176274,
 SSLCommonName: (string) "",
 SSLFingerprint: (string) "",
 SSLCert: (string) "",
 SSLKey: (string) "",
 NodesStatus: (*linodego.NodeBalancerNodeStatus)(0x1400000f050)({
  Up: (int) 0,
  Down: (int) 0
 })
})

@lgarber-akamai lgarber-akamai added the new-feature for new features in the changelog. label Nov 22, 2024
Comment on lines 4 to 10
"context"
"testing"

"github.com/jarcoal/httpmock"
"github.com/linode/linodego"
"github.com/stretchr/testify/assert"
"testing"
)
Copy link
Contributor Author

@lgarber-akamai lgarber-akamai Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes were made implicitly by gofumpt -l -w .

@lgarber-akamai lgarber-akamai added the do-not-merge PRs that should not be merged until the commented issue is resolved label Nov 22, 2024
@lgarber-akamai lgarber-akamai marked this pull request as ready for review November 22, 2024 21:05
@lgarber-akamai lgarber-akamai requested a review from a team as a code owner November 22, 2024 21:05
@lgarber-akamai lgarber-akamai requested review from jriddle-linode and zliang-akamai and removed request for a team November 22, 2024 21:05
@github-actions github-actions bot added the Stale label Jan 5, 2025
@lgarber-akamai lgarber-akamai removed the do-not-merge PRs that should not be merged until the commented issue is resolved label Jan 7, 2025
@lgarber-akamai lgarber-akamai requested review from a team, ykim-akamai and yec-akamai and removed request for a team January 7, 2025 16:29
Copy link
Contributor

@ykim-akamai ykim-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, everything works well locally. Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature for new features in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants