mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +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 {
|
||||
ctx, cancel := defaultContext()
|
||||
defer cancel()
|
||||
_, err := runtime.impl.ImageStatus(ctx, runtime.imageService, &runtimeapi.ImageSpec{Image: image}, false)
|
||||
return err == nil
|
||||
resp, err := runtime.impl.ImageStatus(ctx, runtime.imageService, &runtimeapi.ImageSpec{Image: image}, false)
|
||||
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
|
||||
|
@ -319,7 +319,12 @@ func TestImageExists(t *testing.T) {
|
||||
prepare func(*fakeImpl)
|
||||
}{
|
||||
{
|
||||
name: "valid",
|
||||
name: "valid",
|
||||
prepare: func(mock *fakeImpl) {
|
||||
mock.ImageStatusReturns(&v1.ImageStatusResponse{
|
||||
Image: &v1.Image{},
|
||||
}, nil)
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user