From d215eb1a98d63583241bec28b45893d2a255ce56 Mon Sep 17 00:00:00 2001 From: Zygimantas Date: Fri, 10 Jan 2025 11:45:11 +0100 Subject: [PATCH] fix: fully remove sidecars and lint --- core/provider/definitions.go | 2 +- core/provider/provider.go | 1 - core/provider/task.go | 40 ++++++++---------------------------- core/types/chain.go | 16 +++------------ core/types/node.go | 2 +- cosmos/node/node.go | 13 ------------ 6 files changed, 13 insertions(+), 61 deletions(-) diff --git a/core/provider/definitions.go b/core/provider/definitions.go index 1f91729..13e896f 100644 --- a/core/provider/definitions.go +++ b/core/provider/definitions.go @@ -41,7 +41,7 @@ type TaskDefinition struct { Command []string Args []string - ProviderSpecificConfig map[string]string + ProviderSpecificConfig interface{} } func (t *TaskDefinition) ValidateBasic() error { diff --git a/core/provider/provider.go b/core/provider/provider.go index 0fd099a..479ff13 100644 --- a/core/provider/provider.go +++ b/core/provider/provider.go @@ -23,7 +23,6 @@ type Task struct { ID string Definition TaskDefinition - Sidecars []*Task logger *zap.Logger mu sync.RWMutex diff --git a/core/provider/task.go b/core/provider/task.go index b244800..ab107b6 100644 --- a/core/provider/task.go +++ b/core/provider/task.go @@ -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) @@ -25,8 +25,6 @@ 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 { @@ -34,33 +32,23 @@ func CreateTask(ctx context.Context, logger *zap.Logger, provider Provider, defi 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 { @@ -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 { @@ -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 diff --git a/core/types/chain.go b/core/types/chain.go index 5fb11f7..1ab65e7 100644 --- a/core/types/chain.go +++ b/core/types/chain.go @@ -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 @@ -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 @@ -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 @@ -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") } diff --git a/core/types/node.go b/core/types/node.go index f916479..332912d 100644 --- a/core/types/node.go +++ b/core/types/node.go @@ -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 diff --git a/cosmos/node/node.go b/cosmos/node/node.go index 822a0ff..0f81a58 100644 --- a/cosmos/node/node.go +++ b/cosmos/node/node.go @@ -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,