Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit e500408

Browse files
committed
Docker API client version bumped to 1.24 everywhere
1 parent 55a4699 commit e500408

12 files changed

+120
-29
lines changed

prog/weaveutil/addrs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func containerAddrs(args []string) error {
1414
}
1515
bridgeName := args[0]
1616

17-
client, err := docker.NewVersionedClientFromEnv("1.18")
17+
client, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
1818
if err != nil {
1919
return err
2020
}

prog/weaveutil/container.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func inspectContainer(containerNameOrID string) (*docker.Container, error) {
12-
c, err := docker.NewVersionedClientFromEnv("1.18")
12+
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
1313
if err != nil {
1414
return nil, fmt.Errorf("unable to connect to docker: %s", err)
1515
}
@@ -174,7 +174,7 @@ func parseContainerArgs(args []string) docker.CreateContainerOptions {
174174
func runContainer(args []string) error {
175175
containerOptions := parseContainerArgs(args)
176176

177-
c, err := docker.NewVersionedClientFromEnv("1.18")
177+
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
178178
if err != nil {
179179
return fmt.Errorf("unable to connect to docker: %s", err)
180180
}
@@ -206,7 +206,7 @@ func listContainers(args []string) error {
206206
cmdUsage("list-containers", "[<label>]")
207207
}
208208

209-
c, err := docker.NewVersionedClientFromEnv("1.18")
209+
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
210210
if err != nil {
211211
return fmt.Errorf("unable to connect to docker: %s", err)
212212
}
@@ -233,7 +233,7 @@ func stopContainer(args []string) error {
233233
cmdUsage("stop-container", "<container-id> [<container-id2> ...]")
234234
}
235235

236-
c, err := docker.NewVersionedClientFromEnv("1.18")
236+
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
237237
if err != nil {
238238
return fmt.Errorf("unable to connect to docker: %s", err)
239239
}
@@ -252,7 +252,7 @@ func killContainer(args []string) error {
252252
cmdUsage("kill-container", "<container-id> [<container-id2> ...]")
253253
}
254254

255-
c, err := docker.NewVersionedClientFromEnv("1.18")
255+
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
256256
if err != nil {
257257
return fmt.Errorf("unable to connect to docker: %s", err)
258258
}
@@ -288,7 +288,7 @@ func removeContainer(args []string) error {
288288
}
289289
}
290290

291-
c, err := docker.NewVersionedClientFromEnv("1.18")
291+
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
292292
if err != nil {
293293
return fmt.Errorf("unable to connect to docker: %s", err)
294294
}

prog/weaveutil/dockerclientwrapper.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
docker "github.com/fsouza/go-dockerclient"
7+
)
8+
9+
const defaulDockerAPIVersion = "1.24"
10+
const swarmDockerAPIVersion = "1.26"
11+
12+
// newVersionedDockerClientFromEnv offers some control over the version
13+
// of the docker client weaveutil uses for a number of operations.
14+
// The version specified by the caller, usually defaulDockerAPIVersion,
15+
// may be overridden by setting an environment variable called
16+
// DOCKER_API_VERSION.
17+
func newVersionedDockerClientFromEnv(apiVersionString string) (*docker.Client, error) {
18+
overridenAPIVersion, ok := os.LookupEnv("DOCKER_API_VERSION")
19+
if ok && overridenAPIVersion != "" {
20+
apiVersionString = overridenAPIVersion
21+
}
22+
return docker.NewVersionedClientFromEnv(apiVersionString)
23+
}

prog/weaveutil/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ func usage() {
9090
for cmd := range commands {
9191
fmt.Fprintln(os.Stderr, cmd)
9292
}
93+
fmt.Fprintln(os.Stderr)
94+
fmt.Fprintf(os.Stderr, "Set an environment variable called DOCKER_API_VERSION to control the API version used.\nDefault is: %v\n", defaulDockerAPIVersion)
9395
}
9496

9597
func cmdUsage(cmd string, usage string) {

prog/weaveutil/plugin_network.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func isDockerPluginEnabled(args []string) error {
7575
}
7676

7777
func newDockerClient() (*docker.Client, error) {
78-
// API 1.21 is the first version that supports docker network
79-
// commands
80-
c, err := docker.NewVersionedClientFromEnv("1.21")
78+
// API 1.21 was the first version that supports docker network
79+
// commands. In March 2024, the minimum suupported API is 1.24
80+
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
8181
if err != nil {
8282
return nil, fmt.Errorf("unable to connect to docker: %s", err)
8383
}

prog/weaveutil/swarm.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/fsouza/go-dockerclient"
7+
docker "github.com/fsouza/go-dockerclient"
88
"github.com/pkg/errors"
99
)
1010

11-
const DOCKER_API_VERSION = "1.26"
12-
1311
func swarmManagerPeers(args []string) error {
1412
info, err := dockerInfo()
1513
if err != nil {
@@ -32,7 +30,7 @@ func swarmManagerPeers(args []string) error {
3230
}
3331

3432
func dockerInfo() (*docker.DockerInfo, error) {
35-
client, err := docker.NewVersionedClientFromEnv(DOCKER_API_VERSION)
33+
client, err := newVersionedDockerClientFromEnv(swarmDockerAPIVersion)
3634
if err != nil {
3735
return nil, errors.Wrap(err, "docker.NewVersionedClientFromEnv")
3836
}

prog/weaveutil/volume.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func createVolumeContainer(args []string) error {
1515
label := args[2]
1616
bindMounts := args[3:]
1717

18-
c, err := docker.NewVersionedClientFromEnv("1.18")
18+
c, err := newVersionedDockerClientFromEnv(defaulDockerAPIVersion)
1919
if err != nil {
2020
return fmt.Errorf("unable to connect to docker: %s", err)
2121
}

proxy/create_exec_interceptor.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package proxy
22

33
import (
44
"net/http"
5+
"slices"
56
"strings"
7+
8+
docker "github.com/fsouza/go-dockerclient"
69
)
710

811
type createExecInterceptor struct{ proxy *Proxy }
@@ -18,7 +21,19 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error {
1821
return err
1922
}
2023

21-
if _, hasWeaveWait := container.Volumes["/w"]; !hasWeaveWait {
24+
// The .Volumes property seems to have been replaced with .Mounts in Docker
25+
// API 1.20.
26+
// .Volumes was a list, where the key was the mount path or destination
27+
// .Mounts is an array of objects, where the .Destination property
28+
// corresponds to the old .Volumes list key.
29+
//
30+
// if _, hasWeaveWait := container.Volumes["/w"]; !hasWeaveWait {
31+
// return nil
32+
// }
33+
mountIndex := slices.IndexFunc(container.Mounts, func(m docker.Mount) bool {
34+
return m.Destination == "/w"
35+
})
36+
if mountIndex == -1 {
2237
return nil
2338
}
2439

proxy/proxy.go

+44-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"path/filepath"
1111
"regexp"
12+
"slices"
1213
"strings"
1314
"sync"
1415
"syscall"
@@ -125,6 +126,16 @@ func (j attachJob) Stop() {
125126
j.timer.Stop()
126127
}
127128

129+
const defaulDockerAPIVersion = "1.24"
130+
131+
func dockerAPIVersion() string {
132+
overridenAPIVersion, ok := os.LookupEnv("DOCKER_API_VERSION")
133+
if ok && overridenAPIVersion != "" {
134+
return overridenAPIVersion
135+
}
136+
return defaulDockerAPIVersion
137+
}
138+
128139
func StubProxy(c Config) (*Proxy, error) {
129140
p := &Proxy{
130141
Config: c,
@@ -139,7 +150,14 @@ func StubProxy(c Config) (*Proxy, error) {
139150
// to insulate ourselves from breaking changes to the API, as
140151
// happened in 1.20 (Docker 1.8.0) when the presentation of
141152
// volumes changed in `inspect`.
142-
client, err := weavedocker.NewVersionedClient(c.DockerHost, "1.18")
153+
// Updated in March 2024: We can't do that any more. Protocol
154+
// version has to be updated to minimum 1.24.
155+
// The presentation of volumes aspect has been handled later in
156+
// this file. There may be other breaking changes if we change
157+
// the protocol again, so will wait and watch.
158+
// The default, 1.24, can be overridden using an environment
159+
// variable called DOCKER_API_VERSION.
160+
client, err := weavedocker.NewVersionedClient(c.DockerHost, dockerAPIVersion())
143161
if err != nil {
144162
return nil, err
145163
}
@@ -212,15 +230,33 @@ func (proxy *Proxy) findVolume(v string) (string, error) {
212230
return "", fmt.Errorf("Could not find the weavewait volume: %s", err)
213231
}
214232

215-
if container.Volumes == nil {
216-
return "", fmt.Errorf("Could not find the weavewait volume")
217-
}
218-
219-
volume, ok := container.Volumes[v]
220-
if !ok {
221-
return "", fmt.Errorf("Could not find the weavewait volume")
233+
// The .Volumes property seems to have been replaced with .Mounts in Docker
234+
// API 1.20.
235+
// .Volumes was a list, where the key was the mount path or destination
236+
// .Mounts is an array of objects, where the .Destination property
237+
// corresponds to the old .Volumes list key.
238+
//
239+
// if container.Volumes == nil {
240+
// return "", fmt.Errorf("Could not find the weavewait volume - no volumes : %+v", container)
241+
// }
242+
//
243+
// volume, ok := container.Volumes[v]
244+
// if !ok {
245+
// return "", fmt.Errorf("Could not find the weavewait volume named '%v' : %+v", v, container)
246+
// }
247+
mounts := container.Mounts
248+
if mounts == nil {
249+
return "", fmt.Errorf("Could not find the weavewait volume - no volumes : %+v", container)
250+
}
251+
252+
mountIndex := slices.IndexFunc(mounts, func(m docker.Mount) bool {
253+
return m.Destination == v
254+
})
255+
if mountIndex < 0 {
256+
return "", fmt.Errorf("Could not find the weavewait volume named '%v' : %+v", v, container)
222257
}
223258

259+
volume := container.Mounts[mountIndex].Name
224260
return volume, nil
225261
}
226262

reweave/CHANGELOG.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22

33
All changes made to the weave net codebase during the reweave effort will be documented in this file.
44

5-
## 2.8.2 latest
5+
## latest
6+
7+
### Changed
8+
9+
* The docker API client version, used by the proxy package and the weaveutil command, was bumped from 1.18 to 1.24. As of March 2024, Docker API versions below 1.24 are deprecated. This means that the minimum supported Docker version is now 1.12.0
10+
11+
### Added
12+
13+
* Provision was made in weaveutil program and the weave script to override the API version used, via the environment variable `DOCKER_API_VERSION`. The same variable is used by standard docker clients
14+
15+
### Fixed
16+
17+
* Fixed `proxy.go` in the proxy package to handle changes in the Docker API. In the 1.24 API, container objects expose a `.Mounts` property rather than a `.Volumes` property.
18+
* The `weave` script was modified to add a `-t` switch when invoking functionality inside a container. This ensures that output is visible even when using the Weave docker proxy
19+
20+
## 2.8.2 (7b087168)
621

722
### Changed
823

reweave/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
IMAGE_VERSION ?= 2.8.2
1+
IMAGE_VERSION ?= 2.8.3-beta1
22
REGISTRY_USER ?= rajchaudhuri
33

44
ALPINE_BASEIMAGE ?= alpine:3.19.1

weave

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ IMAGE_VERSION=latest
99
IMAGE_VERSION=${WEAVE_VERSION:-$IMAGE_VERSION}
1010

1111
# Minimum tested version of Docker + Weave Net
12-
MIN_DOCKER_VERSION=1.10.0
12+
MIN_DOCKER_VERSION=1.12.0
1313

1414
# These are needed for remote execs, hence we introduce them here
15-
DOCKERHUB_USER=${DOCKERHUB_USER:-weaveworks}
15+
DOCKERHUB_USER=${DOCKERHUB_USER:-rajchaudhuri}
1616
BASE_EXEC_IMAGE=$DOCKERHUB_USER/weaveexec
1717
EXEC_IMAGE=$BASE_EXEC_IMAGE:$IMAGE_VERSION
1818
WEAVEDB_IMAGE=$DOCKERHUB_USER/weavedb:latest
@@ -95,8 +95,8 @@ where <peer> = <ip_address_or_fqdn>[:<port>]
9595
<peer_id> = <nickname> | <weave internal peer ID>
9696
<mode> = consensus[=<count>] | seed=<mac>,... | observer
9797
98-
To troubleshoot and visualize Weave networks, try Weave Cloud: http://www.weave.works/product/cloud/
9998
EOF
99+
# To troubleshoot and visualize Weave networks, try Weave : http://www.weave.works/product/cloud/
100100
}
101101

102102
usage() {
@@ -155,6 +155,8 @@ exec_remote() {
155155
-e COVERAGE \
156156
-e CHECKPOINT_DISABLE \
157157
-e AWSVPC \
158+
-e DOCKER_API_VERSION \
159+
-t \
158160
$WEAVEEXEC_DOCKER_ARGS $EXEC_IMAGE --local "$@"
159161
}
160162

0 commit comments

Comments
 (0)