From 254c3f7ffa0aa487771d7ba991df61622dd714ae Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Mon, 17 Jun 2024 09:58:42 +0600 Subject: [PATCH] fix(image): parse `Created` field only for non-empty values --- pkg/fanal/image/daemon/image.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/fanal/image/daemon/image.go b/pkg/fanal/image/daemon/image.go index 5d80cb93eee4..d3787cc0abc7 100644 --- a/pkg/fanal/image/daemon/image.go +++ b/pkg/fanal/image/daemon/image.go @@ -110,16 +110,25 @@ func (img *image) ConfigFile() (*v1.ConfigFile, error) { return nil, xerrors.Errorf("unable to get diff IDs: %w", err) } - created, err := time.Parse(time.RFC3339Nano, img.inspect.Created) - if err != nil { - return nil, xerrors.Errorf("failed parsing created %s: %w", img.inspect.Created, err) + var created v1.Time + // `Created` field can be empty. Skip parsing to avoid error. + // cf. https://github.com/moby/moby/blob/8e96db1c328d0467b015768e42a62c0f834970bb/api/types/types.go#L76-L77 + if img.inspect.Created != "" { + var t time.Time + t, err = time.Parse(time.RFC3339Nano, img.inspect.Created) + if err != nil { + return nil, xerrors.Errorf("failed parsing created %s: %w", img.inspect.Created, err) + } + created = v1.Time{ + Time: t, + } } return &v1.ConfigFile{ Architecture: img.inspect.Architecture, Author: img.inspect.Author, Container: img.inspect.Container, - Created: v1.Time{Time: created}, + Created: created, DockerVersion: img.inspect.DockerVersion, Config: img.imageConfig(img.inspect.Config), History: img.history,