Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions exec/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package exec

import (
"context"
"github.com/chaosblade-io/chaosblade-spec-go/log"
"io/ioutil"
"io"
"time"

"github.com/chaosblade-io/chaosblade-spec-go/log"

"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)
Expand All @@ -44,7 +45,7 @@ func (c *Client) waitAndGetOutput(ctx context.Context, containerId string) (stri
return "", err
}
defer resp.Close()
bytes, err := ioutil.ReadAll(resp)
bytes, err := io.ReadAll(resp)
return string(bytes), err
}

Expand All @@ -56,13 +57,13 @@ func containerWait() error {
return nil
}

//GetImageInspectById
// GetImageInspectById
func (c *Client) getImageInspectById(imageId string) (types.ImageInspect, error) {
inspect, _, err := c.client.ImageInspectWithRaw(context.Background(), imageId)
return inspect, err
}

//DeleteImageByImageId
// DeleteImageByImageId
func (c *Client) deleteImageByImageId(imageId string) error {
_, err := c.client.ImageRemove(context.Background(), imageId, types.ImageRemoveOptions{
Force: false,
Expand Down
22 changes: 11 additions & 11 deletions exec/container/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"time"

"github.com/chaosblade-io/chaosblade-spec-go/log"
Expand All @@ -41,7 +41,7 @@ type Client struct {
Ctx context.Context
}

//GetClient returns the docker client
// GetClient returns the docker client
func NewClient(endpoint string) (*Client, error) {
var oldClient *client.Client
if cli != nil {
Expand All @@ -58,7 +58,7 @@ func NewClient(endpoint string) (*Client, error) {
return cli, nil
}

//checkAndCreateClient
// checkAndCreateClient
func checkAndCreateClient(endpoint string, cli *client.Client) (*client.Client, error) {
if cli == nil {
var err error
Expand Down Expand Up @@ -119,7 +119,7 @@ func (c *Client) GetContainerById(ctx context.Context, containerId string) (cont
return c.GetContainerFromDocker(option)
}

//getContainerByName returns the container object by container name
// getContainerByName returns the container object by container name
func (c *Client) GetContainerByName(ctx context.Context, containerName string) (container.ContainerInfo, error, int32) {
option := types.ContainerListOptions{
All: true,
Expand Down Expand Up @@ -165,7 +165,7 @@ func convertContainerInfo(container2 types.Container) container.ContainerInfo {
}
}

//RemoveContainer
// RemoveContainer
func (c *Client) RemoveContainer(ctx context.Context, containerId string, force bool) error {
err := c.client.ContainerRemove(context.Background(), containerId, types.ContainerRemoveOptions{
Force: force,
Expand All @@ -177,7 +177,7 @@ func (c *Client) RemoveContainer(ctx context.Context, containerId string, force
return nil
}

//ExecuteAndRemove: create and start a container for executing a command, and remove the container
// ExecuteAndRemove: create and start a container for executing a command, and remove the container
func (c *Client) ExecuteAndRemove(ctx context.Context, config *containertype.Config, hostConfig *containertype.HostConfig,
networkConfig *network.NetworkingConfig, containerName string, removed bool,
timeout time.Duration,
Expand Down Expand Up @@ -213,7 +213,7 @@ func (c *Client) ExecuteAndRemove(ctx context.Context, config *containertype.Con
return containerId, output, nil, spec.OK.Code
}

//ImageExists
// ImageExists
func (c *Client) getImageByRef(ctx context.Context, ref string) (types.ImageSummary, error) {
args := filters.NewArgs(filters.Arg("reference", ref))
list, err := c.client.ImageList(context.Background(), types.ImageListOptions{
Expand All @@ -231,18 +231,18 @@ func (c *Client) getImageByRef(ctx context.Context, ref string) (types.ImageSumm
return list[0], nil
}

//PullImage
// PullImage
func (c *Client) pullImage(ref string) (string, error) {
reader, err := c.client.ImagePull(context.Background(), ref, types.ImagePullOptions{})
if err != nil {
return "", err
}
defer reader.Close()
bytes, err := ioutil.ReadAll(reader)
bytes, err := io.ReadAll(reader)
return string(bytes), nil
}

//createAndStartContainer
// createAndStartContainer
func (c *Client) createAndStartContainer(ctx context.Context, config *containertype.Config, hostConfig *containertype.HostConfig,
networkConfig *network.NetworkingConfig, containerName string) (string, error) {
body, err := c.client.ContainerCreate(context.Background(), config, hostConfig, networkConfig, containerName)
Expand All @@ -255,7 +255,7 @@ func (c *Client) createAndStartContainer(ctx context.Context, config *containert
return containerId, err
}

//startContainer
// startContainer
func (c *Client) startContainer(ctx context.Context, containerId string) error {
err := c.client.ContainerStart(context.Background(), containerId, types.ContainerStartOptions{})
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions exec/executor_common_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package exec
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -190,6 +190,7 @@ func execForHangAction(uid string, ctx context.Context, expModel *spec.ExpModel,
}
}


log.Infof(ctx, "wait nsexec process pasue, current comm: %s, pid: %d", comm, command.Process.Pid)
if comm == "pause\n" {
signal <- true
Expand Down Expand Up @@ -237,7 +238,7 @@ func getProcessComm(pid int) (string, error) {
}
defer f.Close()

b, err := ioutil.ReadAll(f)
b, err := io.ReadAll(f)
if err != nil {
return "", err
}
Expand All @@ -252,7 +253,7 @@ func getProcessCmdline(pid int) (string, error) {
}
defer f.Close()

b, err := ioutil.ReadAll(f)
b, err := io.ReadAll(f)
if err != nil {
return "", err
}
Expand Down