mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #85965 from neolit123/revert-85603-PR008-kubeadm-dont-check-if-image-exists
Revert "kubeadm: don't check if image exists before pulling"
This commit is contained in:
commit
c9dafcddb7
@ -833,6 +833,14 @@ func (ImagePullCheck) Name() string {
|
|||||||
// Check pulls images required by kubeadm. This is a mutating check
|
// Check pulls images required by kubeadm. This is a mutating check
|
||||||
func (ipc ImagePullCheck) Check() (warnings, errorList []error) {
|
func (ipc ImagePullCheck) Check() (warnings, errorList []error) {
|
||||||
for _, image := range ipc.imageList {
|
for _, image := range ipc.imageList {
|
||||||
|
ret, err := ipc.runtime.ImageExists(image)
|
||||||
|
if ret && err == nil {
|
||||||
|
klog.V(1).Infof("image exists: %s", image)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
errorList = append(errorList, errors.Wrapf(err, "failed to check if image %s exists", image))
|
||||||
|
}
|
||||||
klog.V(1).Infof("pulling %s", image)
|
klog.V(1).Infof("pulling %s", image)
|
||||||
if err := ipc.runtime.PullImage(image); err != nil {
|
if err := ipc.runtime.PullImage(image); err != nil {
|
||||||
errorList = append(errorList, errors.Wrapf(err, "failed to pull image %s", image))
|
errorList = append(errorList, errors.Wrapf(err, "failed to pull image %s", image))
|
||||||
|
@ -753,20 +753,18 @@ func TestSetHasItemOrAll(t *testing.T) {
|
|||||||
func TestImagePullCheck(t *testing.T) {
|
func TestImagePullCheck(t *testing.T) {
|
||||||
fcmd := fakeexec.FakeCmd{
|
fcmd := fakeexec.FakeCmd{
|
||||||
RunScript: []fakeexec.FakeRunAction{
|
RunScript: []fakeexec.FakeRunAction{
|
||||||
// Test case 1: pull 3 images successfully
|
// Test case 1: img1 and img2 exist, img3 doesn't exist
|
||||||
func() ([]byte, []byte, error) { return nil, nil, nil },
|
|
||||||
func() ([]byte, []byte, error) { return nil, nil, nil },
|
func() ([]byte, []byte, error) { return nil, nil, nil },
|
||||||
func() ([]byte, []byte, error) { return nil, nil, nil },
|
func() ([]byte, []byte, error) { return nil, nil, nil },
|
||||||
|
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
|
|
||||||
// Test case 2: image pull errors
|
// Test case 2: images don't exist
|
||||||
func() ([]byte, []byte, error) { return nil, nil, nil },
|
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
|
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
|
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
|
||||||
},
|
},
|
||||||
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
|
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
|
||||||
// Test case1: pull 3 images
|
// Test case1: pull only img3
|
||||||
func() ([]byte, error) { return nil, nil },
|
|
||||||
func() ([]byte, error) { return nil, nil },
|
|
||||||
func() ([]byte, error) { return nil, nil },
|
func() ([]byte, error) { return nil, nil },
|
||||||
// Test case 2: fail to pull image2 and image3
|
// Test case 2: fail to pull image2 and image3
|
||||||
func() ([]byte, error) { return nil, nil },
|
func() ([]byte, error) { return nil, nil },
|
||||||
@ -783,6 +781,10 @@ 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...) },
|
||||||
},
|
},
|
||||||
LookPathFunc: func(cmd string) (string, error) { return "/usr/bin/docker", nil },
|
LookPathFunc: func(cmd string) (string, error) { return "/usr/bin/docker", nil },
|
||||||
}
|
}
|
||||||
@ -801,7 +803,7 @@ func TestImagePullCheck(t *testing.T) {
|
|||||||
t.Fatalf("did not expect any warnings but got %q", warnings)
|
t.Fatalf("did not expect any warnings but got %q", warnings)
|
||||||
}
|
}
|
||||||
if len(errors) != 0 {
|
if len(errors) != 0 {
|
||||||
t.Fatalf("expected 0 errors but got %d: %q", len(errors), errors)
|
t.Fatalf("expected 1 errors but got %d: %q", len(errors), errors)
|
||||||
}
|
}
|
||||||
|
|
||||||
warnings, errors = check.Check()
|
warnings, errors = check.Check()
|
||||||
|
Loading…
Reference in New Issue
Block a user