Skip to content

Commit 98f3c9b

Browse files
committed
Add parse for images
Signed-off-by: Vitor Savian <[email protected]>
1 parent 2a71842 commit 98f3c9b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ require (
166166
k8s.io/utils v0.0.0-20240902221715-702e33fdd3c3
167167
sigs.k8s.io/cri-tools v0.0.0-00010101000000-000000000000
168168
sigs.k8s.io/yaml v1.4.0
169+
github.com/google/go-containerregistry v0.20.2
169170
)
170171

171172
require (
@@ -272,7 +273,7 @@ require (
272273
github.com/google/cel-go v0.20.1 // indirect
273274
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
274275
github.com/google/go-cmp v0.6.0 // indirect
275-
github.com/google/go-containerregistry v0.20.2 // indirect
276+
276277
github.com/google/gofuzz v1.2.0 // indirect
277278
github.com/google/gopacket v1.1.19 // indirect
278279
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect

pkg/agent/containerd/containerd.go

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/containerd/containerd/pkg/cri/constants"
1919
"github.com/containerd/containerd/pkg/cri/labels"
2020
"github.com/containerd/containerd/reference/docker"
21+
reference "github.com/google/go-containerregistry/pkg/name"
2122
"github.com/k3s-io/k3s/pkg/agent/cri"
2223
util2 "github.com/k3s-io/k3s/pkg/agent/util"
2324
"github.com/k3s-io/k3s/pkg/daemons/config"
@@ -360,6 +361,12 @@ func prePullImages(ctx context.Context, client *containerd.Client, imageClient r
360361
for scanner.Scan() {
361362
name := strings.TrimSpace(scanner.Text())
362363

364+
// the options in the reference.ParseReference are for filtering only strings that cannot be seen as a possible image
365+
if _, err := reference.ParseReference(name, reference.WeakValidation, reference.Insecure); err != nil {
366+
logrus.Errorf("Unable to pull image %s: %v", name, err)
367+
continue
368+
}
369+
363370
if status, err := imageClient.ImageStatus(ctx, &runtimeapi.ImageStatusRequest{
364371
Image: &runtimeapi.ImageSpec{
365372
Image: name,

0 commit comments

Comments
 (0)