Skip to content

Commit 8203f85

Browse files
CurtisTheJay Pateljaywasd
authored
Ipv6 (#257)
* Support for IPv6 endpoints. Co-authored-by: Jay Patel <[email protected]> Co-authored-by: jaywasd <[email protected]>
1 parent cc4f541 commit 8203f85

File tree

16 files changed

+498
-71
lines changed

16 files changed

+498
-71
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ test: manifests generate generate-mocks fmt vet goimports lint ## Run tests
7171
go test ./... -coverprofile=cover.out -covermode=atomic
7272

7373
kind-integration-suite: ## Provision and run integration tests with cleanup
74+
export ADDRESS_TYPE="IPv4" && \
75+
make kind-integration-setup && \
76+
make kind-integration-run && \
77+
make kind-integration-cleanup
78+
79+
export ADDRESS_TYPE="IPv6" && \
7480
make kind-integration-setup && \
7581
make kind-integration-run && \
7682
make kind-integration-cleanup
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
networking:
4+
ipFamily: ipv6
5+
apiServerAddress: 127.0.0.1

integration/kind-test/scripts/dns-test.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env bash
22

3+
# If the IP Type env var is not set, default it to IPv4
4+
if [[ -z "${ADDRESS_TYPE}" ]]; then
5+
ADDRESS_TYPE="IPv4"
6+
fi
7+
38
# Helper function to verify DNS results
49
checkDNS() {
510
dns_addresses_count=$(echo "$1" | wc -l | xargs)
@@ -31,10 +36,20 @@ $KUBECTL_BIN wait --for=condition=ready pod/dnsutils # wait until pod is deploye
3136

3237
# Perform a dig to cluster-local CoreDNS
3338
# TODO: parse dig outputs for more precise verification - check specifics IPs?
34-
echo "performing dig for A/AAAA records..."
35-
addresses=$($KUBECTL_BIN exec dnsutils -- dig +all +ans $SERVICE.$NAMESPACE.svc.clusterset.local +short)
36-
exit_code=$?
37-
echo "$addresses"
39+
if [[ $ADDRESS_TYPE == "IPv4" ]]; then
40+
echo "performing dig for A records for IPv4..."
41+
addresses=$($KUBECTL_BIN exec dnsutils -- dig +all +ans $SERVICE.$NAMESPACE.svc.clusterset.local +short)
42+
exit_code=$?
43+
echo "$addresses"
44+
elif [[ $ADDRESS_TYPE == "IPv6" ]]; then
45+
echo "performing dig for AAAA records for IPv6..."
46+
addresses=$($KUBECTL_BIN exec dnsutils -- dig AAAA +all +ans $SERVICE.$NAMESPACE.svc.clusterset.local +short)
47+
exit_code=$?
48+
echo "$addresses"
49+
else
50+
echo "ADDRESS_TYPE invalid"
51+
exit 1
52+
fi
3853

3954
if [ "$exit_code" -ne 0 ]; then
4055
echo "ERROR: Unable to dig service $SERVICE.$NAMESPACE.svc.clusterset.local"

integration/kind-test/scripts/run-helper.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ source ./integration/kind-test/scripts/common.sh
77
# create test namespace
88
$KUBECTL_BIN create namespace "$NAMESPACE"
99

10+
# If the IP Type env var is not set, default it to IPV4
11+
if [[ -z "${ADDRESS_TYPE}" ]]; then
12+
ADDRESS_TYPE="IPv4"
13+
fi
14+
1015
# ClusterIP service test
11-
./integration/kind-test/scripts/run-tests.sh "$CLUSTERIP_SERVICE" "ClusterSetIP"
16+
./integration/kind-test/scripts/run-tests.sh "$CLUSTERIP_SERVICE" "ClusterSetIP" $ADDRESS_TYPE
1217
exit_code=$?
1318
if [ "$exit_code" -ne 0 ] ; then
1419
echo "ERROR: Testing $CLUSTERIP_SERVICE failed"
@@ -18,7 +23,7 @@ fi
1823
sleep 5
1924

2025
# Headless service test
21-
./integration/kind-test/scripts/run-tests.sh "$HEADLESS_SERVICE" "Headless"
26+
./integration/kind-test/scripts/run-tests.sh "$HEADLESS_SERVICE" "Headless" $ADDRESS_TYPE
2227
exit_code=$?
2328
if [ "$exit_code" -ne 0 ] ; then
2429
echo "ERROR: Testing $HEADLESS_SERVICE failed"

integration/kind-test/scripts/run-tests.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
source ./integration/kind-test/scripts/common.sh
66
export SERVICE=$1
77
export SERVICE_TYPE=$2
8+
export IP_TYPE=$3
89

910
# Deploy pods
1011
$KUBECTL_BIN apply -f "$KIND_CONFIGS/e2e-deployment.yaml"
@@ -24,7 +25,7 @@ mkdir -p "$LOGS"
2425
CTL_PID=$!
2526
echo "controller PID:$CTL_PID"
2627

27-
go run $SCENARIOS/runner/main.go $NAMESPACE $SERVICE $CLUSTERID1 $CLUSTERSETID1 $ENDPT_PORT $SERVICE_PORT $SERVICE_TYPE "$endpts"
28+
go run $SCENARIOS/runner/main.go $NAMESPACE $SERVICE $CLUSTERID1 $CLUSTERSETID1 $ENDPT_PORT $SERVICE_PORT $SERVICE_TYPE $IP_TYPE "$endpts"
2829
exit_code=$?
2930

3031
if [ "$exit_code" -eq 0 ] ; then
@@ -58,7 +59,7 @@ if [ "$exit_code" -eq 0 ] ; then
5859
fi
5960

6061
if [ "$exit_code" -eq 0 ] ; then
61-
go run $SCENARIOS/runner/main.go $NAMESPACE $SERVICE $CLUSTERID1 $CLUSTERSETID1 $ENDPT_PORT $SERVICE_PORT $SERVICE_TYPE "$updated_endpoints"
62+
go run $SCENARIOS/runner/main.go $NAMESPACE $SERVICE $CLUSTERID1 $CLUSTERSETID1 $ENDPT_PORT $SERVICE_PORT $SERVICE_TYPE $IP_TYPE "$updated_endpoints"
6263
exit_code=$?
6364
fi
6465

integration/kind-test/scripts/setup-kind.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ source ./integration/kind-test/scripts/common.sh
99

1010
./integration/kind-test/scripts/ensure-jq.sh
1111

12-
$KIND_BIN create cluster --name "$KIND_SHORT" --image "$IMAGE"
12+
# If the IP Type env var is not set, default it to IPv4
13+
if [[ -z "${ADDRESS_TYPE}" ]]; then
14+
ADDRESS_TYPE="IPv4"
15+
fi
16+
17+
echo "ADDRESS_TYPE: $ADDRESS_TYPE"
18+
if [[ $ADDRESS_TYPE == "IPv4" ]]; then
19+
$KIND_BIN create cluster --name "$KIND_SHORT" --image "$IMAGE"
20+
elif [[ $ADDRESS_TYPE == "IPv6" ]]; then
21+
$KIND_BIN create cluster --name "$KIND_SHORT" --image "$IMAGE" --config=./integration/kind-test/configs/ipv6.yaml
22+
else
23+
echo "ADDRESS_TYPE invalid"
24+
fi
25+
1326
$KUBECTL_BIN config use-context "$CLUSTER"
1427
make install
1528

integration/shared/scenarios/export_service.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type exportServiceScenario struct {
3333
expectedSvc model.Service
3434
}
3535

36-
func NewExportServiceScenario(cfg *aws.Config, nsName string, svcName string, clusterId string, clusterSetId string, portStr string, servicePortStr string, serviceType string, ips string) (ExportServiceScenario, error) {
36+
func NewExportServiceScenario(cfg *aws.Config, nsName string, svcName string, clusterId string, clusterSetId string, portStr string, servicePortStr string, serviceType string, addressTypeStr string, ips string) (ExportServiceScenario, error) {
3737
endpts := make([]*model.Endpoint, 0)
3838

3939
port, parseError := strconv.ParseUint(portStr, 10, 16)
@@ -44,15 +44,20 @@ func NewExportServiceScenario(cfg *aws.Config, nsName string, svcName string, cl
4444
if parseError != nil {
4545
return nil, parseError
4646
}
47+
addressType, parseError := model.GetAddressTypeFromString(addressTypeStr)
48+
if parseError != nil {
49+
return nil, parseError
50+
}
4751

4852
for _, ip := range strings.Split(ips, ",") {
4953
endpointPort := model.Port{
5054
Port: int32(port),
5155
Protocol: string(v1.ProtocolTCP),
5256
}
5357
endpts = append(endpts, &model.Endpoint{
54-
Id: model.EndpointIdFromIPAddressAndPort(ip, endpointPort),
55-
IP: ip,
58+
Id: model.EndpointIdFromIPAddressAndPort(ip, endpointPort),
59+
IP: ip,
60+
AddressType: addressType,
5661
ServicePort: model.Port{
5762
Port: int32(servicePort),
5863
TargetPort: portStr,

integration/shared/scenarios/runner/main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
func main() {
14-
if len(os.Args) != 9 {
15-
fmt.Println("Expected namespace, service, clusterId, clusterSetId, endpoint port, service port, serviceType, and endpoint IP list as arguments")
14+
if len(os.Args) != 10 {
15+
fmt.Println("Expected namespace, service, clusterId, clusterSetId, endpoint port, service port, serviceType, endpoint AddressType, and endpoint IP list as arguments")
1616
os.Exit(1)
1717
}
1818

@@ -23,15 +23,16 @@ func main() {
2323
port := os.Args[5]
2424
servicePort := os.Args[6]
2525
serviceType := os.Args[7]
26-
ips := os.Args[8]
26+
addressType := os.Args[8]
27+
ips := os.Args[9]
2728

28-
testServiceExport(nsName, svcName, clusterId, clusterSetId, port, servicePort, serviceType, ips)
29+
testServiceExport(nsName, svcName, clusterId, clusterSetId, port, servicePort, serviceType, addressType, ips)
2930
}
3031

31-
func testServiceExport(nsName string, svcName string, clusterId string, clusterSetId string, port string, servicePort string, serviceType string, ips string) {
32+
func testServiceExport(nsName string, svcName string, clusterId string, clusterSetId string, port string, servicePort string, serviceType string, addressType string, ips string) {
3233
fmt.Printf("Testing service export integration for namespace %s and service %s\n", nsName, svcName)
3334

34-
export, err := scenarios.NewExportServiceScenario(getAwsConfig(), nsName, svcName, clusterId, clusterSetId, port, servicePort, serviceType, ips)
35+
export, err := scenarios.NewExportServiceScenario(getAwsConfig(), nsName, svcName, clusterId, clusterSetId, port, servicePort, serviceType, addressType, ips)
3536
if err != nil {
3637
fmt.Printf("Failed to setup service export integration test scenario: %s", err.Error())
3738
os.Exit(1)

pkg/controllers/multicluster/controllers_common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func endpointSliceForTest() *discovery.EndpointSlice {
9696

9797
func endpointSliceFromEndpointsForTest(endpts []*model.Endpoint, ports []discovery.EndpointPort) *discovery.EndpointSlice {
9898
svc := k8sServiceForTest()
99-
slice := CreateEndpointSliceStruct(svc, test.SvcName, test.ClusterId1)
99+
slice := CreateEndpointSliceStruct(svc, test.SvcName, test.ClusterId1, endpts[0].AddressType)
100100
slice.Ports = ports
101101

102102
testEndpoints := make([]discovery.Endpoint, 0)

pkg/controllers/multicluster/endpointslice_plan.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ type EndpointSlicePlan struct {
3939
ClusterId string
4040
}
4141

42+
// CheckAddressType TODO: Will need to improve how IP Type is determined when we implement dual stack.
43+
func (p *EndpointSlicePlan) CheckAddressType() discovery.AddressType {
44+
// Peek at the first endpoint for its AddressType. All endpoints in a slice will be of the same AddressType.
45+
if len(p.Desired) == 0 {
46+
return discovery.AddressTypeIPv4
47+
}
48+
return p.Desired[0].AddressType
49+
}
50+
4251
// CalculateChanges returns list of EndpointSlice Changes that need to applied
4352
func (p *EndpointSlicePlan) CalculateChanges() EndpointSliceChanges {
4453
// populate map of desired endpoints for lookup efficiency
@@ -147,7 +156,7 @@ func (p *EndpointSlicePlan) getOrCreateUnfilledEndpointSlice(changes *EndpointSl
147156
}
148157

149158
// No existing slices can fill new endpoint requirements so create a new slice
150-
sliceToCreate := CreateEndpointSliceStruct(p.Service, p.ServiceImportName, p.ClusterId)
159+
sliceToCreate := CreateEndpointSliceStruct(p.Service, p.ServiceImportName, p.ClusterId, p.CheckAddressType())
151160
changes.Create = append(changes.Create, sliceToCreate)
152161
return sliceToCreate, true
153162
}

0 commit comments

Comments
 (0)