Skip to content

Commit c9dafcd

Browse files
authored
Merge pull request kubernetes#85965 from neolit123/revert-85603-PR008-kubeadm-dont-check-if-image-exists
Revert "kubeadm: don't check if image exists before pulling"
2 parents 4fe4ff8 + bc22d70 commit c9dafcd

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

cmd/kubeadm/app/preflight/checks.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,14 @@ func (ImagePullCheck) Name() string {
833833
// Check pulls images required by kubeadm. This is a mutating check
834834
func (ipc ImagePullCheck) Check() (warnings, errorList []error) {
835835
for _, image := range ipc.imageList {
836+
ret, err := ipc.runtime.ImageExists(image)
837+
if ret && err == nil {
838+
klog.V(1).Infof("image exists: %s", image)
839+
continue
840+
}
841+
if err != nil {
842+
errorList = append(errorList, errors.Wrapf(err, "failed to check if image %s exists", image))
843+
}
836844
klog.V(1).Infof("pulling %s", image)
837845
if err := ipc.runtime.PullImage(image); err != nil {
838846
errorList = append(errorList, errors.Wrapf(err, "failed to pull image %s", image))

cmd/kubeadm/app/preflight/checks_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -753,20 +753,18 @@ func TestSetHasItemOrAll(t *testing.T) {
753753
func TestImagePullCheck(t *testing.T) {
754754
fcmd := fakeexec.FakeCmd{
755755
RunScript: []fakeexec.FakeRunAction{
756-
// Test case 1: pull 3 images successfully
757-
func() ([]byte, []byte, error) { return nil, nil, nil },
756+
// Test case 1: img1 and img2 exist, img3 doesn't exist
758757
func() ([]byte, []byte, error) { return nil, nil, nil },
759758
func() ([]byte, []byte, error) { return nil, nil, nil },
759+
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
760760

761-
// Test case 2: image pull errors
762-
func() ([]byte, []byte, error) { return nil, nil, nil },
761+
// Test case 2: images don't exist
762+
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
763763
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
764764
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
765765
},
766766
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
767-
// Test case1: pull 3 images
768-
func() ([]byte, error) { return nil, nil },
769-
func() ([]byte, error) { return nil, nil },
767+
// Test case1: pull only img3
770768
func() ([]byte, error) { return nil, nil },
771769
// Test case 2: fail to pull image2 and image3
772770
func() ([]byte, error) { return nil, nil },
@@ -783,6 +781,10 @@ func TestImagePullCheck(t *testing.T) {
783781
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
784782
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
785783
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
784+
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
785+
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
786+
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
787+
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
786788
},
787789
LookPathFunc: func(cmd string) (string, error) { return "/usr/bin/docker", nil },
788790
}
@@ -801,7 +803,7 @@ func TestImagePullCheck(t *testing.T) {
801803
t.Fatalf("did not expect any warnings but got %q", warnings)
802804
}
803805
if len(errors) != 0 {
804-
t.Fatalf("expected 0 errors but got %d: %q", len(errors), errors)
806+
t.Fatalf("expected 1 errors but got %d: %q", len(errors), errors)
805807
}
806808

807809
warnings, errors = check.Check()

0 commit comments

Comments
 (0)