Skip to content

Commit

Permalink
Merge pull request #43407 from dims/cherry-pick-remove_containerd_fro…
Browse files Browse the repository at this point in the history
…m_client

[20.10] Remove containerd "platform" dependency from client
  • Loading branch information
thaJeztah committed Mar 24, 2022
2 parents 87a90dc + 5f9753a commit 66a9676
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions client/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"encoding/json"
"net/url"
"path"

"github.com/containerd/containerd/platforms"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/versions"
Expand All @@ -16,7 +16,6 @@ type configWrapper struct {
*container.Config
HostConfig *container.HostConfig
NetworkingConfig *network.NetworkingConfig
Platform *specs.Platform
}

// ContainerCreate creates a new container based in the given configuration.
Expand All @@ -38,8 +37,8 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config
}

query := url.Values{}
if platform != nil {
query.Set("platform", platforms.Format(*platform))
if p := formatPlatform(platform); p != "" {
query.Set("platform", p)
}

if containerName != "" {
Expand All @@ -61,3 +60,15 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config
err = json.NewDecoder(serverResp.body).Decode(&response)
return response, err
}

// formatPlatform returns a formatted string representing platform (e.g. linux/arm/v7).
//
// Similar to containerd's platforms.Format(), but does allow components to be
// omitted (e.g. pass "architecture" only, without "os":
// https://github.com/containerd/containerd/blob/v1.5.2/platforms/platforms.go#L243-L263
func formatPlatform(platform *specs.Platform) string {
if platform == nil {
return ""
}
return path.Join(platform.OS, platform.Architecture, platform.Variant)
}

0 comments on commit 66a9676

Please sign in to comment.