Skip to content

Commit

Permalink
Allow specifying Private IP by annotation for VLAN / VPC support
Browse files Browse the repository at this point in the history
  • Loading branch information
glennpratt committed Nov 13, 2023
1 parent fc4ad36 commit 7e7f7d2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
14 changes: 12 additions & 2 deletions cloud/linode/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (

annLinodeHostnameOnlyIngress = "service.beta.kubernetes.io/linode-loadbalancer-hostname-only-ingress"
annLinodeLoadBalancerTags = "service.beta.kubernetes.io/linode-loadbalancer-tags"

annLinodeNodePrivateIP = "node.k8s.linode.com/private-ip"
)

var (
Expand Down Expand Up @@ -644,7 +646,7 @@ func (l *loadbalancers) buildLoadBalancerRequest(ctx context.Context, clusterNam

func (l *loadbalancers) buildNodeBalancerNodeCreateOptions(node *v1.Node, nodePort int32) linodego.NodeBalancerNodeCreateOptions {
return linodego.NodeBalancerNodeCreateOptions{
Address: fmt.Sprintf("%v:%v", getNodeInternalIP(node), nodePort),
Address: fmt.Sprintf("%v:%v", getNodePrivateIP(node), nodePort),
Label: node.Name,
Mode: "accept",
Weight: 100,
Expand Down Expand Up @@ -758,7 +760,15 @@ func getPortConfigAnnotation(service *v1.Service, port int) (portConfigAnnotatio
return annotation, nil
}

func getNodeInternalIP(node *v1.Node) string {
// getNodePrivateIP should provide the Linode Private IP the NodeBalance
// will comminucate with. When using a VLAN or VPC for the Kubernetes cluster

Check failure on line 764 in cloud/linode/loadbalancers.go

View workflow job for this annotation

GitHub Actions / test

`comminucate` is a misspelling of `communicate` (misspell)
// network, this will not be the NodeInternalIP, so this prefers an annotation
// cluster operators may specify in such a situation.
func getNodePrivateIP(node *v1.Node) string {
if address, exists := node.Annotations[annLinodeNodePrivateIP]; exists {
return address
}

for _, addr := range node.Status.Addresses {
if addr.Type == v1.NodeInternalIP {
return addr.Address
Expand Down
23 changes: 21 additions & 2 deletions cloud/linode/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ func Test_getHealthCheckType(t *testing.T) {
}
}

func Test_getNodeInternalIP(t *testing.T) {
func Test_getNodePrivateIP(t *testing.T) {
testcases := []struct {
name string
node *v1.Node
Expand Down Expand Up @@ -1146,11 +1146,30 @@ func Test_getNodeInternalIP(t *testing.T) {
},
"",
},
{
"node internal ip annotation present",
&v1.Node{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
annLinodeNodePrivateIP: "192.168.42.42",
},
},
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{
Type: v1.NodeInternalIP,
Address: "10.0.1.1",
},
},
},
},
"192.168.42.42",
},
}

for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
ip := getNodeInternalIP(test.node)
ip := getNodePrivateIP(test.node)
if ip != test.address {
t.Error("unexpected certificate")
t.Logf("expected: %q", test.address)
Expand Down

0 comments on commit 7e7f7d2

Please sign in to comment.