Skip to content

Commit

Permalink
fix: fully remove sidecars and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Zygimantass committed Jan 10, 2025
1 parent 165a41b commit d215eb1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 61 deletions.
2 changes: 1 addition & 1 deletion core/provider/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type TaskDefinition struct {
Command []string
Args []string

ProviderSpecificConfig map[string]string
ProviderSpecificConfig interface{}
}

func (t *TaskDefinition) ValidateBasic() error {
Expand Down
1 change: 0 additions & 1 deletion core/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type Task struct {

ID string
Definition TaskDefinition
Sidecars []*Task

logger *zap.Logger
mu sync.RWMutex
Expand Down
40 changes: 8 additions & 32 deletions core/provider/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go.uber.org/zap"
)

// CreateTask creates a task structure and sets up its underlying workload on a provider, including sidecars if there are any in the definition
// CreateTask creates a task structure and sets up its underlying workload on a provider
func CreateTask(ctx context.Context, logger *zap.Logger, provider Provider, definition TaskDefinition) (*Task, error) {
if err := definition.ValidateBasic(); err != nil {
return nil, fmt.Errorf("failed to validate task definition: %w", err)
Expand All @@ -25,42 +25,30 @@ func CreateTask(ctx context.Context, logger *zap.Logger, provider Provider, defi
task.mu.Lock()
defer task.mu.Unlock()

sidecarTasks := make([]*Task, 0)

var eg errgroup.Group

eg.Go(func() error {
id, err := provider.CreateTask(ctx, logger, definition)
if err != nil {
return err
}

task.ID = id

return nil
})

if err := eg.Wait(); err != nil {
return nil, err
}

task.Sidecars = sidecarTasks

return task, nil
}

// Start starts the underlying task's workload including its sidecars if startSidecars is set to true.
// Start starts the underlying task's workload
// This method does not take a lock on the provider, hence 2 threads may simultaneously call Start on the same task,
// this is not thread-safe: PLEASE DON'T DO THAT.
func (t *Task) Start(ctx context.Context, startSidecars bool) error {
if startSidecars {
for _, sidecar := range t.Sidecars {
err := sidecar.Start(ctx, startSidecars)
if err != nil {
return err
}
}
}

if t.PreStart != nil {
err := t.PreStart(ctx, t)
if err != nil {
Expand All @@ -76,20 +64,11 @@ func (t *Task) Start(ctx context.Context, startSidecars bool) error {
return nil
}

// Stop stops the underlying task's workload including its sidecars if stopSidecars is set to true
// Stop stops the underlying task's workload
func (t *Task) Stop(ctx context.Context, stopSidecars bool) error {
t.mu.Lock()
defer t.mu.Unlock()

if stopSidecars {
for _, sidecar := range t.Sidecars {
err := sidecar.Stop(ctx, stopSidecars)
if err != nil {
return err
}
}
}

err := t.Provider.StopTask(ctx, t.ID)

if t.PostStop != nil {
Expand Down Expand Up @@ -177,14 +156,11 @@ func (t *Task) GetStatus(ctx context.Context) (TaskStatus, error) {
return t.Provider.GetTaskStatus(ctx, t.ID)
}

// Destroy destroys the task's underlying workload, including it's sidecars if destroySidecars is set to true
// Destroy destroys the task's underlying workload
func (t *Task) Destroy(ctx context.Context, destroySidecars bool) error {
t.mu.Lock()
defer t.mu.Unlock()

if destroySidecars {
}

err := t.Provider.DestroyTask(ctx, t.ID)
if err != nil {
return err
Expand Down
16 changes: 3 additions & 13 deletions core/types/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ChainI interface {
}

// ChainConfig is the configuration structure for a logical chain.
// It contains all the relevant details needed to create a Cosmos chain and it's sidecars
// It contains all the relevant details needed to create a Cosmos chain
type ChainConfig struct {
Denom string // Denom is the denomination of the native staking token
Decimals uint64 // Decimals is the number of decimals of the native staking token
Expand All @@ -49,8 +49,7 @@ type ChainConfig struct {

BinaryName string // BinaryName is the name of the chain binary in the Docker image

Image provider.ImageDefinition // Image is the Docker ImageDefinition of the chain
SidecarImage provider.ImageDefinition // SidecarImage is the Docker ImageDefinition of the chain sidecar
Image provider.ImageDefinition // Image is the Docker ImageDefinition of the chain

GasPrices string // GasPrices are the minimum gas prices to set on the chain
GasAdjustment float64 // GasAdjustment is the margin by which to multiply the default gas prices
Expand All @@ -59,10 +58,7 @@ type ChainConfig struct {

EncodingConfig testutil.TestEncodingConfig // EncodingConfig is the encoding config of the chain

HomeDir string // HomeDir is the home directory of the chain
SidecarHomeDir string // SidecarHomeDir is the home directory of the chain sidecar
SidecarPorts []string // SidecarPorts are the ports to expose on the chain sidecar
SidecarArgs []string // SidecarArgs are the arguments to launch the chain sidecar
HomeDir string // HomeDir is the home directory of the chain

CoinType string // CoinType is the coin type of the chain (e.g. 118)
ChainId string // ChainId is the chain ID of the chain
Expand Down Expand Up @@ -125,12 +121,6 @@ func (c *ChainConfig) ValidateBasic() error {
return fmt.Errorf("image definition is invalid: %w", err)
}

if c.SidecarImage.Image != "" {
if err := c.SidecarImage.ValidateBasic(); err != nil {
return fmt.Errorf("sidecar image definition is invalid: %w", err)
}
}

if c.Bech32Prefix == "" {
return fmt.Errorf("bech32 prefix cannot be empty")
}
Expand Down
2 changes: 1 addition & 1 deletion core/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c NodeConfig) ValidateBasic() error {
}

// NodeDefinitionModifier is a type of function that given a NodeConfig modifies the task definition. It usually
// adds additional sidecars or modifies the entrypoint. This function is typically called in NodeCreator
// modifies the entrypoint. This function is typically called in NodeCreator
// before the task is created
type NodeDefinitionModifier func(provider.TaskDefinition, NodeConfig) provider.TaskDefinition

Expand Down
13 changes: 0 additions & 13 deletions cosmos/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@ func CreateNode(ctx context.Context, logger *zap.Logger, nodeConfig petritypes.N

chainConfig := nodeConfig.Chain.GetConfig()

var sidecars []provider.TaskDefinition

if chainConfig.SidecarHomeDir != "" {
sidecars = append(sidecars, provider.TaskDefinition{
Name: fmt.Sprintf("%s-sidecar-%d", nodeConfig.Name, 0), // todo(Zygimantass): fix this to support multiple sidecars
ContainerName: fmt.Sprintf("%s-sidecar-%d", nodeConfig.Name, 0),
Image: chainConfig.SidecarImage,
DataDir: chainConfig.SidecarHomeDir,
Ports: chainConfig.SidecarPorts,
Entrypoint: chainConfig.SidecarArgs,
})
}

def := provider.TaskDefinition{
Name: nodeConfig.Name,
ContainerName: nodeConfig.Name,
Expand Down

0 comments on commit d215eb1

Please sign in to comment.