-
Notifications
You must be signed in to change notification settings - Fork 31
/
util.go
65 lines (57 loc) · 1.56 KB
/
util.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package common
import (
"time"
"k8s.io/klog"
"github.com/joyrex2001/kubedock/internal/backend"
"github.com/joyrex2001/kubedock/internal/model/types"
)
// StartContainer will start given container and saves the appropriate state
// in the database.
func StartContainer(cr *ContextRouter, tainr *types.Container) error {
state, err := cr.Backend.StartContainer(tainr)
if err != nil {
return err
}
tainr.HostIP = "0.0.0.0"
if cr.Config.PortForward {
cr.Backend.CreatePortForwards(tainr)
} else {
if len(tainr.GetServicePorts()) > 0 {
ip, err := cr.Backend.GetPodIP(tainr)
if err != nil {
return err
}
tainr.HostIP = ip
if cr.Config.ReverseProxy {
cr.Backend.CreateReverseProxies(tainr)
}
}
}
tainr.Stopped = false
tainr.Killed = false
tainr.Failed = (state == backend.DeployFailed)
tainr.Completed = (state == backend.DeployCompleted)
tainr.Running = (state == backend.DeployRunning)
return cr.DB.SaveContainer(tainr)
}
// UpdateContainerStatus will check if the started container is finished and will
// update the container database record accordingly.
func UpdateContainerStatus(cr *ContextRouter, tainr *types.Container) {
if tainr.Completed {
return
}
if !cr.Limiter.Allow() {
klog.V(2).Infof("rate-limited status request for container: %s", tainr.ID)
return
}
status, err := cr.Backend.GetContainerStatus(tainr)
if err != nil {
klog.Warningf("container status error: %s", err)
tainr.Failed = true
}
if status == backend.DeployCompleted {
tainr.Finished = time.Now()
tainr.Completed = true
tainr.Running = false
}
}