From 31ebc2e58222395c6705167b9af6abb297717a0d Mon Sep 17 00:00:00 2001 From: timfeirg Date: Mon, 28 Aug 2017 16:46:18 +0800 Subject: [PATCH] [skip ci] completely remove timeout from config --- cluster/calcium/build_image.go | 12 +++------ cluster/calcium/build_image_test.go | 4 +-- cluster/calcium/cluster.go | 2 +- cluster/calcium/create_container.go | 36 ++++++++------------------ cluster/calcium/helper.go | 11 +++----- cluster/calcium/image.go | 13 +++------- cluster/calcium/meta_test.go | 6 ++--- cluster/calcium/mock_test.go | 14 ++++------- cluster/calcium/realloc.go | 11 +++----- cluster/calcium/remove_container.go | 12 ++++----- cluster/calcium/remove_image.go | 4 +-- cluster/calcium/run_and_wait.go | 12 +++------ core.yaml.sample | 10 -------- network/calico/plugin.go | 21 +++++----------- types/config.go | 22 +++------------- utils/config.go | 39 +---------------------------- 16 files changed, 57 insertions(+), 172 deletions(-) diff --git a/cluster/calcium/build_image.go b/cluster/calcium/build_image.go index 35730ec32..16c2bd721 100644 --- a/cluster/calcium/build_image.go +++ b/cluster/calcium/build_image.go @@ -176,9 +176,7 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t log.Infof("Building image %v with artifact %v at %v:%v", tag, artifact, buildPodname, node.Name) - ctx, cancel := context.WithTimeout(context.Background(), c.config.Timeout.BuildImage) - defer cancel() - resp, err := node.Engine.ImageBuild(ctx, buildContext, buildOptions) + resp, err := node.Engine.ImageBuild(context.Background(), buildContext, buildOptions) if err != nil { return ch, err } @@ -200,11 +198,9 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t ch <- message } - ctx, cancel := context.WithTimeout(context.Background(), c.config.Timeout.BuildImage) - defer cancel() // About this "Khadgar", https://github.com/docker/docker/issues/10983#issuecomment-85892396 // Just because Ben Schnetzer's cute Khadgar... - rc, err := node.Engine.ImagePush(ctx, tag, enginetypes.ImagePushOptions{RegistryAuth: "Khadgar"}) + rc, err := node.Engine.ImagePush(context.Background(), tag, enginetypes.ImagePushOptions{RegistryAuth: "Khadgar"}) if err != nil { ch <- makeErrorBuildImageMessage(err) return @@ -229,9 +225,7 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t // 事实上他不会跟cached pod一样 // 一样就砍死 go func() { - ctx, cancel := context.WithTimeout(context.Background(), c.config.Timeout.BuildImage) - defer cancel() - _, err := node.Engine.ImageRemove(ctx, tag, enginetypes.ImageRemoveOptions{ + _, err := node.Engine.ImageRemove(context.Background(), tag, enginetypes.ImageRemoveOptions{ Force: false, PruneChildren: true, }) diff --git a/cluster/calcium/build_image_test.go b/cluster/calcium/build_image_test.go index 539aba6ca..0947ff7e9 100644 --- a/cluster/calcium/build_image_test.go +++ b/cluster/calcium/build_image_test.go @@ -17,7 +17,7 @@ import ( func TestGetRandomNode(t *testing.T) { store := &mockstore.MockStore{} config := types.Config{} - c := &calcium{store: store, config: config, scheduler: simplescheduler.New(), network: calico.New(config), source: gitlab.New(config)} + c := &calcium{store: store, config: config, scheduler: simplescheduler.New(), network: calico.New(), source: gitlab.New(config)} n1 := &types.Node{Name: "node1", Podname: "podname", Endpoint: "tcp://10.0.0.1:2376", CPU: types.CPUMap{"0": 10, "1": 10}, Available: true} n2 := &types.Node{Name: "node2", Podname: "podname", Endpoint: "tcp://10.0.0.2:2376", CPU: types.CPUMap{"0": 10, "1": 10}, Available: true} @@ -34,7 +34,7 @@ func TestGetRandomNode(t *testing.T) { func TestGetRandomNodeFail(t *testing.T) { store := &mockstore.MockStore{} config := types.Config{} - c := &calcium{store: store, config: config, scheduler: simplescheduler.New(), network: calico.New(config), source: gitlab.New(config)} + c := &calcium{store: store, config: config, scheduler: simplescheduler.New(), network: calico.New(), source: gitlab.New(config)} n1 := &types.Node{Name: "node1", Podname: "podname", Endpoint: "tcp://10.0.0.1:2376", CPU: types.CPUMap{"0": 10, "1": 10}, Available: false} n2 := &types.Node{Name: "node2", Podname: "podname", Endpoint: "tcp://10.0.0.2:2376", CPU: types.CPUMap{"0": 10, "1": 10}, Available: false} diff --git a/cluster/calcium/cluster.go b/cluster/calcium/cluster.go index bb6e43ede..ca9397c91 100644 --- a/cluster/calcium/cluster.go +++ b/cluster/calcium/cluster.go @@ -46,7 +46,7 @@ func New(config types.Config) (*calcium, error) { } // set network - titanium := calico.New(config) + titanium := calico.New() // set scm var scm source.Source diff --git a/cluster/calcium/create_container.go b/cluster/calcium/create_container.go index f5a08bb36..9878db55c 100644 --- a/cluster/calcium/create_container.go +++ b/cluster/calcium/create_container.go @@ -83,9 +83,7 @@ func (c *calcium) createContainerWithMemoryPrior(specs types.Specs, opts *types. func (c *calcium) removeMemoryPodFailedContainer(id string, node *types.Node, nodeInfo types.NodeInfo, opts *types.DeployOptions) { defer c.store.UpdateNodeMem(opts.Podname, nodeInfo.Name, opts.Memory, "+") - ctx, cancel := context.WithTimeout(context.Background(), c.config.Timeout.CreateContainer) - defer cancel() - if err := node.Engine.ContainerRemove(ctx, id, enginetypes.ContainerRemoveOptions{}); err != nil { + if err := node.Engine.ContainerRemove(context.Background(), id, enginetypes.ContainerRemoveOptions{}); err != nil { log.Errorf("[RemoveMemoryPodFailedContainer] Error during remove failed container %v", err) } } @@ -127,9 +125,7 @@ func (c *calcium) doCreateContainerWithMemoryPrior(nodeInfo types.NodeInfo, spec } //create container - ctx, cancel := context.WithTimeout(context.Background(), c.config.Timeout.CreateContainer) - defer cancel() - container, err := node.Engine.ContainerCreate(ctx, config, hostConfig, networkConfig, containerName) + container, err := node.Engine.ContainerCreate(context.Background(), config, hostConfig, networkConfig, containerName) if err != nil { log.Errorf("[CreateContainerWithMemoryPrior] Error during ContainerCreate, %v", err) ms[i].Error = err.Error() @@ -165,9 +161,7 @@ func (c *calcium) doCreateContainerWithMemoryPrior(nodeInfo types.NodeInfo, spec continue } } - ctxStart, cancelStart := context.WithTimeout(context.Background(), c.config.Timeout.CreateContainer) - defer cancelStart() - err = node.Engine.ContainerStart(ctxStart, container.ID, enginetypes.ContainerStartOptions{}) + err = node.Engine.ContainerStart(context.Background(), container.ID, enginetypes.ContainerStartOptions{}) if err != nil { log.Errorf("[CreateContainerWithMemoryPrior] Error during ContainerStart, %v", err) ms[i].Error = err.Error() @@ -178,9 +172,7 @@ func (c *calcium) doCreateContainerWithMemoryPrior(nodeInfo types.NodeInfo, spec // TODO // if network manager uses our own, then connect must be called after container starts // here - ctxInspect, cancelInspect := context.WithTimeout(context.Background(), c.config.Timeout.CreateContainer) - defer cancelInspect() - info, err := node.Engine.ContainerInspect(ctxInspect, container.ID) + info, err := node.Engine.ContainerInspect(context.Background(), container.ID) if err != nil { log.Errorf("[CreateContainerWithMemoryPrior] Error during ContainerInspect, %v", err) ms[i].Error = err.Error() @@ -190,7 +182,7 @@ func (c *calcium) doCreateContainerWithMemoryPrior(nodeInfo types.NodeInfo, spec ms[i].ContainerID = info.ID // after start - if err := runExec(node.Engine, info, AFTER_START, c.config.Timeout.CreateContainer); err != nil { + if err := runExec(node.Engine, info, AFTER_START); err != nil { log.Errorf("[CreateContainerWithMemoryPrior] Run exec at %s error: %v", AFTER_START, err) } @@ -259,9 +251,7 @@ func (c *calcium) createContainerWithCPUPrior(specs types.Specs, opts *types.Dep func (c *calcium) removeCPUPodFailedContainer(id string, node *types.Node, quota types.CPUMap) { defer c.releaseQuota(node, quota) - ctx, cancel := context.WithTimeout(context.Background(), c.config.Timeout.CreateContainer) - defer cancel() - if err := node.Engine.ContainerRemove(ctx, id, enginetypes.ContainerRemoveOptions{}); err != nil { + if err := node.Engine.ContainerRemove(context.Background(), id, enginetypes.ContainerRemoveOptions{}); err != nil { log.Errorf("[RemoveCPUPodFailedContainer] Error during remove failed container %v", err) } } @@ -301,9 +291,7 @@ func (c *calcium) doCreateContainerWithCPUPrior(nodeName string, cpuMap []types. } // create container - ctxCreate, cancelCreate := context.WithTimeout(context.Background(), c.config.Timeout.CreateContainer) - defer cancelCreate() - container, err := node.Engine.ContainerCreate(ctxCreate, config, hostConfig, networkConfig, containerName) + container, err := node.Engine.ContainerCreate(context.Background(), config, hostConfig, networkConfig, containerName) if err != nil { log.Errorf("[CreateContainerWithCPUPrior] Error when creating container, %v", err) ms[i].Error = err.Error() @@ -341,9 +329,7 @@ func (c *calcium) doCreateContainerWithCPUPrior(nodeName string, cpuMap []types. continue } } - ctxStart, cancelStart := context.WithTimeout(context.Background(), c.config.Timeout.CreateContainer) - defer cancelStart() - err = node.Engine.ContainerStart(ctxStart, container.ID, enginetypes.ContainerStartOptions{}) + err = node.Engine.ContainerStart(context.Background(), container.ID, enginetypes.ContainerStartOptions{}) if err != nil { log.Errorf("[CreateContainerWithCPUPrior] Error when starting container, %v", err) ms[i].Error = err.Error() @@ -354,9 +340,7 @@ func (c *calcium) doCreateContainerWithCPUPrior(nodeName string, cpuMap []types. // TODO // if network manager uses our own, then connect must be called after container starts // here - ctxInspect, cancelInspect := context.WithTimeout(context.Background(), c.config.Timeout.CreateContainer) - defer cancelInspect() - info, err := node.Engine.ContainerInspect(ctxInspect, container.ID) + info, err := node.Engine.ContainerInspect(context.Background(), container.ID) if err != nil { log.Errorf("[CreateContainerWithCPUPrior] Error when inspecting container, %v", err) ms[i].Error = err.Error() @@ -366,7 +350,7 @@ func (c *calcium) doCreateContainerWithCPUPrior(nodeName string, cpuMap []types. ms[i].ContainerID = info.ID // after start - if err := runExec(node.Engine, info, AFTER_START, c.config.Timeout.CreateContainer); err != nil { + if err := runExec(node.Engine, info, AFTER_START); err != nil { log.Errorf("[CreateContainerWithCPUPrior] Run exec at %s error: %v", AFTER_START, err) } diff --git a/cluster/calcium/helper.go b/cluster/calcium/helper.go index 271367e40..562a28aaf 100644 --- a/cluster/calcium/helper.go +++ b/cluster/calcium/helper.go @@ -8,7 +8,6 @@ import ( "os" "path/filepath" "strings" - "time" log "github.com/Sirupsen/logrus" enginetypes "github.com/docker/docker/api/types" @@ -188,7 +187,7 @@ func makeMountPaths(specs types.Specs, config types.Config) ([]string, map[strin // 跑存在labels里的exec // 为什么要存labels呢, 因为下线容器的时候根本不知道entrypoint是啥 -func runExec(client *engineapi.Client, container enginetypes.ContainerJSON, label string, timeout time.Duration) error { +func runExec(client *engineapi.Client, container enginetypes.ContainerJSON, label string) error { cmd, ok := container.Config.Labels[label] if !ok || cmd == "" { log.Debugf("No %s found in container %s", label, container.ID) @@ -197,14 +196,10 @@ func runExec(client *engineapi.Client, container enginetypes.ContainerJSON, labe cmds := utils.MakeCommandLineArgs(cmd) execConfig := enginetypes.ExecConfig{User: container.Config.User, Cmd: cmds} - ctxExec, cancelCreate := context.WithTimeout(context.Background(), timeout) - defer cancelCreate() - resp, err := client.ContainerExecCreate(ctxExec, container.ID, execConfig) + resp, err := client.ContainerExecCreate(context.Background(), container.ID, execConfig) if err != nil { log.Errorf("Error during runExec: %v", err) return err } - ctxStart, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - return client.ContainerExecStart(ctxStart, resp.ID, enginetypes.ExecStartCheck{}) + return client.ContainerExecStart(context.Background(), resp.ID, enginetypes.ExecStartCheck{}) } diff --git a/cluster/calcium/image.go b/cluster/calcium/image.go index 6f1c10dfd..a5178a68c 100644 --- a/cluster/calcium/image.go +++ b/cluster/calcium/image.go @@ -4,7 +4,6 @@ import ( "context" "strings" "sync" - "time" log "github.com/Sirupsen/logrus" enginetypes "github.com/docker/docker/api/types" @@ -63,7 +62,7 @@ func (c *calcium) cleanImage(podname, image string) error { wg.Add(1) go func(node *types.Node) { defer wg.Done() - if err := cleanImageOnNode(node, image, c.config.ImageCache, c.config.Timeout.RemoveImage); err != nil { + if err := cleanImageOnNode(node, image, c.config.ImageCache); err != nil { log.Errorf("cleanImageOnNode error: %s", err) } }(node) @@ -90,14 +89,12 @@ func (x imageList) Less(i, j int) bool { return x[i].Created > x[j].Created } // 清理一个node上的这个image // 只清理同名字不同tag的 // 并且保留最新的两个 -func cleanImageOnNode(node *types.Node, image string, count int, timeout time.Duration) error { +func cleanImageOnNode(node *types.Node, image string, count int) error { log.Debugf("[cleanImageOnNode] node: %s, image: %s", node.Name, strings.Split(image, ":")[0]) imgListFilter := filters.NewArgs() image = normalizeImage(image) imgListFilter.Add("reference", image) // 相同repo的image - ctxList, cancelList := context.WithTimeout(context.Background(), timeout) - defer cancelList() - images, err := node.Engine.ImageList(ctxList, enginetypes.ImageListOptions{Filters: imgListFilter}) + images, err := node.Engine.ImageList(context.Background(), enginetypes.ImageListOptions{Filters: imgListFilter}) if err != nil { return err } @@ -110,15 +107,13 @@ func cleanImageOnNode(node *types.Node, image string, count int, timeout time.Du log.Debugf("Delete Images: %v", images) for _, image := range images { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - _, err := node.Engine.ImageRemove(ctx, image.ID, enginetypes.ImageRemoveOptions{ + _, err := node.Engine.ImageRemove(context.Background(), image.ID, enginetypes.ImageRemoveOptions{ Force: false, PruneChildren: true, }) if err != nil { log.Errorf("[cleanImageOnNode] Node %s ImageRemove error: %s, imageID: %s", node.Name, err, image.ID) } - cancel() } return nil } diff --git a/cluster/calcium/meta_test.go b/cluster/calcium/meta_test.go index ec8976dad..142825762 100644 --- a/cluster/calcium/meta_test.go +++ b/cluster/calcium/meta_test.go @@ -15,7 +15,7 @@ import ( func TestListPods(t *testing.T) { store := &mockstore.MockStore{} config := types.Config{} - c := &calcium{store: store, config: config, scheduler: simplescheduler.New(), network: calico.New(config), source: gitlab.New(config)} + c := &calcium{store: store, config: config, scheduler: simplescheduler.New(), network: calico.New(), source: gitlab.New(config)} store.On("GetAllPods").Return([]*types.Pod{ &types.Pod{Name: "pod1", Desc: "desc1"}, @@ -36,7 +36,7 @@ func TestListPods(t *testing.T) { func TestAddPod(t *testing.T) { store := &mockstore.MockStore{} config := types.Config{} - c := &calcium{store: store, config: config, scheduler: simplescheduler.New(), network: calico.New(config), source: gitlab.New(config)} + c := &calcium{store: store, config: config, scheduler: simplescheduler.New(), network: calico.New(), source: gitlab.New(config)} store.On("AddPod", "pod1", "", "desc1").Return(&types.Pod{Name: "pod1", Favor: "MEM", Desc: "desc1"}, nil) store.On("AddPod", "pod2", "", "desc2").Return(nil, fmt.Errorf("Etcd Error")) @@ -55,7 +55,7 @@ func TestAddPod(t *testing.T) { func TestGetPods(t *testing.T) { store := &mockstore.MockStore{} config := types.Config{} - c := &calcium{store: store, config: config, scheduler: simplescheduler.New(), network: calico.New(config), source: gitlab.New(config)} + c := &calcium{store: store, config: config, scheduler: simplescheduler.New(), network: calico.New(), source: gitlab.New(config)} store.On("GetPod", "pod1").Return(&types.Pod{Name: "pod1", Desc: "desc1"}, nil).Once() store.On("GetPod", "pod2").Return(nil, fmt.Errorf("Not found")).Once() diff --git a/cluster/calcium/mock_test.go b/cluster/calcium/mock_test.go index 3f3cdc793..e9293fe0e 100644 --- a/cluster/calcium/mock_test.go +++ b/cluster/calcium/mock_test.go @@ -41,19 +41,15 @@ var ( Hub: "hub.testhub.com", HubPrefix: "apps", }, - Timeout: coretypes.TimeoutConfig{ - Common: 3, - }, Scheduler: coretypes.SchedConfig{ ShareBase: 10, MaxShare: -1, }, } - mockc *calcium - mockStore *mockstore.MockStore - err error - mockTimeoutError bool - specs = coretypes.Specs{ + mockc *calcium + mockStore *mockstore.MockStore + err error + specs = coretypes.Specs{ Appname: "root", Entrypoints: map[string]coretypes.Entrypoint{ "test": coretypes.Entrypoint{ @@ -291,7 +287,7 @@ func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) { } func initMockConfig() { - mockc, err = New(utils.SetTimeout(config)) + mockc, err = New(config) if err != nil { panic(err) } diff --git a/cluster/calcium/realloc.go b/cluster/calcium/realloc.go index 2e32a8371..830d37c6f 100644 --- a/cluster/calcium/realloc.go +++ b/cluster/calcium/realloc.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "sync" - "time" log "github.com/Sirupsen/logrus" enginecontainer "github.com/docker/docker/api/types/container" @@ -149,7 +148,7 @@ func (c *calcium) doUpdateContainerWithMemoryPrior( // CPUQuota not cpu newResource := c.makeMemoryPriorSetting(newMemory, float64(newCPUQuota)/float64(utils.CpuPeriodBase)) updateConfig := enginecontainer.UpdateConfig{Resources: newResource} - if err := reSetContainer(containerJSON.ID, node, updateConfig, c.config.Timeout.Realloc); err != nil { + if err := reSetContainer(containerJSON.ID, node, updateConfig); err != nil { log.Errorf("[realloc] update container failed %v, %s", err, containerJSON.ID) ch <- &types.ReallocResourceMessage{ContainerID: containerJSON.ID, Success: false} // 如果是增加内存,失败的时候应该把内存还回去 @@ -258,7 +257,7 @@ func (c *calcium) doReallocContainersWithCPUPrior( for index, container := range containers { resource := c.makeCPUPriorSetting(cpuset[index]) updateConfig := enginecontainer.UpdateConfig{Resources: resource} - if err := reSetContainer(container.ID, node, updateConfig, c.config.Timeout.Realloc); err != nil { + if err := reSetContainer(container.ID, node, updateConfig); err != nil { log.Errorf("[realloc] update container failed %v", err) // TODO 这里理论上是可以恢复 CPU 占用表的,一来我们知道新的占用是怎样,二来我们也晓得老的占用是啥样 ch <- &types.ReallocResourceMessage{ContainerID: container.ID, Success: false} @@ -268,9 +267,7 @@ func (c *calcium) doReallocContainersWithCPUPrior( } } -func reSetContainer(ID string, node *types.Node, config enginecontainer.UpdateConfig, timeout time.Duration) error { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - _, err := node.Engine.ContainerUpdate(ctx, ID, config) +func reSetContainer(ID string, node *types.Node, config enginecontainer.UpdateConfig) error { + _, err := node.Engine.ContainerUpdate(context.Background(), ID, config) return err } diff --git a/cluster/calcium/remove_container.go b/cluster/calcium/remove_container.go index dc5a14771..dd903eb15 100644 --- a/cluster/calcium/remove_container.go +++ b/cluster/calcium/remove_container.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "sync" + "time" log "github.com/Sirupsen/logrus" enginetypes "github.com/docker/docker/api/types" @@ -141,12 +142,13 @@ func (c *calcium) removeOneContainer(container *types.Container, info enginetype }() // before stop - if err := runExec(container.Engine, info, BEFORE_STOP, c.config.Timeout.RemoveContainer); err != nil { + if err := runExec(container.Engine, info, BEFORE_STOP); err != nil { log.Errorf("Run exec at %s error: %s", BEFORE_STOP, err.Error()) } - // FUXK docker - err = container.Engine.ContainerStop(context.Background(), info.ID, &c.config.Timeout.RemoveContainer) + // 一分钟还停不下来的话, 就好自为之吧 + timeout := time.Minute * 2 + err = container.Engine.ContainerStop(context.Background(), info.ID, &timeout) if err != nil { log.Errorf("Error during ContainerStop: %s", err.Error()) return err @@ -156,9 +158,7 @@ func (c *calcium) removeOneContainer(container *types.Container, info enginetype RemoveVolumes: true, Force: true, } - ctxRemove, cancelRemove := context.WithTimeout(context.Background(), c.config.Timeout.RemoveContainer) - defer cancelRemove() - err = container.Engine.ContainerRemove(ctxRemove, info.ID, rmOpts) + err = container.Engine.ContainerRemove(context.Background(), info.ID, rmOpts) if err != nil { log.Errorf("Error during ContainerRemove: %s", err.Error()) return err diff --git a/cluster/calcium/remove_image.go b/cluster/calcium/remove_image.go index d9f211aea..d1ddd33e6 100644 --- a/cluster/calcium/remove_image.go +++ b/cluster/calcium/remove_image.go @@ -35,8 +35,7 @@ func (c *calcium) RemoveImage(podname, nodename string, images []string) (chan * messages := []string{} success := true - ctx, cancel := context.WithTimeout(context.Background(), c.config.Timeout.RemoveImage) - ms, err := node.Engine.ImageRemove(ctx, image, opts) + ms, err := node.Engine.ImageRemove(context.Background(), image, opts) if err != nil { success = false messages = append(messages, err.Error()) @@ -50,7 +49,6 @@ func (c *calcium) RemoveImage(podname, nodename string, images []string) (chan * } } } - cancel() ch <- &types.RemoveImageMessage{ Image: image, Success: success, diff --git a/cluster/calcium/run_and_wait.go b/cluster/calcium/run_and_wait.go index 83a9c4545..9e0e8cd72 100644 --- a/cluster/calcium/run_and_wait.go +++ b/cluster/calcium/run_and_wait.go @@ -22,11 +22,9 @@ func (c *calcium) RunAndWait(specs types.Specs, opts *types.DeployOptions, stdin entry.LogConfig = "journald" specs.Entrypoints[opts.Entrypoint] = entry - // 默认给出1200秒的超时时间吧 - // 没别的地方好传了, 不如放这里好了, 不需要用的就默认0或者不传 - waitTimeout := c.config.Timeout.RunAndWait - if entry.RunAndWaitTimeout != 0 { - waitTimeout = time.Duration(entry.RunAndWaitTimeout) * time.Second + waitTimeout := time.Duration(entry.RunAndWaitTimeout) * time.Second + if waitTimeout == 0 { + waitTimeout = time.Minute * 2 } // count = 1 && OpenStdin @@ -77,9 +75,7 @@ func (c *calcium) RunAndWait(specs types.Specs, opts *types.DeployOptions, stdin defer log.Infof("[RunAndWait] Container %s finished and removed", containerID[:12]) defer c.removeContainerSync([]string{containerID}) - ctx, cancel := context.WithTimeout(context.Background(), waitTimeout) - defer cancel() - resp, err := node.Engine.ContainerLogs(ctx, containerID, logsOpts) + resp, err := node.Engine.ContainerLogs(context.Background(), containerID, logsOpts) if err != nil { log.Errorf("[RunAndWait] Failed to get logs, %v", err) ch <- &types.RunAndWaitMessage{ContainerID: containerID, diff --git a/core.yaml.sample b/core.yaml.sample index 62d06a684..7a5e98d4b 100644 --- a/core.yaml.sample +++ b/core.yaml.sample @@ -39,13 +39,3 @@ syslog: address: "udp://localhost:5111" facility: "daemon" format: "rfc5424" - -timeout: - run_and_wait: 12 - build_image: 6 - create_container: 6 - remove_container: 6 - remove_image: 6 - backup: 6 - common: 6 - realloc: 6 diff --git a/network/calico/plugin.go b/network/calico/plugin.go index 767e87a54..e1827bc82 100644 --- a/network/calico/plugin.go +++ b/network/calico/plugin.go @@ -13,9 +13,7 @@ import ( "gitlab.ricebook.net/platform/core/utils" ) -type titanium struct { - Timeout types.TimeoutConfig -} +type titanium struct{} // type of the network manager // if set to "plugin", then it will act like a plugin @@ -56,9 +54,7 @@ func (t *titanium) ConnectToNetwork(ctx context.Context, containerID, networkID, } log.Debugf("Connect %q to %q with IP %q", containerID, networkID, ipv4) - ctx, cancel := context.WithTimeout(context.Background(), t.Timeout.Common) - defer cancel() - return engine.NetworkConnect(ctx, networkID, containerID, config) + return engine.NetworkConnect(context.Background(), networkID, containerID, config) } // disconnect from network @@ -73,9 +69,7 @@ func (t *titanium) DisconnectFromNetwork(ctx context.Context, containerID, netwo } log.Debugf("Disconnect %q from %q", containerID, networkID) - ctx, cancel := context.WithTimeout(context.Background(), t.Timeout.Common) - defer cancel() - return engine.NetworkDisconnect(ctx, networkID, containerID, false) + return engine.NetworkDisconnect(context.Background(), networkID, containerID, false) } // list networks from context @@ -86,12 +80,9 @@ func (t *titanium) ListNetworks(ctx context.Context) ([]*types.Network, error) { return networks, fmt.Errorf("Not actually a `engineapi.Client` for value engine in context") } - ctx, cancel := context.WithTimeout(context.Background(), t.Timeout.Common) - defer cancel() - filters := enginefilters.NewArgs() filters.Add("driver", t.Name()) - ns, err := engine.NetworkList(ctx, enginetypes.NetworkListOptions{Filters: filters}) + ns, err := engine.NetworkList(context.Background(), enginetypes.NetworkListOptions{Filters: filters}) if err != nil { return networks, err } @@ -106,6 +97,6 @@ func (t *titanium) ListNetworks(ctx context.Context) ([]*types.Network, error) { return networks, nil } -func New(config types.Config) *titanium { - return &titanium{Timeout: config.Timeout} +func New() *titanium { + return &titanium{} } diff --git a/types/config.go b/types/config.go index 52e9201d8..6910d74f3 100644 --- a/types/config.go +++ b/types/config.go @@ -1,7 +1,5 @@ package types -import "time" - // Config holds eru-core config type Config struct { Bind string `yaml:"bind"` // HTTP API address @@ -15,11 +13,10 @@ type Config struct { Zone string `yaml:"zone"` // zone for core, e.g. C1, C2 ImageCache int `yaml:"image_cache"` // cache image count - Git GitConfig `yaml:"git"` - Docker DockerConfig `yaml:"docker"` - Scheduler SchedConfig `yaml:"scheduler"` - Syslog SyslogConfig `yaml:"syslog"` - Timeout TimeoutConfig `yaml:"timeout"` + Git GitConfig `yaml:"git"` + Docker DockerConfig `yaml:"docker"` + Scheduler SchedConfig `yaml:"scheduler"` + Syslog SyslogConfig `yaml:"syslog"` } // GitConfig holds eru-core git config @@ -57,14 +54,3 @@ type SyslogConfig struct { Facility string `yaml:"facility"` Format string `yaml:"format"` } - -type TimeoutConfig struct { - RunAndWait time.Duration `yaml:"run_and_wait"` - BuildImage time.Duration `yaml:"build_image"` - CreateContainer time.Duration `yaml:"create_container"` - RemoveContainer time.Duration `yaml:"remove_container"` - RemoveImage time.Duration `yaml:"remove_image"` - Backup time.Duration `yaml:"backup"` - Realloc time.Duration `yaml:"realloc"` - Common time.Duration `yaml:"common"` -} diff --git a/utils/config.go b/utils/config.go index e03b8df1b..1aa3c0176 100644 --- a/utils/config.go +++ b/utils/config.go @@ -2,8 +2,6 @@ package utils import ( "io/ioutil" - "log" - "time" "gitlab.ricebook.net/platform/core/types" @@ -22,10 +20,6 @@ func LoadConfig(configPath string) (types.Config, error) { return config, err } - if config.Timeout.Common == 0 { - log.Fatal("Common timeout not set, exit") - } - if config.Docker.APIVersion == "" { config.Docker.APIVersion = "v1.23" } @@ -39,36 +33,5 @@ func LoadConfig(configPath string) (types.Config, error) { config.Scheduler.MaxShare = -1 } - return SetTimeout(config), nil -} - -func SetTimeout(config types.Config) types.Config { - ct := config.Timeout - - ct.Common *= time.Second - c := ct.Common - if ct.Backup *= time.Second; ct.Backup == 0 { - ct.Backup = c - } - if ct.BuildImage *= time.Second; ct.BuildImage == 0 { - ct.BuildImage = c - } - if ct.CreateContainer *= time.Second; ct.CreateContainer == 0 { - ct.CreateContainer = c - } - if ct.RemoveContainer *= time.Second; ct.RemoveContainer == 0 { - ct.RemoveContainer = c - } - if ct.RemoveImage *= time.Second; ct.RemoveImage == 0 { - ct.RemoveImage = c - } - if ct.RunAndWait *= time.Second; ct.RunAndWait == 0 { - ct.RunAndWait = c - } - if ct.Realloc *= time.Second; ct.Realloc == 0 { - ct.Realloc = c - } - - config.Timeout = ct - return config + return config, nil }