forked from tilt-dev/tilt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip.go
48 lines (40 loc) · 942 Bytes
/
ip.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
47
48
package k8s
import (
"context"
"sync"
"github.com/tilt-dev/clusterid"
"github.com/tilt-dev/tilt/pkg/logger"
)
// Some K8s environments expose a single IP for the whole cluster.
type NodeIP string
type nodeIPAsync struct {
mkClient MinikubeClient
env clusterid.Product
once sync.Once
nodeIP NodeIP
}
func newNodeIPAsync(env clusterid.Product, mkClient MinikubeClient) *nodeIPAsync {
return &nodeIPAsync{
env: env,
mkClient: mkClient,
}
}
func (a *nodeIPAsync) detectNodeIP(ctx context.Context) NodeIP {
if a.env != clusterid.ProductMinikube {
return ""
}
nodeIP, err := a.mkClient.NodeIP(ctx)
if err != nil {
logger.Get(ctx).Warnf("%s", err.Error())
}
return nodeIP
}
func (a *nodeIPAsync) NodeIP(ctx context.Context) NodeIP {
a.once.Do(func() {
a.nodeIP = a.detectNodeIP(ctx)
})
return a.nodeIP
}
func (c K8sClient) NodeIP(ctx context.Context) NodeIP {
return c.nodeIPAsync.NodeIP(ctx)
}