Docker API client version bumped to 1.24 everywhere

This commit is contained in:
Raj Chaudhuri committed 2024-03-07 19:27:12 +05:30
1 parent 55a46992d4
commit e50040883f
12 files changed
+118 -27

No files matched your search

+16 -1
View File
@@ -2,7 +2,10 @@ package proxy
import (
"net/http"
"slices"
"strings"
docker "github.com/fsouza/go-dockerclient"
)
type createExecInterceptor struct{ proxy *Proxy }
@@ -18,7 +21,19 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error {
return err
}
if _, hasWeaveWait := container.Volumes["/w"]; !hasWeaveWait {
// The .Volumes property seems to have been replaced with .Mounts in Docker
// API 1.20.
// .Volumes was a list, where the key was the mount path or destination
// .Mounts is an array of objects, where the .Destination property
// corresponds to the old .Volumes list key.
//
// if _, hasWeaveWait := container.Volumes["/w"]; !hasWeaveWait {
// return nil
// }
mountIndex := slices.IndexFunc(container.Mounts, func(m docker.Mount) bool {
return m.Destination == "/w"
})
if mountIndex == -1 {
return nil
}
+42 -6
View File
@@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"strings"
"sync"
"syscall"
@@ -125,6 +126,16 @@ func (j attachJob) Stop() {
j.timer.Stop()
}
const defaulDockerAPIVersion = "1.24"
func dockerAPIVersion() string {
overridenAPIVersion, ok := os.LookupEnv("DOCKER_API_VERSION")
if ok && overridenAPIVersion != "" {
return overridenAPIVersion
}
return defaulDockerAPIVersion
}
func StubProxy(c Config) (*Proxy, error) {
p := &Proxy{
Config: c,
@@ -139,7 +150,14 @@ func StubProxy(c Config) (*Proxy, error) {
// to insulate ourselves from breaking changes to the API, as
// happened in 1.20 (Docker 1.8.0) when the presentation of
// volumes changed in `inspect`.
client, err := weavedocker.NewVersionedClient(c.DockerHost, "1.18")
// Updated in March 2024: We can't do that any more. Protocol
// version has to be updated to minimum 1.24.
// The presentation of volumes aspect has been handled later in
// this file. There may be other breaking changes if we change
// the protocol again, so will wait and watch.
// The default, 1.24, can be overridden using an environment
// variable called DOCKER_API_VERSION.
client, err := weavedocker.NewVersionedClient(c.DockerHost, dockerAPIVersion())
if err != nil {
return nil, err
}
@@ -212,15 +230,33 @@ func (proxy *Proxy) findVolume(v string) (string, error) {
return "", fmt.Errorf("Could not find the weavewait volume: %s", err)
}
if container.Volumes == nil {
return "", fmt.Errorf("Could not find the weavewait volume")
// The .Volumes property seems to have been replaced with .Mounts in Docker
// API 1.20.
// .Volumes was a list, where the key was the mount path or destination
// .Mounts is an array of objects, where the .Destination property
// corresponds to the old .Volumes list key.
//
// if container.Volumes == nil {
// return "", fmt.Errorf("Could not find the weavewait volume - no volumes : %+v", container)
// }
//
// volume, ok := container.Volumes[v]
// if !ok {
// return "", fmt.Errorf("Could not find the weavewait volume named '%v' : %+v", v, container)
// }
mounts := container.Mounts
if mounts == nil {
return "", fmt.Errorf("Could not find the weavewait volume - no volumes : %+v", container)
}
volume, ok := container.Volumes[v]
if !ok {
return "", fmt.Errorf("Could not find the weavewait volume")
mountIndex := slices.IndexFunc(mounts, func(m docker.Mount) bool {
return m.Destination == v
})
if mountIndex < 0 {
return "", fmt.Errorf("Could not find the weavewait volume named '%v' : %+v", v, container)
}
volume := container.Mounts[mountIndex].Name
return volume, nil
}