Преглед изворни кода

:seedling: Allow to specify minNodes in services

mudler пре 2 година
родитељ
комит
964d2f17c1
1 измењених фајлова са 15 додато и 2 уклоњено
  1. 15 2
      api/client/service/node.go

+ 15 - 2
api/client/service/node.go

@@ -45,6 +45,7 @@ type Node struct {
 	networkToken                             string
 	apiAddress                               string
 	defaultRoles, persistentRoles, stopRoles string
+	minNode                                  int
 
 	assets []string
 	fs     embed.FS
@@ -66,6 +67,13 @@ func WithRoles(k ...RoleKey) Option {
 	}
 }
 
+func WithMinNodes(i int) Option {
+	return func(k *Node) error {
+		k.minNode = i
+		return nil
+	}
+}
+
 // WithFS accepts an embed.FS file system where to copy binaries from
 func WithFS(fs embed.FS) Option {
 	return func(k *Node) error {
@@ -311,6 +319,11 @@ func (k *Node) Start(ctx context.Context) error {
 
 	k.client.Advertize(k.uuid)
 
+	minNode := 2
+	if k.minNode != 0 {
+		minNode = k.minNode
+	}
+
 	i := 0
 	for {
 		select {
@@ -340,8 +353,8 @@ func (k *Node) Start(ctx context.Context) error {
 			}
 
 			// Not enough nodes
-			if len(uuids) <= 1 {
-				k.logger.Info("not enough nodes available, sleeping...")
+			if len(uuids) < minNode {
+				k.logger.Infof("not enough nodes available, sleeping... needed: %d, available: %d", minNode, len(uuids))
 				continue
 			}