Skip to content

Commit

Permalink
Merge branch 'main' into move_zos-update-worker_to_zos/tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Nov 7, 2023
2 parents 466b229 + 89999e3 commit 0594472
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/PULL_REQUEST_TEMPLATE.md

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/zos-update-worker-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
uses: Jerome1337/[email protected]
with:
gofmt-flags: "-l -d"
working-directory: tools/zos-update-worker

- name: Test
run: go test -v ./...
Expand Down
41 changes: 28 additions & 13 deletions pkg/perf/publicip/publicip_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,33 +268,48 @@ func getIPWithRoute(publicIP substrate.PublicIP) (net.IP, []*net.IPNet, []*netli
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to parse IP %s: %w", publicIP.IP, err)
}
ipNet.IP = ip
gateway := net.ParseIP(publicIP.Gateway)
if gateway == nil {
return nil, nil, nil, fmt.Errorf("failed to parse gateway %s: %w", publicIP.Gateway, err)
}
route, err := netlink.RouteGet(gateway)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to get route to gateway %s", publicIP.Gateway)
}
routes := make([]*netlink.Route, 0)
for _, r := range route {
routes = append(routes, &r)
route := netlink.Route{
Dst: &net.IPNet{
IP: net.ParseIP("0.0.0.0"),
Mask: net.CIDRMask(0, 32),
},
Gw: gateway,
}
return ip, []*net.IPNet{ipNet}, routes, nil
return ip, []*net.IPNet{ipNet}, []*netlink.Route{&route}, nil
}

func getRealPublicIP() (net.IP, error) {
// for testing now, should change to cloudflare
req, err := http.Get("https://api.ipify.org/")
con, err := net.DialTimeout("tcp", "api.ipify.org:443", 10*time.Second)
if err != nil {
return nil, errors.Join(err, errPublicIPLookup)
}

defer con.Close()

cl := http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return con, nil
},
},
}
response, err := cl.Get("https://api.ipify.org/")
if err != nil {
return nil, errors.Join(err, errPublicIPLookup)
}
defer req.Body.Close()
defer response.Body.Close()

if req.StatusCode != 200 {
return nil, fmt.Errorf("request to get public IP failed with status code %d", req.StatusCode)
if response.StatusCode != 200 {
return nil, fmt.Errorf("request to get public IP failed with status code %d", response.StatusCode)
}
body, err := io.ReadAll(req.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0594472

Please sign in to comment.