Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to pause and resume containers #692

Merged
merged 5 commits into from
Aug 17, 2023
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
23 changes: 21 additions & 2 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ import (
volumetypes "github.com/docker/docker/api/types/volume"
dockerclient "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"

"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/internal/blockdb"
"github.com/strangelove-ventures/interchaintest/v7/internal/dockerutil"
"github.com/strangelove-ventures/interchaintest/v7/testutil"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
)

// ChainNode represents a node in the test network that is being created
Expand Down Expand Up @@ -1138,6 +1139,24 @@ func (tn *ChainNode) StartContainer(ctx context.Context) error {
}, retry.Context(ctx), retry.Attempts(40), retry.Delay(3*time.Second), retry.DelayType(retry.FixedDelay))
}

func (tn *ChainNode) PauseContainer(ctx context.Context) error {
for _, s := range tn.Sidecars {
if err := s.PauseContainer(ctx); err != nil {
return err
}
}
return tn.containerLifecycle.PauseContainer(ctx)
}

func (tn *ChainNode) UnpauseContainer(ctx context.Context) error {
for _, s := range tn.Sidecars {
if err := s.UnpauseContainer(ctx); err != nil {
return err
}
}
return tn.containerLifecycle.UnpauseContainer(ctx)
}

func (tn *ChainNode) StopContainer(ctx context.Context) error {
for _, s := range tn.Sidecars {
if err := s.StopContainer(ctx); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion chain/cosmos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (

dockerclient "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"go.uber.org/zap"

"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/internal/dockerutil"
"go.uber.org/zap"
)

type SidecarProcesses []*SidecarProcess
Expand Down Expand Up @@ -110,6 +111,14 @@ func (s *SidecarProcess) StartContainer(ctx context.Context) error {
return s.containerLifecycle.StartContainer(ctx)
}

func (s *SidecarProcess) PauseContainer(ctx context.Context) error {
return s.containerLifecycle.PauseContainer(ctx)
}

func (s *SidecarProcess) UnpauseContainer(ctx context.Context) error {
return s.containerLifecycle.UnpauseContainer(ctx)
}

func (s *SidecarProcess) StopContainer(ctx context.Context) error {
return s.containerLifecycle.StopContainer(ctx)
}
Expand Down
6 changes: 6 additions & 0 deletions ibc/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ type Relayer interface {
// StopRelayer stops a relayer that started work through StartRelayer.
StopRelayer(ctx context.Context, rep RelayerExecReporter) error

// PauseRelayer halts a relayer that started work through StartRelayer.
PauseRelayer(ctx context.Context) error

// ResumeRelayer resumes a relayer that was paused through PauseRelayer.
ResumeRelayer(ctx context.Context) error

// Flush flushes any outstanding packets and then returns.
Flush(ctx context.Context, rep RelayerExecReporter, pathName string, channelID string) error

Expand Down
11 changes: 10 additions & 1 deletion internal/dockerutil/container_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
dockerclient "github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
"github.com/docker/go-connections/nat"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"go.uber.org/zap"

"github.com/strangelove-ventures/interchaintest/v7/ibc"
)

type ContainerLifecycle struct {
Expand Down Expand Up @@ -113,6 +114,14 @@ func (c *ContainerLifecycle) StartContainer(ctx context.Context) error {
return nil
}

func (c *ContainerLifecycle) PauseContainer(ctx context.Context) error {
return c.client.ContainerPause(ctx, c.id)
}

func (c *ContainerLifecycle) UnpauseContainer(ctx context.Context) error {
return c.client.ContainerUnpause(ctx, c.id)
}

func (c *ContainerLifecycle) StopContainer(ctx context.Context) error {
var timeout container.StopOptions
timeoutSec := 30
Expand Down
17 changes: 16 additions & 1 deletion relayer/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
"go.uber.org/zap"

"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/internal/dockerutil"
"github.com/strangelove-ventures/interchaintest/v7/testutil"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -445,6 +446,20 @@ func (r *DockerRelayer) StopRelayer(ctx context.Context, rep ibc.RelayerExecRepo
return nil
}

func (r *DockerRelayer) PauseRelayer(ctx context.Context) error {
if r.containerLifecycle == nil {
return fmt.Errorf("container not running")
}
return r.client.ContainerPause(ctx, r.containerLifecycle.ContainerID())
}

func (r *DockerRelayer) ResumeRelayer(ctx context.Context) error {
if r.containerLifecycle == nil {
return fmt.Errorf("container not running")
}
return r.client.ContainerUnpause(ctx, r.containerLifecycle.ContainerID())
}

func (r *DockerRelayer) containerImage() ibc.DockerImage {
if r.customImage != nil {
return *r.customImage
Expand Down
Loading