Skip to content

Commit 78f2850

Browse files
Update hook-bootkit:
Update go.mod dependencies. Check for tink-worker image and don't fail the image pull if it doesn't exist. With embedded images, the tink worker could potentially already exist in the local Docker image cache. And the image name could be something unreachable via the network (for example: 127.0.0.1/embedded/tink-worker). Signed-off-by: Jacob Weinstock <[email protected]>
1 parent 50cdc1d commit 78f2850

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

images/hook-bootkit/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21-alpine AS dev
1+
FROM golang:1.22.6-alpine AS dev
22
COPY . /src/
33
WORKDIR /src
44
RUN go mod download

images/hook-bootkit/go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/tinkerbell/hook/hook-bootkit
22

3-
go 1.17
3+
go 1.22
4+
5+
toolchain go1.22.6
46

57
require (
68
github.com/cenkalti/backoff/v4 v4.3.0

images/hook-bootkit/main.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"time"
1616

1717
"github.com/cenkalti/backoff/v4"
18-
"github.com/docker/docker/api/types"
1918
"github.com/docker/docker/api/types/container"
19+
"github.com/docker/docker/api/types/image"
2020
"github.com/docker/docker/api/types/mount"
2121
"github.com/docker/docker/api/types/registry"
2222
"github.com/docker/docker/client"
@@ -127,13 +127,22 @@ func run(ctx context.Context, log logr.Logger) error {
127127

128128
authStr := base64.URLEncoding.EncodeToString(encodedJSON)
129129

130-
pullOpts := types.ImagePullOptions{
130+
pullOpts := image.PullOptions{
131131
RegistryAuth: authStr,
132132
}
133133
var out io.ReadCloser
134134
imagePullOperation := func() error {
135+
// with embedded images, the tink worker could potentially already exist
136+
// in the local Docker image cache. And the image name could be something
137+
// unreachable via the network (for example: 127.0.0.1/embedded/tink-worker).
138+
// Because of this we check if the image already exists and don't return an
139+
// error if the image does not exist and the pull fails.
140+
var imageExists bool
141+
if _, _, err := cli.ImageInspectWithRaw(ctx, imageName); err == nil {
142+
imageExists = true
143+
}
135144
out, err = cli.ImagePull(ctx, imageName, pullOpts)
136-
if err != nil {
145+
if err != nil && !imageExists {
137146
log.Error(err, "image pull failure", "imageName", imageName)
138147
return err
139148
}
@@ -143,18 +152,20 @@ func run(ctx context.Context, log logr.Logger) error {
143152
return err
144153
}
145154

146-
buf := bufio.NewScanner(out)
147-
for buf.Scan() {
148-
structured := make(map[string]interface{})
149-
if err := json.Unmarshal(buf.Bytes(), &structured); err != nil {
150-
log.Info("image pull logs", "output", buf.Text())
151-
} else {
152-
log.Info("image pull logs", "logs", structured)
153-
}
155+
if out != nil {
156+
buf := bufio.NewScanner(out)
157+
for buf.Scan() {
158+
structured := make(map[string]interface{})
159+
if err := json.Unmarshal(buf.Bytes(), &structured); err != nil {
160+
log.Info("image pull logs", "output", buf.Text())
161+
} else {
162+
log.Info("image pull logs", "logs", structured)
163+
}
154164

155-
}
156-
if err := out.Close(); err != nil {
157-
log.Error(err, "closing image pull logs failed")
165+
}
166+
if err := out.Close(); err != nil {
167+
log.Error(err, "closing image pull logs failed")
168+
}
158169
}
159170

160171
log.Info("Removing any existing tink-worker container")

0 commit comments

Comments
 (0)