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

reload only chainlink node dbs when performing restart of CL nodes #1346

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 12 additions & 9 deletions framework/components/clnode/clnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ import (
"context"
"errors"
"fmt"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/postgres"
tc "github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"os"
"path/filepath"
"sync"
"text/template"
"time"

"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
tc "github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"

"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/postgres"
)

const (
DefaultHTTPPort = "6688"
DefaultP2PPort = "6690"
DefaultHTTPPort = "6688"
DefaultP2PPort = "6690"
CLNodeContainerLabel = "clnode"
)

var (
Expand Down Expand Up @@ -151,7 +154,7 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
if in.Node.Name != "" {
containerName = in.Node.Name
} else {
containerName = framework.DefaultTCName("node")
containerName = framework.DefaultTCName(CLNodeContainerLabel)
}
customPorts := make([]string, 0)
for _, p := range in.Node.CustomPorts {
Expand Down
18 changes: 13 additions & 5 deletions framework/components/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package postgres
import (
"context"
"fmt"
"os"
"strings"
"time"

"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/google/uuid"
"github.com/testcontainers/testcontainers-go"
tcwait "github.com/testcontainers/testcontainers-go/wait"
"os"
"strings"
"time"

"github.com/smartcontractkit/chainlink-testing-framework/framework"
)

const (
Expand All @@ -20,10 +23,12 @@ const (
ExposedStaticPort = 13000
Database = "chainlink"
DBVolumeName = "postgresql_data"
DBContainerLabel = "postgresql"
)

type Input struct {
Image string `toml:"image" validate:"required"`
Name string `toml:"name"`
Port int `toml:"port"`
VolumeName string `toml:"volume_name"`
Databases int `toml:"databases"`
Expand All @@ -41,7 +46,10 @@ func NewPostgreSQL(in *Input) (*Output, error) {
ctx := context.Background()

bindPort := fmt.Sprintf("%s/tcp", Port)
containerName := framework.DefaultTCName("ns-postgresql")
if in.Name == "" {
in.Name = uuid.NewString()[0:5]
}
containerName := framework.DefaultTCName(fmt.Sprintf("%s-%s", DBContainerLabel, in.Name))

var sqlCommands []string
for i := 0; i <= in.Databases; i++ {
Expand Down
14 changes: 9 additions & 5 deletions framework/components/simple_node_set/node_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ package simple_node_set

import (
"fmt"
"slices"
"strings"
"sync"

"golang.org/x/sync/errgroup"

"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/clnode"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/postgres"
"golang.org/x/sync/errgroup"
"slices"
"strings"
"sync"
)

const (
DefaultHTTPPortStaticRangeStart = 10000
DefaultP2PStaticRangeStart = 12000
CLNodeContainerLabel = "clnode"
)

// Input is a node set configuration input
Expand Down Expand Up @@ -74,6 +77,7 @@ func printURLs(out *Output) {

func sharedDBSetup(in *Input, bcOut *blockchain.Output) (*Output, error) {
in.DbInput.Databases = in.Nodes
in.DbInput.Name = CLNodeContainerLabel
dbOut, err := postgres.NewPostgreSQL(in.DbInput)
if err != nil {
return nil, err
Expand Down Expand Up @@ -109,7 +113,7 @@ func sharedDBSetup(in *Input, bcOut *blockchain.Output) (*Output, error) {
}
}
if in.NodeSpecs[overrideIdx].Node.Name == "" {
nodeName = fmt.Sprintf("node%d", i)
nodeName = fmt.Sprintf("%s%d", CLNodeContainerLabel, i)
}
eg.Go(func() error {
var net string
Expand Down
9 changes: 7 additions & 2 deletions framework/components/simple_node_set/reload.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package simple_node_set

import (
"fmt"
"time"

"github.com/smartcontractkit/chainlink-testing-framework/framework/chaos"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
"time"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/postgres"
)

// UpgradeNodeSet updates nodes configuration TOML files
// this API is discouraged, however, you can use it if nodes require restart or configuration updates, temporarily!
func UpgradeNodeSet(in *Input, bc *blockchain.Output, wait time.Duration) (*Output, error) {
_, err := chaos.ExecPumba("rm --volumes=false re2:node.*|ns-postgresql.*", wait)
clNodeContainerNameRegex := fmt.Sprintf("%s.*", CLNodeContainerLabel)
clNodeDBContainerNameRegex := fmt.Sprintf("%s-%s.*", postgres.DBContainerLabel, CLNodeContainerLabel)
_, err := chaos.ExecPumba(fmt.Sprintf("rm --volumes=false re2:%s|%s", clNodeContainerNameRegex, clNodeDBContainerNameRegex), wait)
if err != nil {
return nil, err
}
Expand Down
Loading