Skip to content

Commit

Permalink
[node-split] Extend systest with option to add split node setup
Browse files Browse the repository at this point in the history
Note: split node setup will always deploy non smeshing node
to which there will be deployed connected n-1 activation nodes.
Because of that - node-split-size has to be set to 0 or >1.
  • Loading branch information
jellonek committed Dec 5, 2024
1 parent 913a87a commit 69979cf
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 11 deletions.
2 changes: 2 additions & 0 deletions systest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ level ?= debug
bootstrap ?= 5m
storage ?= standard=1Gi
node_selector ?=
node_split_size ?=
namespace ?=
count ?= 1
failfast ?= true
Expand Down Expand Up @@ -73,6 +74,7 @@ template:
@echo post-init-image=$(post_init_image) >> $(tmpfile)
@echo keep=$(keep) >> $(tmpfile)
@echo testid=$(test_id) >> $(tmpfile)
@echo node-split-size=$(node_split_size) >> $(tmpfile)

.PHONY: config
config: template
Expand Down
99 changes: 95 additions & 4 deletions systest/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
poetApp = "poet"
bootnodeApp = "boot"
smesherApp = "smesher"
activationApp = "activation"
postServiceApp = "postservice"
bootstrapperApp = "bootstrapper"
bootstrapperPort = 80
Expand Down Expand Up @@ -161,13 +162,14 @@ func ReuseWait(cctx *testcontext.Context, opts ...Opt) (*Cluster, error) {
func Default(cctx *testcontext.Context, opts ...Opt) (*Cluster, error) {
cl := New(cctx, opts...)

smeshers := cctx.ClusterSize - cctx.BootnodeSize - cctx.OldSize - cctx.RemoteSize
smeshers := cctx.ClusterSize - cctx.BootnodeSize - cctx.OldSize - cctx.RemoteSize - cctx.NodeSplitSize

cctx.Log.Desugar().Info("Using the following nodes",
zap.Int("total", cctx.ClusterSize),
zap.Int("bootnodes", cctx.BootnodeSize),
zap.Int("smeshers", smeshers),
zap.Int("old smeshers", cctx.OldSize),
zap.Int("node split setup", cctx.NodeSplitSize),
zap.Int("remote", cctx.RemoteSize),
)

Expand Down Expand Up @@ -196,20 +198,28 @@ func Default(cctx *testcontext.Context, opts ...Opt) (*Cluster, error) {
return nil, err
}

smesherKeys := keys[cctx.BootnodeSize : cctx.BootnodeSize+smeshers]
oldOffset := cctx.BootnodeSize + smeshers
smesherKeys := keys[cctx.BootnodeSize:oldOffset]
if err := cl.AddSmeshers(cctx, smeshers, WithSmeshers(smesherKeys)); err != nil {
return nil, err
}

oldKeys := keys[cctx.BootnodeSize+smeshers : cctx.BootnodeSize+smeshers+cctx.OldSize]
remoteOffset := oldOffset + cctx.OldSize
oldKeys := keys[oldOffset:remoteOffset]
if err := cl.AddSmeshers(cctx, cctx.OldSize, WithSmeshers(oldKeys), WithImage(cctx.OldImage)); err != nil {
return nil, err
}

remoteKeys := keys[cctx.BootnodeSize+smeshers+cctx.OldSize:]
splitNodeOffset := remoteOffset + cctx.NodeSplitSize
remoteKeys := keys[remoteOffset:splitNodeOffset]
if err := cl.AddRemoteSmeshers(cctx, cctx.RemoteSize, WithSmeshers(remoteKeys)); err != nil {
return nil, err
}

splitNodeKeys := keys[splitNodeOffset:]
if err := cl.AddSplitNodes(cctx, cctx.NodeSplitSize, WithSmeshers(splitNodeKeys)); err != nil {
return nil, err
}
return cl, nil
}

Expand Down Expand Up @@ -315,6 +325,16 @@ func (c *Cluster) persistConfigs(ctx *testcontext.Context) error {
if err != nil {
return fmt.Errorf("apply cfgmap %v/%v: %w", ctx.Namespace, spacemeshConfigMapName, err)
}
_, err = ctx.Client.CoreV1().ConfigMaps(ctx.Namespace).Apply(
ctx,
corev1.ConfigMap(activationConfigMapName, ctx.Namespace).WithData(map[string]string{
attachedActivationConfig: activationConfig.Get(ctx.Parameters),
}),
apimetav1.ApplyOptions{FieldManager: "test"},
)
if err != nil {
return fmt.Errorf("apply cfgmap %v/%v: %w", ctx.Namespace, spacemeshConfigMapName, err)
}
_, err = ctx.Client.CoreV1().ConfigMaps(ctx.Namespace).Apply(
ctx,
corev1.ConfigMap(certifierConfigMapName, ctx.Namespace).WithData(map[string]string{
Expand Down Expand Up @@ -417,6 +437,16 @@ func (c *Cluster) reuse(cctx *testcontext.Context) error {
c.clients = append(c.clients, clients...)
c.smeshers = len(clients)

clients, err = discoverNodes(cctx, activationApp)
if err != nil {
return err
}
for _, node := range clients {
cctx.Log.Debugw("discovered existing activation nodes", "name", node.Name)
}
c.clients = append(c.clients, clients...)
c.smeshers += len(clients)

c.poets, err = discoverNodes(cctx, poetApp)
if err != nil {
return err
Expand Down Expand Up @@ -641,6 +671,67 @@ func (c *Cluster) AddRemoteSmeshers(tctx *testcontext.Context, n int, opts ...De
return nil
}

func (c *Cluster) AddSplitNodes(tctx *testcontext.Context, n int, opts ...DeploymentOpt) error {
if n == 0 {
return nil
}
if n == 1 {
return errors.New("split nodes size has to be at least 2 while provided size is 1")
}
if err := c.resourceControl(tctx, n); err != nil {
return err
}
if err := c.persist(tctx); err != nil {
return err
}
flags := maps.Values(c.smesherFlags)
endpoints, err := ExtractP2PEndpoints(tctx, c.clients[:c.bootnodes])
if err != nil {
return fmt.Errorf("extracting p2p endpoints %w", err)
}

cfg := SmesherDeploymentConfig{}
for _, opt := range opts {
opt(&cfg)
}
keys := cfg.keys

// deploy a single node-service
dopts := []DeploymentOpt{
WithFlags(flags...),
WithFlags(Bootnodes(endpoints...), StartSmeshing(false)),
WithSmeshers(keys[:1]),
}
clients, err := deployNodes(tctx, smesherApp, c.nextSmesher(), c.nextSmesher()+1, dopts...)
if err != nil {
return err
}
c.clients = append(c.clients, clients...)
c.smeshers += len(clients)

nodeServer := clients[0]
c.Wait(tctx, len(c.clients)-1)

if err := deployNodeSvc(tctx, nodeServer.Name); err != nil {
return err
}

// deploy client services
dopts = []DeploymentOpt{
WithFlags(flags...),
WithFlags(StartSmeshing(true)),
WithSmeshers(keys[1:]),
}
clients, err = deployActivationNodes(
tctx, nodeServer.Name, c.nextSmesher(), c.nextSmesher()+n-1, dopts...)
if err != nil {
return err
}
c.clients = append(c.clients, clients...)
c.smeshers += len(clients)
return nil
}

func (c *Cluster) AddBootstrapper(cctx *testcontext.Context, i int) error {
if err := c.persist(cctx); err != nil {
return err
Expand Down
Loading

0 comments on commit 69979cf

Please sign in to comment.