Skip to content

Commit a5d875c

Browse files
committed
chore(namespace): Add safety check for unexpected digest format
Signed-off-by: Park jungtae <[email protected]>
1 parent 0a3ac58 commit a5d875c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pkg/cmd/namespace/inspect.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package namespace
1818

1919
import (
2020
"context"
21-
"errors"
2221
"strings"
2322

2423
containerd "github.com/containerd/containerd/v2/client"
@@ -80,10 +79,6 @@ func Inspect(ctx context.Context, client *containerd.Client, inspectedNamespaces
8079
log.G(ctx).Warn(warn)
8180
}
8281

83-
if len(warns) != 0 {
84-
return errors.New("some namespaces could not be inspected")
85-
}
86-
8782
return nil
8883
}
8984
func containerInfo(ctx context.Context, client *containerd.Client) (native.ContainerInfo, error) {
@@ -111,13 +106,18 @@ func imageInfo(ctx context.Context, client *containerd.Client) (native.ImageInfo
111106
return info, err
112107
}
113108

114-
info.Count = len(images)
115-
ids := make([]string, info.Count)
116-
109+
ids := make([]string, 0, len(images))
117110
info.IDs = ids
118-
for idx, img := range images {
119-
ids[idx] = strings.Split(img.Target.Digest.String(), ":")[1]
111+
112+
for _, img := range images {
113+
digestStrSplit := strings.SplitN(img.Target.Digest.String(), ":", 2)
114+
if len(digestStrSplit) == 2 {
115+
ids = append(ids, digestStrSplit[1][:12])
116+
} else {
117+
log.G(ctx).Warnf("invalid image digest format:%s", img.Target.Digest.String())
118+
}
120119
}
120+
info.Count = len(ids)
121121

122122
return info, nil
123123
}

0 commit comments

Comments
 (0)