Skip to content

Commit bfffdb9

Browse files
authored
Merge pull request #17671 from prezha/fix-containerd-ImageExists
fix containerd ImageExists to look for image name and image id sha
2 parents 638da15 + 199a0e3 commit bfffdb9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Diff for: pkg/minikube/cruntime/containerd.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ func (r *Containerd) Disable() error {
248248

249249
// ImageExists checks if image exists based on image name and optionally image sha
250250
func (r *Containerd) ImageExists(name string, sha string) bool {
251-
c := exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo ctr -n=k8s.io images check | grep %s", name))
252-
rr, err := r.Runner.RunCmd(c)
253-
if err != nil {
254-
return false
255-
}
256-
if sha != "" && !strings.Contains(rr.Output(), sha) {
251+
klog.Infof("Checking existence of image with name %q and sha %q", name, sha)
252+
c := exec.Command("sudo", "ctr", "-n=k8s.io", "images", "check")
253+
// note: image name and image id's sha can be on different lines in ctr output
254+
if rr, err := r.Runner.RunCmd(c); err != nil ||
255+
!strings.Contains(rr.Output(), name) ||
256+
(sha != "" && !strings.Contains(rr.Output(), sha)) {
257257
return false
258258
}
259259
return true

0 commit comments

Comments
 (0)