Skip to content

Commit 74208e1

Browse files
committed
Merge branch 'bug/timeout' into 'master'
pull image for as long as you like See merge request !140
2 parents c9a51ba + 2ad78ed commit 74208e1

File tree

4 files changed

+6
-88
lines changed

4 files changed

+6
-88
lines changed

cluster/calcium/create_container.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strconv"
88
"strings"
99
"sync"
10-
"time"
1110

1211
log "github.com/Sirupsen/logrus"
1312
enginetypes "github.com/docker/docker/api/types"
@@ -104,7 +103,7 @@ func (c *calcium) doCreateContainerWithMemoryPrior(nodeInfo types.NodeInfo, spec
104103
return ms
105104
}
106105

107-
if err := pullImage(node, opts.Image, c.config.Timeout.CreateContainer); err != nil {
106+
if err := pullImage(node, opts.Image); err != nil {
108107
for i := 0; i < nodeInfo.Deploy; i++ {
109108
if err != nil {
110109
log.Errorf("Error during pullImage %s for %s: %v", opts.Image, nodeInfo.Name, err)
@@ -279,7 +278,7 @@ func (c *calcium) doCreateContainerWithCPUPrior(nodeName string, cpuMap []types.
279278
return ms
280279
}
281280

282-
if err := pullImage(node, opts.Image, c.config.Timeout.CreateContainer); err != nil {
281+
if err := pullImage(node, opts.Image); err != nil {
283282
log.Errorf("Error during pullImage: %v", err)
284283
for i := 0; i < len(ms); i++ {
285284
ms[i].Error = err.Error()
@@ -566,13 +565,12 @@ func (c *calcium) makeContainerOptions(index int, quota types.CPUMap, specs type
566565

567566
// Pull an image
568567
// Blocks until it finishes.
569-
func pullImage(node *types.Node, image string, timeout time.Duration) error {
568+
func pullImage(node *types.Node, image string) error {
570569
log.Debugf("Pulling image %s", image)
571570
if image == "" {
572571
return fmt.Errorf("Goddamn empty image, WTF?")
573572
}
574-
ctx, cancel := context.WithTimeout(context.Background(), timeout)
575-
defer cancel()
573+
ctx := context.Background()
576574
outStream, err := node.Engine.ImagePull(ctx, image, enginetypes.ImagePullOptions{})
577575
if err != nil {
578576
log.Errorf("Error during pulling image %s: %v", image, err)

cluster/calcium/create_container_test.go

+1-41
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package calcium
33
import (
44
"fmt"
55
"testing"
6-
"time"
76

87
"github.com/docker/docker/client"
98
"github.com/stretchr/testify/assert"
@@ -19,7 +18,7 @@ func TestPullImage(t *testing.T) {
1918
t.Fatal(err)
2019
}
2120

22-
if err := pullImage(nodes[0], image, 5*time.Second); err != nil {
21+
if err := pullImage(nodes[0], image); err != nil {
2322
t.Fatal(err)
2423
}
2524
}
@@ -90,42 +89,3 @@ func TestCreateContainerWithCPUPrior(t *testing.T) {
9089
fmt.Printf("Get Container ID: %s\n", msg.ContainerID)
9190
}
9291
}
93-
94-
func TestCreateContainerMemTimeoutError(t *testing.T) {
95-
initMockConfig()
96-
mockTimeoutError = true
97-
98-
// update node
99-
mockStore.On("UpdateNode", mock.MatchedBy(func(input *types.Node) bool {
100-
return true
101-
})).Return(nil)
102-
103-
// Create Container with memory prior
104-
testlogF("Create containers with memory prior")
105-
createCh, err := mockc.createContainerWithMemoryPrior(specs, opts)
106-
assert.NoError(t, err)
107-
for msg := range createCh {
108-
assert.False(t, msg.Success)
109-
assert.Contains(t, msg.Error, "context deadline exceeded")
110-
}
111-
112-
}
113-
114-
func TestCreateContainerCPUTimeoutError(t *testing.T) {
115-
initMockConfig()
116-
mockTimeoutError = true
117-
118-
// update node
119-
mockStore.On("UpdateNode", mock.MatchedBy(func(input *types.Node) bool {
120-
return true
121-
})).Return(nil)
122-
123-
// Create Container with cpu prior
124-
testlogF("Create containers with cpu prior")
125-
createCh, err := mockc.createContainerWithCPUPrior(specs, opts)
126-
assert.NoError(t, err)
127-
for msg := range createCh {
128-
assert.False(t, msg.Success)
129-
assert.Contains(t, msg.Error, "context deadline exceeded")
130-
}
131-
}

cluster/calcium/image.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (c *calcium) cacheImage(podname, image string) error {
3636
wg.Add(1)
3737
go func(node *types.Node) {
3838
defer wg.Done()
39-
pullImage(node, image, c.config.Timeout.CreateContainer)
39+
pullImage(node, image)
4040
}(node)
4141
}
4242

cluster/calcium/mock_test.go

-40
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,19 @@ package calcium
22

33
import (
44
"bytes"
5-
"context"
65
"encoding/base64"
76
"encoding/json"
87
"fmt"
9-
"io"
108
"io/ioutil"
119
"net/http"
1210
"runtime"
1311
"strings"
14-
"time"
1512

1613
"github.com/stretchr/testify/mock"
1714

1815
"github.com/docker/docker/api/types"
1916
"github.com/docker/docker/api/types/container"
2017
"github.com/docker/docker/client"
21-
"github.com/docker/docker/pkg/ioutils"
2218
"gitlab.ricebook.net/platform/core/store/mock"
2319
coretypes "gitlab.ricebook.net/platform/core/types"
2420
"gitlab.ricebook.net/platform/core/utils"
@@ -110,35 +106,6 @@ func mockContainerID() string {
110106
return utils.RandomString(64)
111107
}
112108

113-
func mockReadCloser(ctx context.Context) io.ReadCloser {
114-
pr, pw := io.Pipe()
115-
w := ioutils.NewWriteFlusher(pw)
116-
msgChan := make(chan string)
117-
118-
go func() {
119-
for {
120-
msgChan <- "pulling image...\n"
121-
time.Sleep(1000 * time.Millisecond)
122-
}
123-
}()
124-
go func() {
125-
for {
126-
select {
127-
case <-ctx.Done():
128-
testlogF("Error!! Context canceld!!!")
129-
w.Close()
130-
pw.Close()
131-
pr.Close()
132-
return
133-
case msg := <-msgChan:
134-
w.Write([]byte(msg))
135-
}
136-
}
137-
}()
138-
139-
return pr
140-
}
141-
142109
func mockDockerDoer(r *http.Request) (*http.Response, error) {
143110
var b []byte
144111
prefix := fmt.Sprintf("/%s", APIVersion)
@@ -176,13 +143,6 @@ func mockDockerDoer(r *http.Request) (*http.Response, error) {
176143
tag := query.Get("tag")
177144
testlogF("mock docker create image: %s:%s", fromImage, tag)
178145
b = []byte("body")
179-
if mockTimeoutError {
180-
ctx := r.Context()
181-
return &http.Response{
182-
StatusCode: http.StatusOK,
183-
Body: mockReadCloser(ctx),
184-
}, nil
185-
}
186146
case "/images/json": // docker images
187147
testlogF("mock docker list images")
188148
b, _ = json.Marshal([]types.ImageSummary{

0 commit comments

Comments
 (0)