Skip to content

Commit

Permalink
Change IPv6 to IPv4 in terratests
Browse files Browse the repository at this point in the history
  • Loading branch information
kuritka committed Feb 10, 2025
1 parent ae139d0 commit 74fa057
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
55 changes: 55 additions & 0 deletions taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# https://taskfile.dev/usage/
version: '3'
env:
VERSION: test004

tasks:

start-*:
vars:
CLUSTER: '{{index .MATCH 0}}'
cmds:
- echo "starting $CLUSTER"
- kubectl -n k8gb scale deployment k8gb --replicas=1 --context=$CLUSTER
description: "k3d-test-gslb2 = us, k3d-test-gslb1 = eu"

stop-*:
vars:
CLUSTER: '{{index .MATCH 0}}'
cmds:
- echo "stopping $CLUSTER"
- kubectl -n k8gb scale deployment k8gb --replicas=0 --context=$CLUSTER
description: "k3d-test-gslb2 = us, k3d-test-gslb1 = eu"

install:
cmds:
- defer: { task: us}
- echo "Installing current k8gb $VERSION"
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w -X main.version=$VERSION -X main.commit=123" -o ./k8gb main.go
- docker build . -t docker.io/kuritka/k8gb:$VERSION
- k3d image import docker.io/kuritka/k8gb:$VERSION -c test-gslb1
- k3d image import docker.io/kuritka/k8gb:$VERSION -c test-gslb2
- kubectl apply -f deploy/crds/test-ingress-init.yaml --context=k3d-test-gslb2 # for INGRESS_PATH=test-gslb/init-ingress
- kubectl apply -f deploy/crds/test-ingress-init.yaml --context=k3d-test-gslb1 # for INGRESS_PATH=test-gslb/init-ingress
- task: stop
- kubectl -n k8gb set image deployment/k8gb k8gb=kuritka/k8gb:$VERSION --context=k3d-test-gslb2
- kubectl -n k8gb set image deployment/k8gb k8gb=kuritka/k8gb:$VERSION --context=k3d-test-gslb1
- task: start_k3d-test-gslb1
silent: true

stop:
cmds:
- task: stop_k3d-test-gslb1
- task: stop_k3d-test-gslb2

start:
cmds:
- task: start_k3d-test-gslb1
- task: start_k3d-test-gslb2

us:
cmds:
- kubectl config use-context k3d-test-gslb2
eu:
cmds:
- kubectl config use-context k3d-test-gslb1
6 changes: 3 additions & 3 deletions terratest/utils/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,15 @@ func (i *Instance) String() (out string) {

// Dig returns a list of IP addresses from CoreDNS that belong to the instance
func (i *Instance) Dig() []string {
dig, err := dns.Dig("localhost:"+strconv.Itoa(i.w.state.gslb.port), i.w.state.gslb.host, i.w.settings.digUsingUDP)
dig, err := dns.Dig("127.0.0.1:"+strconv.Itoa(i.w.state.gslb.port), i.w.state.gslb.host, i.w.settings.digUsingUDP)
require.NoError(i.w.t, err)
return dig
}

// GetLocalTargets returns instance local targets
func (i *Instance) GetLocalTargets() []string {
dnsName := fmt.Sprintf("localtargets-%s", i.w.state.gslb.host)
dig, err := dns.Dig("localhost:"+strconv.Itoa(i.w.state.gslb.port), dnsName, i.w.settings.digUsingUDP)
dig, err := dns.Dig("127.0.0.1:"+strconv.Itoa(i.w.state.gslb.port), dnsName, i.w.settings.digUsingUDP)
i.logIfError(err, "GetLocalTargets(), dig: %s", err)
return dig
}
Expand Down Expand Up @@ -685,7 +685,7 @@ func waitForLocalGSLBNew(t *testing.T, host string, port int, expectedResult []s
"Wait for failover to happen and coredns to pickup new values...",
DefaultRetries,
time.Second*3,
func() ([]string, error) { return dns.Dig("localhost:"+strconv.Itoa(port), host, isUdp) },
func() ([]string, error) { return dns.Dig("127.0.0.1:"+strconv.Itoa(port), host, isUdp) },
expectedResult)
}

Expand Down

0 comments on commit 74fa057

Please sign in to comment.