Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle docker/docker v28 API breaking change #2073

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions pkg/v1/daemon/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package daemon
import (
"bytes"
"context"
"fmt"
"io"
"sync"
"time"
Expand Down Expand Up @@ -234,9 +235,20 @@ func (i *image) LayerByDiffID(h v1.Hash) (v1.Layer, error) {
}

func (i *image) configHistory(author string) ([]v1.History, error) {
historyItems, err := i.opener.client.ImageHistory(i.opener.ctx, i.ref.String())
if err != nil {
return nil, err
var historyItems []api.HistoryResponseItem
var err error
if pre28, ok := i.opener.client.(clientPre28); ok {
historyItems, err = pre28.ImageHistory(i.opener.ctx, i.ref.String())
if err != nil {
return nil, err
}
} else if post28, ok := i.opener.client.(clientPost28); ok {
historyItems, err = post28.ImageHistory(i.opener.ctx, i.ref.String())
if err != nil {
return nil, err
}
} else {
return nil, fmt.Errorf("client does not implement ImageHistory: %T", i.opener.client)
}

history := make([]v1.History, len(historyItems))
Expand Down
12 changes: 12 additions & 0 deletions pkg/v1/daemon/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,17 @@ type Client interface {
ImageLoad(context.Context, io.Reader, ...client.ImageLoadOption) (api.LoadResponse, error)
ImageTag(context.Context, string, string) error
ImageInspectWithRaw(context.Context, string) (api.InspectResponse, []byte, error)
}

// https://github.com/google/go-containerregistry/issues/2072
// Docker v28.0 changed the API signature for ImageHistory, in ways that broke callers dependent on the old signature.
// This is a temporary workaround to allow the daemon package to work with both pre- and post-28.0 clients.
// After some time, we can remove this workaround and require a post-28.0 client with the variadic args.

type clientPre28 interface {
ImageHistory(context.Context, string) ([]api.HistoryResponseItem, error)
}

type clientPost28 interface {
ImageHistory(context.Context, string, ...client.ImageHistoryOption) ([]api.HistoryResponseItem, error)
}
Loading