From 91ae9fa50d5583c579fd8388529c7022d28be9b0 Mon Sep 17 00:00:00 2001 From: wanyaoqi <18528551+wanyaoqi@users.noreply.github.com> Date: Wed, 5 Feb 2025 18:53:58 +0800 Subject: [PATCH] fix(host): check image desc is empty (#22057) image.inf record chksum or image id not matched will cause image desc empty --- pkg/hostman/hostinfo/hostinfo.go | 2 +- pkg/hostman/storageman/imagecache_local.go | 2 ++ pkg/hostman/storageman/imagecachemanager_local.go | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/hostman/hostinfo/hostinfo.go b/pkg/hostman/hostinfo/hostinfo.go index f0f210c561..3e4225bbba 100644 --- a/pkg/hostman/hostinfo/hostinfo.go +++ b/pkg/hostman/hostinfo/hostinfo.go @@ -2709,7 +2709,7 @@ func (h *SHostInfo) getProcessesPids(processesPrefix []string) (map[string]strin segs := strings.Split(cmdline, "\x00") if utils.IsInStringArray(segs[0], processesPrefix) { res[segs[0]] = f.Name() - log.Infof("getProcessesPids append %s %s", segs[0], f.Name()) + log.Debugf("getProcessesPids append %s %s", segs[0], f.Name()) } } } diff --git a/pkg/hostman/storageman/imagecache_local.go b/pkg/hostman/storageman/imagecache_local.go index 78773ed2fc..8a98d28984 100644 --- a/pkg/hostman/storageman/imagecache_local.go +++ b/pkg/hostman/storageman/imagecache_local.go @@ -150,6 +150,8 @@ func (l *SLocalImageCache) Load() error { if len(desc.Chksum) > 0 && len(desc.Id) > 0 && desc.Id == l.imageId { l.Desc = desc return nil + } else { + log.Errorf("image %s desc not correct, desc.Chksum %s desc.Id %s l.imageId %s", imgPath, desc.Chksum, desc.Id, l.imageId) } } diff --git a/pkg/hostman/storageman/imagecachemanager_local.go b/pkg/hostman/storageman/imagecachemanager_local.go index 4fb633b02f..38b08d8159 100644 --- a/pkg/hostman/storageman/imagecachemanager_local.go +++ b/pkg/hostman/storageman/imagecachemanager_local.go @@ -192,8 +192,11 @@ func (c *SLocalImageCacheManager) getTotalSize(ctx context.Context) (int64, map[ images := make(map[string]IImageCache) c.cachedImages.Range(func(imgId, imgObj any) bool { img := imgObj.(IImageCache) - total += img.GetDesc().SizeMb - images[imgId.(string)] = img + imgDesc := img.GetDesc() + if imgDesc != nil { + total += img.GetDesc().SizeMb + images[imgId.(string)] = img + } return true }) return total, images