Skip to content

Commit

Permalink
rename client
Browse files Browse the repository at this point in the history
  • Loading branch information
sreya committed Nov 26, 2024
1 parent 7f28e79 commit 3981155
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cli/clitest/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Mounter(ctx context.Context) *mount.FakeMounter {
func DockerClient(t *testing.T, ctx context.Context) *dockerfake.MockClient {
t.Helper()

client, err := dockerutil.Client(ctx)
client, err := dockerutil.ExtractClient(ctx)
require.NoError(t, err)
//nolint we should panic if this isn't the case.
return client.(*dockerfake.MockClient)
Expand Down Expand Up @@ -71,7 +71,7 @@ func New(t *testing.T, cmd string, args ...string) (context.Context, *cobra.Comm
return ctx, root
}

func ctx(t *testing.T, fs xunix.FS, ex xunix.Execer, mnt mount.Interface, client dockerutil.DockerClient) context.Context {
func ctx(t *testing.T, fs xunix.FS, ex xunix.Execer, mnt mount.Interface, client dockerutil.Client) context.Context {
t.Helper()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
Expand Down
2 changes: 1 addition & 1 deletion cli/clitest/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewFakeExecer() *xunixfake.FakeExec {
}
}

func NewFakeDockerClient() dockerutil.DockerClient {
func NewFakeDockerClient() dockerutil.Client {
client := &dockerfake.MockClient{}

client.ContainerInspectFn = func(_ context.Context, _ string) (dockertypes.ContainerJSON, error) {
Expand Down
4 changes: 2 additions & 2 deletions cli/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func dockerCmd() *cobra.Command {
return xerrors.Errorf("wait for sysbox-mgr: %w", err)
}

client, err := dockerutil.Client(ctx)
client, err := dockerutil.ExtractClient(ctx)
if err != nil {
return xerrors.Errorf("new docker client: %w", err)
}
Expand Down Expand Up @@ -387,7 +387,7 @@ func dockerCmd() *cobra.Command {
return cmd
}

func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.DockerClient, blog buildlog.Logger, flags flags) error {
func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Client, blog buildlog.Logger, flags flags) error {
fs := xunix.GetFS(ctx)

// Set our OOM score to something really unfavorable to avoid getting killed
Expand Down
10 changes: 5 additions & 5 deletions dockerutil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"golang.org/x/xerrors"
)

type DockerClient interface {
type Client interface {
dockerclient.SystemAPIClient
dockerclient.ContainerAPIClient
dockerclient.ImageAPIClient
Expand All @@ -23,13 +23,13 @@ type clientKey struct{}

// WithClient sets the provided DockerClient on the context.
// It should only be used for tests.
func WithClient(ctx context.Context, client DockerClient) context.Context {
func WithClient(ctx context.Context, client Client) context.Context {
return context.WithValue(ctx, clientKey{}, client)
}

// Client returns the DockerClient set on the context. If one can't be
// ExtractClient returns the DockerClient set on the context. If one can't be
// found a default client is returned.
func Client(ctx context.Context) (DockerClient, error) {
func ExtractClient(ctx context.Context) (Client, error) {
client := ctx.Value(clientKey{})
if client == nil {
client, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv)
Expand All @@ -41,7 +41,7 @@ func Client(ctx context.Context) (DockerClient, error) {
}

//nolint we should panic if this isn't the case.
return client.(DockerClient), nil
return client.(Client), nil
}

type AuthConfig registry.AuthConfig
Expand Down
4 changes: 2 additions & 2 deletions dockerutil/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ContainerConfig struct {
}

// CreateContainer creates a sysbox-runc container.
func CreateContainer(ctx context.Context, client DockerClient, conf *ContainerConfig) (string, error) {
func CreateContainer(ctx context.Context, client Client, conf *ContainerConfig) (string, error) {
host := &container.HostConfig{
Runtime: runtime,
AutoRemove: true,
Expand Down Expand Up @@ -99,7 +99,7 @@ type BootstrapConfig struct {

// BoostrapContainer runs a script inside the container as the provided user.
// If conf.Script is empty then it is a noop.
func BootstrapContainer(ctx context.Context, client DockerClient, conf BootstrapConfig) error {
func BootstrapContainer(ctx context.Context, client Client, conf BootstrapConfig) error {
if conf.Script == "" {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion dockerutil/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// WaitForDaemon waits for a Docker daemon to startup. It waits a max
// of 5m before giving up.
func WaitForDaemon(ctx context.Context, client DockerClient) error {
func WaitForDaemon(ctx context.Context, client Client) error {
ticker := time.NewTicker(time.Millisecond * 250)
defer ticker.Stop()

Expand Down
2 changes: 1 addition & 1 deletion dockerutil/dockerfake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/coder/envbox/dockerutil"
)

var _ dockerutil.DockerClient = MockClient{}
var _ dockerutil.Client = MockClient{}

// MockClient provides overrides for functions that are called in envbox.
type MockClient struct {
Expand Down
2 changes: 1 addition & 1 deletion dockerutil/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ExecConfig struct {

// ExecContainer runs a command in a container. It returns the output and any error.
// If an error occurs during the execution of the command, the output is appended to the error.
func ExecContainer(ctx context.Context, client DockerClient, config ExecConfig) ([]byte, error) {
func ExecContainer(ctx context.Context, client Client, config ExecConfig) ([]byte, error) {
exec, err := client.ContainerExecCreate(ctx, config.ContainerID, dockertypes.ExecConfig{
Detach: true,
Cmd: append([]string{config.Cmd}, config.Args...),
Expand Down
6 changes: 3 additions & 3 deletions dockerutil/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
const diskFullStorageDriver = "vfs"

type PullImageConfig struct {
Client DockerClient
Client Client
Image string
Auth AuthConfig
ProgressFn ImagePullProgressFn
Expand Down Expand Up @@ -107,7 +107,7 @@ func PullImage(ctx context.Context, config *PullImageConfig) error {
}

// PruneImage runs a simple 'docker prune'.
func PruneImages(ctx context.Context, client DockerClient) (dockertypes.ImagesPruneReport, error) {
func PruneImages(ctx context.Context, client Client) (dockertypes.ImagesPruneReport, error) {
report, err := client.ImagesPrune(ctx,
filters.NewArgs(filters.Arg("dangling", "false")),
)
Expand Down Expand Up @@ -156,7 +156,7 @@ type ImageMetadata struct {

// GetImageMetadata returns metadata about an image such as the UID/GID of the
// provided username and whether it contains an /sbin/init that we should run.
func GetImageMetadata(ctx context.Context, client DockerClient, image, username string) (ImageMetadata, error) {
func GetImageMetadata(ctx context.Context, client Client, image, username string) (ImageMetadata, error) {
// Creating a dummy container to inspect the filesystem.
created, err := client.ContainerCreate(ctx,
&container.Config{
Expand Down

0 comments on commit 3981155

Please sign in to comment.