Skip to content

Commit 65f097f

Browse files
authored
Merge pull request #87 from Charliekenney23/fix/externalip-kubeproxy-workaround
allow inter-service communication from within cluster via external LB
2 parents 518fd87 + db061c7 commit 65f097f

File tree

6 files changed

+35
-30
lines changed

6 files changed

+35
-30
lines changed

cloud/linode/loadbalancers.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@ func (l *loadbalancers) getLatestServiceLoadBalancerStatus(ctx context.Context,
120120

121121
// getNodeBalancerByStatus attempts to get the NodeBalancer from the IPv4 specified in the
122122
// most recent LoadBalancer status.
123-
func (l *loadbalancers) getNodeBalancerByStatus(ctx context.Context, service *v1.Service) (*linodego.NodeBalancer, error) {
123+
func (l *loadbalancers) getNodeBalancerByStatus(ctx context.Context, service *v1.Service) (nb *linodego.NodeBalancer, err error) {
124124
for _, ingress := range service.Status.LoadBalancer.Ingress {
125-
ipv4 := ingress.IP
126-
if nb, err := l.getNodeBalancerByIPv4(ctx, service, ipv4); err == nil {
127-
return nb, err
125+
if ingress.Hostname != "" {
126+
return l.getNodeBalancerByHostname(ctx, service, ingress.Hostname)
127+
}
128+
if ingress.IP != "" {
129+
return l.getNodeBalancerByIPv4(ctx, service, ingress.IP)
128130
}
129131
}
130132
return nil, lbNotFoundError{serviceNn: getServiceNn(service)}
@@ -436,6 +438,20 @@ func (l *loadbalancers) EnsureLoadBalancerDeleted(ctx context.Context, clusterNa
436438
return nil
437439
}
438440

441+
func (l *loadbalancers) getNodeBalancerByHostname(ctx context.Context, service *v1.Service, hostname string) (*linodego.NodeBalancer, error) {
442+
lbs, err := l.client.ListNodeBalancers(ctx, nil)
443+
if err != nil {
444+
return nil, err
445+
}
446+
for _, lb := range lbs {
447+
if *lb.Hostname == hostname {
448+
klog.V(2).Infof("found NodeBalancer (%d) for service (%s) via hostname (%s)", lb.ID, getServiceNn(service), hostname)
449+
return &lb, nil
450+
}
451+
}
452+
return nil, lbNotFoundError{serviceNn: getServiceNn(service)}
453+
}
454+
439455
func (l *loadbalancers) getNodeBalancerByIPv4(ctx context.Context, service *v1.Service, ipv4 string) (*linodego.NodeBalancer, error) {
440456
lbs, err := l.client.ListNodeBalancers(ctx, nil)
441457
if err != nil {
@@ -756,7 +772,6 @@ func getConnectionThrottle(service *v1.Service) int {
756772
func makeLoadBalancerStatus(nb *linodego.NodeBalancer) *v1.LoadBalancerStatus {
757773
return &v1.LoadBalancerStatus{
758774
Ingress: []v1.LoadBalancerIngress{{
759-
IP: *nb.IPv4,
760775
Hostname: *nb.Hostname,
761776
}},
762777
}

cloud/linode/loadbalancers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ func testUpdateLoadBalancerAddAnnotation(t *testing.T, client *linodego.Client,
310310
t.Errorf("UpdateLoadBalancer returned an error while updated annotations: %s", err)
311311
}
312312

313-
nb, err := lb.getNodeBalancerByIPv4(context.TODO(), svc, lbStatus.Ingress[0].IP)
313+
nb, err := lb.getNodeBalancerByStatus(context.TODO(), svc)
314314
if err != nil {
315-
t.Errorf("unexpected error: %v", err)
315+
t.Fatalf("failed to get NodeBalancer via status: %s", err)
316316
}
317317

318318
if nb.ClientConnThrottle != 10 {

e2e/test/ccm_e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var _ = Describe("e2e tests", func() {
109109
var getResponseFromSamePod = func(link string) {
110110
var oldResp, newResp string
111111
Eventually(func() string {
112-
resp, err := http.Get(link)
112+
resp, err := http.Get("http://" + link)
113113
if err == nil {
114114
byteData, _ := ioutil.ReadAll(resp.Body)
115115
defer resp.Body.Close()

e2e/test/framework/loadbalancer_suite.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (i *lbInvocation) GetHTTPEndpoints() ([]string, error) {
1515
}
1616

1717
func (i *lbInvocation) GetNodeBalancerID(svcName string) (int, error) {
18-
ip, err := i.waitForLoadBalancerIP(svcName)
18+
hostname, err := i.waitForLoadBalancerHostname(svcName)
1919
if err != nil {
2020
return -1, err
2121
}
@@ -27,7 +27,7 @@ func (i *lbInvocation) GetNodeBalancerID(svcName string) (int, error) {
2727
}
2828

2929
for _, nb := range nbList {
30-
if *nb.IPv4 == ip {
30+
if *nb.Hostname == hostname {
3131
return nb.ID, nil
3232
}
3333
}
@@ -74,7 +74,7 @@ func (i *lbInvocation) GetNodeBalancerConfigForPort(svcName string, port int) (*
7474
return nil, fmt.Errorf("NodeBalancerConfig for port %d was not found", port)
7575
}
7676

77-
func (i *lbInvocation) waitForLoadBalancerIP(svcName string) (string, error) {
77+
func (i *lbInvocation) waitForLoadBalancerHostname(svcName string) (string, error) {
7878
var ip string
7979
err := wait.PollImmediate(RetryInterval, RetryTimeout, func() (bool, error) {
8080
svc, err := i.kubeClient.CoreV1().Services(i.Namespace()).Get(context.TODO(), svcName, metav1.GetOptions{})
@@ -85,7 +85,7 @@ func (i *lbInvocation) waitForLoadBalancerIP(svcName string) (string, error) {
8585
if svc.Status.LoadBalancer.Ingress == nil {
8686
return false, nil
8787
}
88-
ip = svc.Status.LoadBalancer.Ingress[0].IP
88+
ip = svc.Status.LoadBalancer.Ingress[0].Hostname
8989
return true, nil
9090
})
9191

e2e/test/framework/service.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"log"
8-
"net/url"
98
"time"
109

1110
"github.com/golang/glog"
@@ -149,9 +148,9 @@ func (i *lbInvocation) getLoadBalancerURLs() ([]string, error) {
149148
return serverAddr, err
150149
}
151150

152-
ips := make([]string, 0)
151+
hostnames := make([]string, 0)
153152
for _, ingress := range svc.Status.LoadBalancer.Ingress {
154-
ips = append(ips, ingress.IP)
153+
hostnames = append(hostnames, ingress.Hostname)
155154
}
156155

157156
var ports []int32
@@ -164,12 +163,8 @@ func (i *lbInvocation) getLoadBalancerURLs() ([]string, error) {
164163
}
165164

166165
for _, port := range ports {
167-
for _, ip := range ips {
168-
u, err := url.Parse(fmt.Sprintf("http://%s:%d", ip, port))
169-
if err != nil {
170-
return nil, err
171-
}
172-
serverAddr = append(serverAddr, u.String())
166+
for _, hostname := range hostnames {
167+
serverAddr = append(serverAddr, fmt.Sprintf("%s:%d", hostname, port))
173168
}
174169
}
175170

e2e/test/framework/util.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"log"
99
"net"
1010
"net/http"
11-
"net/url"
1211
"os"
1312
"os/exec"
1413
"path"
@@ -142,13 +141,10 @@ func getHTTPSResponse(domain, ip, port string) (string, error) {
142141

143142
func WaitForHTTPSResponse(link string, podName string) error {
144143
return wait.PollImmediate(RetryInterval, RetryTimeout, func() (bool, error) {
145-
u, err := url.Parse(link)
146-
if err != nil {
147-
return false, nil
148-
}
149-
ipPort := strings.Split(u.Host, ":")
144+
hostPort := strings.Split(link, ":")
145+
host, port := hostPort[0], hostPort[1]
150146

151-
resp, err := getHTTPSResponse(Domain, ipPort[0], ipPort[1])
147+
resp, err := getHTTPSResponse(Domain, host, port)
152148
if err != nil {
153149
return false, nil
154150
}
@@ -163,7 +159,7 @@ func WaitForHTTPSResponse(link string, podName string) error {
163159
}
164160

165161
func getHTTPResponse(link string) (bool, string, error) {
166-
resp, err := http.Get(link)
162+
resp, err := http.Get("http://" + link)
167163
if err != nil {
168164
return false, "", err
169165
}
@@ -173,7 +169,6 @@ func getHTTPResponse(link string) (bool, string, error) {
173169
if err != nil {
174170
return false, "", err
175171
}
176-
177172
return resp.StatusCode == 200, string(bodyBytes), nil
178173
}
179174

0 commit comments

Comments
 (0)