-
Notifications
You must be signed in to change notification settings - Fork 687
/
net_override.go
46 lines (41 loc) · 1006 Bytes
/
net_override.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"io/ioutil"
"time"
"github.com/pkg/errors"
"github.com/datawire/ambassador/pkg/supervisor"
)
// MakeNetOverride sets up the network override resource for the daemon
func (d *Daemon) MakeNetOverride(p *supervisor.Process) error {
netOverride, err := CheckedRetryingCommand(
p,
"netOverride",
[]string{edgectl, "teleproxy", "intercept", d.dns, d.fallback},
&RunAsInfo{},
checkNetOverride,
10*time.Second,
)
if err != nil {
return errors.Wrap(err, "teleproxy initial launch")
}
d.network = netOverride
return nil
}
// checkNetOverride checks the status of teleproxy intercept by doing the
// equivalent of curl http://teleproxy/api/tables/.
func checkNetOverride(p *supervisor.Process) error {
res, err := hClient.Get(fmt.Sprintf(
"http://teleproxy%d.cachebust.telepresence.io/api/tables",
time.Now().Unix(),
))
if err != nil {
return err
}
_, err = ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return err
}
return nil
}