mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
kubeadm: fix a bug that ImageExists check returns true when the image isn't in the local storage
This commit is contained in:
parent
5b49afa66b
commit
69a2bebc70
@ -229,8 +229,15 @@ func pullImagesInParallelImpl(images []string, ifNotPresent bool,
|
|||||||
func (runtime *CRIRuntime) ImageExists(image string) bool {
|
func (runtime *CRIRuntime) ImageExists(image string) bool {
|
||||||
ctx, cancel := defaultContext()
|
ctx, cancel := defaultContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_, err := runtime.impl.ImageStatus(ctx, runtime.imageService, &runtimeapi.ImageSpec{Image: image}, false)
|
resp, err := runtime.impl.ImageStatus(ctx, runtime.imageService, &runtimeapi.ImageSpec{Image: image}, false)
|
||||||
return err == nil
|
if err != nil {
|
||||||
|
klog.Warningf("Failed to get image status, image: %q, error: %v", image, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if resp == nil || resp.Image == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// detectCRISocketImpl is separated out only for test purposes, DON'T call it directly, use DetectCRISocket instead
|
// detectCRISocketImpl is separated out only for test purposes, DON'T call it directly, use DetectCRISocket instead
|
||||||
|
@ -320,6 +320,11 @@ func TestImageExists(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "valid",
|
name: "valid",
|
||||||
|
prepare: func(mock *fakeImpl) {
|
||||||
|
mock.ImageStatusReturns(&v1.ImageStatusResponse{
|
||||||
|
Image: &v1.Image{},
|
||||||
|
}, nil)
|
||||||
|
},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user