-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dataclients/kubernetes: refactor GetEndpointAddresses
* change GetEndpointAddresses to return host:port addresses to avoid trimming implicit scheme * use all ports for endpointslices addresses for consistency with endpoints * use separate cluster state cache for addresses since cache key does not contain port * rename helpers protocol argument to scheme For #2476 Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
- Loading branch information
1 parent
cbc4e2d
commit 4b0187f
Showing
9 changed files
with
106 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,91 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"net/url" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/zalando/skipper/dataclients/kubernetes/definitions" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTargets(t *testing.T) { | ||
want := "http://10.0.0.1:8080" | ||
u, err := url.Parse(want) | ||
if err != nil { | ||
t.Fatalf("Failed to parse: %v", err) | ||
} | ||
port, err := strconv.Atoi(u.Port()) | ||
if err != nil { | ||
t.Fatalf("Failed to parse: %v", err) | ||
} | ||
func TestAddresses(t *testing.T) { | ||
assert.Equal(t, []string{"10.0.0.1:8080"}, (&skipperEndpointSlice{ | ||
Endpoints: []*skipperEndpoint{ | ||
{ | ||
Address: "10.0.0.1", | ||
Zone: "zone-1", | ||
}, | ||
}, | ||
Ports: []*endpointSlicePort{ | ||
{ | ||
Name: "main", | ||
Port: 8080, | ||
Protocol: "TCP", | ||
}, | ||
}, | ||
}).addresses()) | ||
|
||
ses := &skipperEndpointSlice{ | ||
Meta: &definitions.Metadata{ | ||
Namespace: "ns1", | ||
Name: "a-slice", | ||
assert.Equal(t, []string{"10.0.0.1:8080", "10.0.0.1:8081"}, (&skipperEndpointSlice{ | ||
Endpoints: []*skipperEndpoint{ | ||
{ | ||
Address: "10.0.0.1", | ||
Zone: "zone-1", | ||
}, | ||
}, | ||
Ports: []*endpointSlicePort{ | ||
{ | ||
Name: "main", | ||
Port: 8080, | ||
Protocol: "TCP", | ||
}, | ||
{ | ||
Name: "support", | ||
Port: 8081, | ||
Protocol: "TCP", | ||
}, | ||
}, | ||
}).addresses()) | ||
|
||
assert.Equal(t, []string{"10.0.0.1:8080", "10.0.0.2:8080"}, (&skipperEndpointSlice{ | ||
Endpoints: []*skipperEndpoint{ | ||
{ | ||
Address: u.Hostname(), | ||
Address: "10.0.0.1", | ||
Zone: "zone-1", | ||
}, | ||
{ | ||
Address: "10.0.0.2", | ||
Zone: "zone-2", | ||
}, | ||
}, | ||
Ports: []*endpointSlicePort{ | ||
{ | ||
Name: "main", | ||
Port: port, | ||
Port: 8080, | ||
Protocol: "TCP", | ||
}, | ||
}, | ||
} | ||
res := ses.targets("TCP", "http") | ||
if l := len(res); l != 1 { | ||
t.Fatalf("Failed to get same number of results than expected %d, got: %d", 1, l) | ||
} | ||
}).addresses()) | ||
|
||
for i := 0; i < len(res); i++ { | ||
if want != res[i] { | ||
t.Fatalf("Failed to get the right target: %s != %s", want, res[i]) | ||
} | ||
} | ||
assert.Equal(t, []string{"10.0.0.1:8080", "10.0.0.1:8081", "10.0.0.2:8080", "10.0.0.2:8081"}, (&skipperEndpointSlice{ | ||
Endpoints: []*skipperEndpoint{ | ||
{ | ||
Address: "10.0.0.1", | ||
Zone: "zone-1", | ||
}, | ||
{ | ||
Address: "10.0.0.2", | ||
Zone: "zone-2", | ||
}, | ||
}, | ||
Ports: []*endpointSlicePort{ | ||
{ | ||
Name: "main", | ||
Port: 8080, | ||
Protocol: "TCP", | ||
}, | ||
{ | ||
Name: "support", | ||
Port: 8081, | ||
Protocol: "TCP", | ||
}, | ||
}, | ||
}).addresses()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters