kubeadm: fix a bug that ImageExists check returns true when the image isn't in the local storage
This commit is contained in:
		| @@ -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, | ||||
| 		}, | ||||
| 		{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 SataQiu
					SataQiu