From 3ee2975d767a0eb32951d1d6100aae8377e60cdf Mon Sep 17 00:00:00 2001 From: Stavros Panakakis <53979866+Stavrospanakakis@users.noreply.github.com> Date: Tue, 7 Sep 2021 14:03:13 +0300 Subject: [PATCH] Upgrade docker sdk to moby (#491) * Replace deprecated method * Upgrade docker sdk to moby --- docker/docker.go | 20 +++++++++++--------- docker/factory.go | 4 ++-- docker/local_cached_factory.go | 4 ++-- docker/mock.go | 4 ++-- go.mod | 3 +-- go.sum | 4 ++-- handlers/ping.go | 4 ++-- provisioner/overlay.go | 2 +- pwd/client_test.go | 2 +- pwd/instance_test.go | 2 +- pwd/session_test.go | 2 +- router/l2/l2.go | 12 ++++++------ scheduler/task/check_swarm_ports_test.go | 4 ++-- scheduler/task/check_swarm_status.go | 2 +- scheduler/task/check_swarm_status_test.go | 4 ++-- scheduler/task/collect_stats.go | 2 +- scheduler/task/collect_stats_test.go | 2 +- 17 files changed, 39 insertions(+), 38 deletions(-) diff --git a/docker/docker.go b/docker/docker.go index 4051c35..e36125d 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -14,13 +14,13 @@ import ( "strings" "time" - client "docker.io/go-docker" - "docker.io/go-docker/api/types" - "docker.io/go-docker/api/types/container" - "docker.io/go-docker/api/types/network" - "docker.io/go-docker/api/types/swarm" - "docker.io/go-docker/api/types/volume" "github.com/containerd/containerd/reference" + "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/network" + "github.com/docker/docker/api/types/swarm" + "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/client" "github.com/play-with-docker/play-with-docker/config" ) @@ -315,7 +315,7 @@ func (d *docker) ContainerCreate(opts CreateContainerOpts) (err error) { pidsLimit = int64(i) } } - h.Resources.PidsLimit = pidsLimit + h.Resources.PidsLimit = &pidsLimit if memLimit := os.Getenv("MAX_MEMORY_MB"); memLimit != "" { if i, err := strconv.Atoi(memLimit); err == nil { @@ -344,7 +344,7 @@ func (d *docker) ContainerCreate(opts CreateContainerOpts) (err error) { } if config.ExternalDindVolume { - _, err = d.c.VolumeCreate(context.Background(), volume.VolumesCreateBody{ + _, err = d.c.VolumeCreate(context.Background(), volume.VolumeCreateBody{ Driver: "xfsvol", DriverOpts: map[string]string{ "size": opts.DindVolumeSize, @@ -451,7 +451,9 @@ func (d *docker) ExecAttach(instanceName string, command []string, out io.Writer if err != nil { return 0, err } - resp, err := d.c.ContainerExecAttach(context.Background(), e.ID, types.ExecConfig{AttachStdout: true, AttachStderr: true, Tty: true}) + resp, err := d.c.ContainerExecAttach(context.Background(), e.ID, types.ExecStartCheck{ + Tty: true, + }) if err != nil { return 0, err } diff --git a/docker/factory.go b/docker/factory.go index ea278d9..da50cd4 100644 --- a/docker/factory.go +++ b/docker/factory.go @@ -8,8 +8,8 @@ import ( "net/url" "time" - client "docker.io/go-docker" - "docker.io/go-docker/api" + "github.com/docker/docker/api" + "github.com/docker/docker/client" "github.com/docker/go-connections/tlsconfig" "github.com/play-with-docker/play-with-docker/pwd/types" "github.com/play-with-docker/play-with-docker/router" diff --git a/docker/local_cached_factory.go b/docker/local_cached_factory.go index 1cb665f..39a2581 100644 --- a/docker/local_cached_factory.go +++ b/docker/local_cached_factory.go @@ -7,7 +7,7 @@ import ( "sync" "time" - client "docker.io/go-docker" + "github.com/docker/docker/client" "github.com/play-with-docker/play-with-docker/pwd/types" "github.com/play-with-docker/play-with-docker/storage" ) @@ -37,7 +37,7 @@ func (f *localCachedFactory) GetForSession(session *types.Session) (DockerApi, e } } - c, err := client.NewEnvClient() + c, err := client.NewClientWithOpts() if err != nil { return nil, err } diff --git a/docker/mock.go b/docker/mock.go index 4d0ad0c..4f4c2c9 100644 --- a/docker/mock.go +++ b/docker/mock.go @@ -5,8 +5,8 @@ import ( "net" "time" - client "docker.io/go-docker" - "docker.io/go-docker/api/types" + "github.com/docker/docker/api/types" + "github.com/docker/docker/client" "github.com/stretchr/testify/mock" ) diff --git a/go.mod b/go.mod index 2ea113e..ad6c6c3 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,13 @@ go 1.16 require ( cloud.google.com/go v0.58.0 // indirect - docker.io/go-docker v1.0.0 github.com/Microsoft/go-winio v0.4.5 // indirect github.com/PuerkitoBio/purell v1.1.0 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/aws/aws-sdk-go v1.12.15 github.com/containerd/containerd v1.0.0-beta.2 github.com/docker/distribution v2.6.0-rc.1.0.20170726174610-edc3ab29cdff+incompatible // indirect - github.com/docker/docker v1.4.2-0.20200309214505-aa6a9891b09c // indirect + github.com/docker/docker v1.4.2-0.20200309214505-aa6a9891b09c github.com/docker/go-connections v0.3.0 github.com/docker/go-units v0.3.2 github.com/emicklei/go-restful v2.4.0+incompatible // indirect diff --git a/go.sum b/go.sum index 11f6382..aa91041 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,6 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -docker.io/go-docker v1.0.0 h1:VdXS/aNYQxyA9wdLD5z8Q8Ro688/hG8HzKxYVEVbE6s= -docker.io/go-docker v1.0.0/go.mod h1:7tiAn5a0LFmjbPDbyTPOaTTOuG1ZRNXdPA6RvKY+fpY= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Microsoft/go-winio v0.4.5 h1:U2XsGR5dBg1yzwSEJoP2dE2/aAXpmad+CNG2hE9Pd5k= @@ -189,6 +187,7 @@ github.com/juju/ratelimit v1.0.1 h1:+7AIFJVQ0EQgq/K9+0Krm7m530Du7tIz0METWzN0RgY= github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -245,6 +244,7 @@ github.com/satori/go.uuid v1.1.1-0.20170321230731-5bf94b69c6b6/go.mod h1:dA0hQrY github.com/shirou/gopsutil v2.16.13-0.20170924065440-6e221c482653+incompatible h1:gh3Hq7V5Zb8X2xk4T9FbHVi1m2Yo+oEIyjjJUiezVoY= github.com/shirou/gopsutil v2.16.13-0.20170924065440-6e221c482653+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= diff --git a/handlers/ping.go b/handlers/ping.go index 33d47ad..5f25e4c 100644 --- a/handlers/ping.go +++ b/handlers/ping.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - docker "docker.io/go-docker" + "github.com/docker/docker/client" "github.com/play-with-docker/play-with-docker/config" "github.com/shirou/gopsutil/load" ) @@ -15,7 +15,7 @@ func Ping(rw http.ResponseWriter, req *http.Request) { defer latencyHistogramVec.WithLabelValues("ping").Observe(float64(time.Since(time.Now()).Nanoseconds()) / 1000000) // Get system load average of the last 5 minutes and compare it against a threashold. - c, err := docker.NewEnvClient() + c, err := client.NewClientWithOpts() if err != nil { rw.WriteHeader(http.StatusInternalServerError) diff --git a/provisioner/overlay.go b/provisioner/overlay.go index ea60888..84c80d0 100644 --- a/provisioner/overlay.go +++ b/provisioner/overlay.go @@ -7,7 +7,7 @@ import ( "net/url" "strings" - dtypes "docker.io/go-docker/api/types" + dtypes "github.com/docker/docker/api/types" "github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/pwd/types" diff --git a/pwd/client_test.go b/pwd/client_test.go index af30718..20ef831 100644 --- a/pwd/client_test.go +++ b/pwd/client_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - dtypes "docker.io/go-docker/api/types" + dtypes "github.com/docker/docker/api/types" "github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/event" diff --git a/pwd/instance_test.go b/pwd/instance_test.go index 3c4fda0..d52fda1 100644 --- a/pwd/instance_test.go +++ b/pwd/instance_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - dtypes "docker.io/go-docker/api/types" + dtypes "github.com/docker/docker/api/types" "github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/event" diff --git a/pwd/session_test.go b/pwd/session_test.go index f4c7fa7..81188ba 100644 --- a/pwd/session_test.go +++ b/pwd/session_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - dtypes "docker.io/go-docker/api/types" + dtypes "github.com/docker/docker/api/types" "github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/event" diff --git a/router/l2/l2.go b/router/l2/l2.go index 1b4e25e..6f1e885 100644 --- a/router/l2/l2.go +++ b/router/l2/l2.go @@ -12,10 +12,10 @@ import ( "golang.org/x/crypto/ssh" - client "docker.io/go-docker" - "docker.io/go-docker/api/types" - "docker.io/go-docker/api/types/filters" - "docker.io/go-docker/api/types/network" + "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/network" + "github.com/docker/docker/client" "github.com/gorilla/mux" "github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/router" @@ -60,7 +60,7 @@ func director(protocol router.Protocol, host string) (*router.DirectorInfo, erro func connectNetworks() error { ctx := context.Background() - c, err := client.NewEnvClient() + c, err := client.NewClientWithOpts() if err != nil { log.Fatal(err) } @@ -91,7 +91,7 @@ func connectNetworks() error { } func monitorNetworks() { - c, err := client.NewEnvClient() + c, err := client.NewClientWithOpts() if err != nil { log.Fatal(err) } diff --git a/scheduler/task/check_swarm_ports_test.go b/scheduler/task/check_swarm_ports_test.go index 53c3113..88d5d68 100644 --- a/scheduler/task/check_swarm_ports_test.go +++ b/scheduler/task/check_swarm_ports_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - dockerTypes "docker.io/go-docker/api/types" - "docker.io/go-docker/api/types/swarm" + dockerTypes "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/swarm" "github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/pwd/types" diff --git a/scheduler/task/check_swarm_status.go b/scheduler/task/check_swarm_status.go index b507108..45f6e56 100644 --- a/scheduler/task/check_swarm_status.go +++ b/scheduler/task/check_swarm_status.go @@ -4,7 +4,7 @@ import ( "context" "log" - "docker.io/go-docker/api/types/swarm" + "github.com/docker/docker/api/types/swarm" "github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/pwd/types" diff --git a/scheduler/task/check_swarm_status_test.go b/scheduler/task/check_swarm_status_test.go index 0cb14d8..d350ef9 100644 --- a/scheduler/task/check_swarm_status_test.go +++ b/scheduler/task/check_swarm_status_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - dockerTypes "docker.io/go-docker/api/types" - "docker.io/go-docker/api/types/swarm" + dockerTypes "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/swarm" "github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/pwd/types" diff --git a/scheduler/task/collect_stats.go b/scheduler/task/collect_stats.go index 0ad1cad..bd11139 100644 --- a/scheduler/task/collect_stats.go +++ b/scheduler/task/collect_stats.go @@ -10,7 +10,7 @@ import ( "net/url" "time" - dockerTypes "docker.io/go-docker/api/types" + dockerTypes "github.com/docker/docker/api/types" units "github.com/docker/go-units" lru "github.com/hashicorp/golang-lru" "github.com/play-with-docker/play-with-docker/docker" diff --git a/scheduler/task/collect_stats_test.go b/scheduler/task/collect_stats_test.go index 121bcba..6de4edb 100644 --- a/scheduler/task/collect_stats_test.go +++ b/scheduler/task/collect_stats_test.go @@ -7,7 +7,7 @@ import ( "io" "testing" - dockerTypes "docker.io/go-docker/api/types" + dockerTypes "github.com/docker/docker/api/types" "github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/pwd/types"