mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #86899 from SataQiu/enable-pull-retry-20200107
kubeadm: support automatic retry after failing to pull image
This commit is contained in:
commit
3e8155ead3
@ -181,6 +181,8 @@ const (
|
|||||||
PatchNodeTimeout = 2 * time.Minute
|
PatchNodeTimeout = 2 * time.Minute
|
||||||
// TLSBootstrapTimeout specifies how long kubeadm should wait for the kubelet to perform the TLS Bootstrap
|
// TLSBootstrapTimeout specifies how long kubeadm should wait for the kubelet to perform the TLS Bootstrap
|
||||||
TLSBootstrapTimeout = 2 * time.Minute
|
TLSBootstrapTimeout = 2 * time.Minute
|
||||||
|
// PullImageRetry specifies how many times ContainerRuntime retries when pulling image failed
|
||||||
|
PullImageRetry = 5
|
||||||
// PrepullImagesInParallelTimeout specifies how long kubeadm should wait for prepulling images in parallel before timing out
|
// PrepullImagesInParallelTimeout specifies how long kubeadm should wait for prepulling images in parallel before timing out
|
||||||
PrepullImagesInParallelTimeout = 10 * time.Second
|
PrepullImagesInParallelTimeout = 10 * time.Second
|
||||||
|
|
||||||
|
@ -762,9 +762,18 @@ func TestImagePullCheck(t *testing.T) {
|
|||||||
// Test case1: pull only img3
|
// Test case1: pull only img3
|
||||||
func() ([]byte, []byte, error) { return nil, nil, nil },
|
func() ([]byte, []byte, error) { return nil, nil, nil },
|
||||||
// Test case 2: fail to pull image2 and image3
|
// Test case 2: fail to pull image2 and image3
|
||||||
|
// If the pull fails, it will be retried 5 times (see PullImageRetry in constants/constants.go)
|
||||||
func() ([]byte, []byte, error) { return nil, nil, nil },
|
func() ([]byte, []byte, error) { return nil, nil, nil },
|
||||||
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -780,6 +789,14 @@ func TestImagePullCheck(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
LookPathFunc: func(cmd string) (string, error) { return "/usr/bin/docker", nil },
|
LookPathFunc: func(cmd string) (string, error) { return "/usr/bin/docker", nil },
|
||||||
}
|
}
|
||||||
|
@ -151,20 +151,28 @@ func (runtime *DockerRuntime) RemoveContainers(containers []string) error {
|
|||||||
|
|
||||||
// PullImage pulls the image
|
// PullImage pulls the image
|
||||||
func (runtime *CRIRuntime) PullImage(image string) error {
|
func (runtime *CRIRuntime) PullImage(image string) error {
|
||||||
out, err := runtime.exec.Command("crictl", "-r", runtime.criSocket, "pull", image).CombinedOutput()
|
var err error
|
||||||
if err != nil {
|
var out []byte
|
||||||
return errors.Wrapf(err, "output: %s, error", string(out))
|
for i := 0; i < constants.PullImageRetry; i++ {
|
||||||
|
out, err = runtime.exec.Command("crictl", "-r", runtime.criSocket, "pull", image).CombinedOutput()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return errors.Wrapf(err, "output: %s, error", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PullImage pulls the image
|
// PullImage pulls the image
|
||||||
func (runtime *DockerRuntime) PullImage(image string) error {
|
func (runtime *DockerRuntime) PullImage(image string) error {
|
||||||
out, err := runtime.exec.Command("docker", "pull", image).CombinedOutput()
|
var err error
|
||||||
if err != nil {
|
var out []byte
|
||||||
return errors.Wrapf(err, "output: %s, error", string(out))
|
for i := 0; i < constants.PullImageRetry; i++ {
|
||||||
|
out, err = runtime.exec.Command("docker", "pull", image).CombinedOutput()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return errors.Wrapf(err, "output: %s, error", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImageExists checks to see if the image exists on the system
|
// ImageExists checks to see if the image exists on the system
|
||||||
|
@ -229,8 +229,18 @@ func TestPullImage(t *testing.T) {
|
|||||||
fcmd := fakeexec.FakeCmd{
|
fcmd := fakeexec.FakeCmd{
|
||||||
CombinedOutputScript: []fakeexec.FakeAction{
|
CombinedOutputScript: []fakeexec.FakeAction{
|
||||||
func() ([]byte, []byte, error) { return nil, nil, nil },
|
func() ([]byte, []byte, error) { return nil, nil, nil },
|
||||||
|
// If the pull fails, it will be retried 5 times (see PullImageRetry in constants/constants.go)
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
func() ([]byte, []byte, error) { return nil, nil, nil },
|
func() ([]byte, []byte, error) { return nil, nil, nil },
|
||||||
|
// If the pull fails, it will be retried 5 times (see PullImageRetry in constants/constants.go)
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
func() ([]byte, []byte, error) { return []byte("error"), nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user