Skip to content

Commit 5948cf4

Browse files
authored
Update docker client dependency (#1877)
* chore: update docker client lib Signed-off-by: Matej Vasek <[email protected]> * fixup: "host" OCI pusher Signed-off-by: Matej Vasek <[email protected]> * fixup: downgrade github.com/containers/image/v5 Signed-off-by: Matej Vasek <[email protected]> * fixup: platform tests Signed-off-by: Matej Vasek <[email protected]> --------- Signed-off-by: Matej Vasek <[email protected]>
1 parent 36489f3 commit 5948cf4

File tree

1,304 files changed

+49368
-48417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,304 files changed

+49368
-48417
lines changed

go.mod

Lines changed: 82 additions & 78 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 183 additions & 1229 deletions
Large diffs are not rendered by default.

pkg/docker/docker_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func NewClient(defaultHost string) (dockerClient client.CommonAPIClient, dockerH
9797
}
9898

9999
if !isSSH {
100-
opts := []client.Opt{client.FromEnv}
100+
opts := []client.Opt{client.FromEnv, client.WithAPIVersionNegotiation()}
101101
if isTCP {
102102
if httpClient := newHttpClient(); httpClient != nil {
103103
opts = append(opts, client.WithHTTPClient(httpClient))

pkg/docker/platform_test.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"github.com/google/go-containerregistry/pkg/v1/empty"
1717
"github.com/google/go-containerregistry/pkg/v1/mutate"
1818
"github.com/google/go-containerregistry/pkg/v1/remote"
19-
gcrTypes "github.com/google/go-containerregistry/pkg/v1/types"
20-
2119
"knative.dev/func/pkg/docker"
2220
)
2321

@@ -52,16 +50,9 @@ func TestPlatform(t *testing.T) {
5250
t.Fatal(err)
5351
}
5452

55-
zeroHash := v1.Hash{
56-
Algorithm: "sha256",
57-
Hex: "0000000000000000000000000000000000000000000000000000000000000000",
58-
}
59-
6053
var imgIdx = mutate.AppendManifests(empty.Index, mutate.IndexAddendum{
61-
Add: empty.Index,
54+
Add: img,
6255
Descriptor: v1.Descriptor{
63-
MediaType: gcrTypes.DockerManifestList,
64-
Digest: zeroHash,
6556
Platform: &v1.Platform{
6657
Architecture: "ppc64le",
6758
OS: "linux",
@@ -99,8 +90,13 @@ func TestPlatform(t *testing.T) {
9990
if err != nil {
10091
t.Errorf("unexpeced error: %v", err)
10192
}
102-
if ref != testRegistry+"/default/builder@sha256:0000000000000000000000000000000000000000000000000000000000000000" {
103-
t.Error("incorrect reference")
93+
94+
imgDigest, err := img.Digest()
95+
if err != nil {
96+
t.Fatal(err)
97+
}
98+
if ref != testRegistry+"/default/builder@"+imgDigest.String() {
99+
t.Errorf("incorrect reference: %q", ref)
104100
}
105101
}
106102

@@ -118,7 +114,7 @@ func startRegistry(t *testing.T) (addr string) {
118114

119115
go func() {
120116
err = s.Serve(l)
121-
if err != nil && !errors.Is(err, net.ErrClosed) {
117+
if err != nil && !errors.Is(err, http.ErrServerClosed) {
122118
fmt.Fprintln(os.Stderr, "ERROR: ", err)
123119
}
124120
}()

pkg/docker/pusher.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
fn "knative.dev/func/pkg/functions"
1717

1818
"github.com/docker/docker/api/types"
19+
"github.com/docker/docker/api/types/registry"
1920
"github.com/docker/docker/client"
2021
"github.com/docker/docker/pkg/jsonmessage"
2122
"github.com/google/go-containerregistry/pkg/authn"
@@ -157,7 +158,7 @@ func (n *Pusher) daemonPush(ctx context.Context, f fn.Function, credentials Cred
157158
}
158159
defer cli.Close()
159160

160-
authConfig := types.AuthConfig{
161+
authConfig := registry.AuthConfig{
161162
Username: credentials.Username,
162163
Password: credentials.Password,
163164
}

pkg/docker/pusher_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"crypto/x509/pkix"
1515
"encoding/base64"
1616
"encoding/json"
17+
"errors"
1718
"fmt"
1819
"io"
1920
"log"
@@ -27,6 +28,7 @@ import (
2728
"time"
2829

2930
"github.com/docker/docker/api/types"
31+
api "github.com/docker/docker/api/types/image"
3032
"github.com/google/go-containerregistry/pkg/authn"
3133
"github.com/google/go-containerregistry/pkg/name"
3234
"github.com/google/go-containerregistry/pkg/registry"
@@ -316,6 +318,10 @@ func (m *mockPusherDockerClient) ImagePush(ctx context.Context, ref string, opti
316318
return m.imagePush(ctx, ref, options)
317319
}
318320

321+
func (m *mockPusherDockerClient) ImageHistory(context.Context, string) ([]api.HistoryResponseItem, error) {
322+
return nil, errors.New("the ImageHistory() function is not implemented")
323+
}
324+
319325
func (m *mockPusherDockerClient) Close() error {
320326
return m.close()
321327
}

pkg/docker/runner.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (n *Runner) Run(ctx context.Context, f fn.Function, startTimeout time.Durat
6060

6161
// Channels for gathering runtime errors from the container instance
6262
copyErrCh = make(chan error, 10)
63-
contBodyCh <-chan container.ContainerWaitOKBody
63+
contBodyCh <-chan container.WaitResponse
6464
contErrCh <-chan error
6565

6666
// Combined runtime error channel for sending all errors to caller
@@ -116,7 +116,11 @@ func (n *Runner) Run(ctx context.Context, f fn.Function, startTimeout time.Durat
116116
timeout = DefaultStopTimeout
117117
ctx = context.Background()
118118
)
119-
if err = c.ContainerStop(ctx, id, &timeout); err != nil {
119+
timeoutSecs := int(timeout.Seconds())
120+
ctrStopOpts := container.StopOptions{
121+
Timeout: &timeoutSecs,
122+
}
123+
if err = c.ContainerStop(ctx, id, ctrStopOpts); err != nil {
120124
return fmt.Errorf("error stopping container %v: %v\n", id, err)
121125
}
122126
if err = c.ContainerRemove(ctx, id, types.ContainerRemoveOptions{}); err != nil {

pkg/docker/zz_close_guarding_client_generated.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"io"
66
"net"
77
"net/http"
8-
"time"
98

109
"github.com/docker/docker/api/types"
1110
"github.com/docker/docker/api/types/container"
@@ -109,7 +108,7 @@ func (c *closeGuardingClient) ContainerCommit(arg0 context.Context, arg1 string,
109108
return c.pimpl.ContainerCommit(arg0, arg1, arg2)
110109
}
111110

112-
func (c *closeGuardingClient) ContainerCreate(arg0 context.Context, arg1 *container.Config, arg2 *container.HostConfig, arg3 *network.NetworkingConfig, arg4 *v1.Platform, arg5 string) (container.ContainerCreateCreatedBody, error) {
111+
func (c *closeGuardingClient) ContainerCreate(arg0 context.Context, arg1 *container.Config, arg2 *container.HostConfig, arg3 *network.NetworkingConfig, arg4 *v1.Platform, arg5 string) (container.CreateResponse, error) {
113112
c.m.RLock()
114113
defer c.m.RUnlock()
115114
if c.closed {
@@ -118,7 +117,7 @@ func (c *closeGuardingClient) ContainerCreate(arg0 context.Context, arg1 *contai
118117
return c.pimpl.ContainerCreate(arg0, arg1, arg2, arg3, arg4, arg5)
119118
}
120119

121-
func (c *closeGuardingClient) ContainerDiff(arg0 context.Context, arg1 string) ([]container.ContainerChangeResponseItem, error) {
120+
func (c *closeGuardingClient) ContainerDiff(arg0 context.Context, arg1 string) ([]container.FilesystemChange, error) {
122121
c.m.RLock()
123122
defer c.m.RUnlock()
124123
if c.closed {
@@ -262,7 +261,7 @@ func (c *closeGuardingClient) ContainerResize(arg0 context.Context, arg1 string,
262261
return c.pimpl.ContainerResize(arg0, arg1, arg2)
263262
}
264263

265-
func (c *closeGuardingClient) ContainerRestart(arg0 context.Context, arg1 string, arg2 *time.Duration) error {
264+
func (c *closeGuardingClient) ContainerRestart(arg0 context.Context, arg1 string, arg2 container.StopOptions) error {
266265
c.m.RLock()
267266
defer c.m.RUnlock()
268267
if c.closed {
@@ -307,7 +306,7 @@ func (c *closeGuardingClient) ContainerStatsOneShot(arg0 context.Context, arg1 s
307306
return c.pimpl.ContainerStatsOneShot(arg0, arg1)
308307
}
309308

310-
func (c *closeGuardingClient) ContainerStop(arg0 context.Context, arg1 string, arg2 *time.Duration) error {
309+
func (c *closeGuardingClient) ContainerStop(arg0 context.Context, arg1 string, arg2 container.StopOptions) error {
311310
c.m.RLock()
312311
defer c.m.RUnlock()
313312
if c.closed {
@@ -343,7 +342,7 @@ func (c *closeGuardingClient) ContainerUpdate(arg0 context.Context, arg1 string,
343342
return c.pimpl.ContainerUpdate(arg0, arg1, arg2)
344343
}
345344

346-
func (c *closeGuardingClient) ContainerWait(arg0 context.Context, arg1 string, arg2 container.WaitCondition) (<-chan container.ContainerWaitOKBody, <-chan error) {
345+
func (c *closeGuardingClient) ContainerWait(arg0 context.Context, arg1 string, arg2 container.WaitCondition) (<-chan container.WaitResponse, <-chan error) {
347346
c.m.RLock()
348347
defer c.m.RUnlock()
349348
if c.closed {
@@ -406,13 +405,13 @@ func (c *closeGuardingClient) Dialer() func(context.Context) (net.Conn, error) {
406405
return c.pimpl.Dialer()
407406
}
408407

409-
func (c *closeGuardingClient) DiskUsage(arg0 context.Context) (types.DiskUsage, error) {
408+
func (c *closeGuardingClient) DiskUsage(arg0 context.Context, arg1 types.DiskUsageOptions) (types.DiskUsage, error) {
410409
c.m.RLock()
411410
defer c.m.RUnlock()
412411
if c.closed {
413412
panic("use of closed client")
414413
}
415-
return c.pimpl.DiskUsage(arg0)
414+
return c.pimpl.DiskUsage(arg0, arg1)
416415
}
417416

418417
func (c *closeGuardingClient) DistributionInspect(arg0 context.Context, arg1 string, arg2 string) (registry.DistributionInspect, error) {
@@ -802,7 +801,7 @@ func (c *closeGuardingClient) PluginUpgrade(arg0 context.Context, arg1 string, a
802801
return c.pimpl.PluginUpgrade(arg0, arg1, arg2)
803802
}
804803

805-
func (c *closeGuardingClient) RegistryLogin(arg0 context.Context, arg1 types.AuthConfig) (registry.AuthenticateOKBody, error) {
804+
func (c *closeGuardingClient) RegistryLogin(arg0 context.Context, arg1 registry.AuthConfig) (registry.AuthenticateOKBody, error) {
806805
c.m.RLock()
807806
defer c.m.RUnlock()
808807
if c.closed {
@@ -1009,7 +1008,7 @@ func (c *closeGuardingClient) TaskLogs(arg0 context.Context, arg1 string, arg2 t
10091008
return c.pimpl.TaskLogs(arg0, arg1, arg2)
10101009
}
10111010

1012-
func (c *closeGuardingClient) VolumeCreate(arg0 context.Context, arg1 volume.VolumeCreateBody) (types.Volume, error) {
1011+
func (c *closeGuardingClient) VolumeCreate(arg0 context.Context, arg1 volume.CreateOptions) (volume.Volume, error) {
10131012
c.m.RLock()
10141013
defer c.m.RUnlock()
10151014
if c.closed {
@@ -1018,7 +1017,7 @@ func (c *closeGuardingClient) VolumeCreate(arg0 context.Context, arg1 volume.Vol
10181017
return c.pimpl.VolumeCreate(arg0, arg1)
10191018
}
10201019

1021-
func (c *closeGuardingClient) VolumeInspect(arg0 context.Context, arg1 string) (types.Volume, error) {
1020+
func (c *closeGuardingClient) VolumeInspect(arg0 context.Context, arg1 string) (volume.Volume, error) {
10221021
c.m.RLock()
10231022
defer c.m.RUnlock()
10241023
if c.closed {
@@ -1027,7 +1026,7 @@ func (c *closeGuardingClient) VolumeInspect(arg0 context.Context, arg1 string) (
10271026
return c.pimpl.VolumeInspect(arg0, arg1)
10281027
}
10291028

1030-
func (c *closeGuardingClient) VolumeInspectWithRaw(arg0 context.Context, arg1 string) (types.Volume, []uint8, error) {
1029+
func (c *closeGuardingClient) VolumeInspectWithRaw(arg0 context.Context, arg1 string) (volume.Volume, []uint8, error) {
10311030
c.m.RLock()
10321031
defer c.m.RUnlock()
10331032
if c.closed {
@@ -1036,7 +1035,7 @@ func (c *closeGuardingClient) VolumeInspectWithRaw(arg0 context.Context, arg1 st
10361035
return c.pimpl.VolumeInspectWithRaw(arg0, arg1)
10371036
}
10381037

1039-
func (c *closeGuardingClient) VolumeList(arg0 context.Context, arg1 filters.Args) (volume.VolumeListOKBody, error) {
1038+
func (c *closeGuardingClient) VolumeList(arg0 context.Context, arg1 volume.ListOptions) (volume.ListResponse, error) {
10401039
c.m.RLock()
10411040
defer c.m.RUnlock()
10421041
if c.closed {
@@ -1062,3 +1061,12 @@ func (c *closeGuardingClient) VolumesPrune(arg0 context.Context, arg1 filters.Ar
10621061
}
10631062
return c.pimpl.VolumesPrune(arg0, arg1)
10641063
}
1064+
1065+
func (c *closeGuardingClient) VolumeUpdate(arg0 context.Context, arg1 string, arg2 swarm.Version, arg3 volume.UpdateOptions) error {
1066+
c.m.RLock()
1067+
defer c.m.RUnlock()
1068+
if c.closed {
1069+
panic("use of closed client")
1070+
}
1071+
return c.pimpl.VolumeUpdate(arg0, arg1, arg2, arg3)
1072+
}

pkg/oci/pusher_test.go

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ package oci
22

33
import (
44
"context"
5-
"encoding/json"
65
"errors"
76
"fmt"
7+
"io"
8+
"log"
89
"net"
910
"net/http"
10-
"net/http/httputil"
1111
"os"
1212
"testing"
1313

14-
v1 "github.com/google/go-containerregistry/pkg/v1"
14+
"github.com/google/go-containerregistry/pkg/registry"
15+
1516
fn "knative.dev/func/pkg/functions"
1617
. "knative.dev/func/pkg/testing"
1718
)
@@ -33,38 +34,17 @@ func TestPusher(t *testing.T) {
3334
// Start a handler on an OS-chosen port which confirms that an incoming
3435
// requests looks for the most part like what we'd expect to see from a
3536
// container push.
37+
regLog := io.Discard
38+
if verbose {
39+
regLog = os.Stderr
40+
}
41+
regHandler := registry.New(registry.Logger(log.New(regLog, "img reg handler: ", log.LstdFlags)))
3642
handler := http.NewServeMux()
3743
handler.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
38-
if verbose {
39-
fmt.Println("Mock registry server received request:")
40-
fmt.Println("--------------------------------------")
41-
requestDump, err := httputil.DumpRequest(req, true)
42-
if err != nil {
43-
t.Fatal(err)
44-
}
45-
fmt.Println(string(requestDump))
46-
}
47-
48-
// Ignore all requests except the PUTs
49-
if req.Method != http.MethodPut {
50-
return
51-
}
52-
53-
// Ignore all PUTs except the the image index
54-
if req.Header.Get("Content-Type") != "application/vnd.oci.image.index.v1+json" {
55-
return
56-
}
57-
58-
// Decode the request as an index JSON
59-
index := v1.IndexManifest{}
60-
d := json.NewDecoder(req.Body)
61-
defer req.Body.Close()
62-
if err := d.Decode(&index); err != nil {
63-
t.Fatal(err)
44+
regHandler.ServeHTTP(res, req)
45+
if req.Method == http.MethodPut && req.URL.Path == "/v2/funcs/f/manifests/latest" {
46+
success = true
6447
}
65-
66-
success = true
67-
6848
})
6949
l, err := net.Listen("tcp4", "127.0.0.1:")
7050
if err != nil {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## 0.7.4 (Jun 6, 2023)
2+
3+
BUG FIXES
4+
5+
- client: fixing an issue where the Content-Type header wouldn't be sent with an empty payload when using HTTP/2 [GH-194]
6+
7+
## 0.7.3 (May 15, 2023)
8+
9+
Initial release
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @hashicorp/release-engineering

third_party/VENDOR-LICENSE/github.com/hashicorp/go-retryablehttp/LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Copyright (c) 2015 HashiCorp, Inc.
2+
13
Mozilla Public License, version 2.0
24

35
1. Definitions

third_party/VENDOR-LICENSE/github.com/hashicorp/go-retryablehttp/client.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
14
// Package retryablehttp provides a familiar HTTP client interface with
25
// automatic retries and exponential backoff. It is a thin wrapper over the
36
// standard net/http client library and exposes nearly the same public API.
@@ -257,10 +260,17 @@ func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, erro
257260
if err != nil {
258261
return nil, 0, err
259262
}
260-
bodyReader = func() (io.Reader, error) {
261-
return bytes.NewReader(buf), nil
263+
if len(buf) == 0 {
264+
bodyReader = func() (io.Reader, error) {
265+
return http.NoBody, nil
266+
}
267+
contentLength = 0
268+
} else {
269+
bodyReader = func() (io.Reader, error) {
270+
return bytes.NewReader(buf), nil
271+
}
272+
contentLength = int64(len(buf))
262273
}
263-
contentLength = int64(len(buf))
264274

265275
// No body provided, nothing to do
266276
case nil:

third_party/VENDOR-LICENSE/github.com/hashicorp/go-retryablehttp/roundtripper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
14
package retryablehttp
25

36
import (

0 commit comments

Comments
 (0)