github.com/kotalco/kotal@v0.3.0/clients/polkadot/polkadot_client.go (about)

     1  package polkadot
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	polkadotv1alpha1 "github.com/kotalco/kotal/apis/polkadot/v1alpha1"
     8  	"github.com/kotalco/kotal/controllers/shared"
     9  	corev1 "k8s.io/api/core/v1"
    10  )
    11  
    12  // PolkadotClient is parity Polkadot client
    13  // https://github.com/paritytech/polkadot-sdk
    14  type PolkadotClient struct {
    15  	node *polkadotv1alpha1.Node
    16  }
    17  
    18  // Images
    19  const (
    20  	//  PolkadotHomeDir is go ipfs image home dir
    21  	PolkadotHomeDir = "/polkadot"
    22  )
    23  
    24  // Command returns environment variables for the client
    25  func (c *PolkadotClient) Env() []corev1.EnvVar {
    26  	return nil
    27  }
    28  
    29  // Command is go-ipfs entrypoint
    30  func (c *PolkadotClient) Command() []string {
    31  	return nil
    32  }
    33  
    34  // Args returns go-ipfs args
    35  func (c *PolkadotClient) Args() (args []string) {
    36  
    37  	node := c.node
    38  
    39  	args = append(args, PolkadotArgBasePath, shared.PathData(c.HomeDir()))
    40  	args = append(args, PolkadotArgChain, node.Spec.Network)
    41  	args = append(args, PolkadotArgName, node.Name)
    42  	args = append(args, PolkadotArgPort, fmt.Sprintf("%d", node.Spec.P2PPort))
    43  	args = append(args, PolkadotArgSync, string(node.Spec.SyncMode))
    44  	args = append(args, PolkadotArgLogging, string(node.Spec.Logging))
    45  
    46  	args = append(args, PolkadotArgDatabase, string(node.Spec.Database))
    47  
    48  	if node.Spec.Pruning != nil {
    49  		var pruning bool = *node.Spec.Pruning
    50  		if pruning {
    51  			args = append(args, PolkadotArgPruning, fmt.Sprintf("%d", node.Spec.RetainedBlocks))
    52  		} else {
    53  			args = append(args, PolkadotArgPruning, "archive")
    54  		}
    55  	}
    56  
    57  	if node.Spec.WS || node.Spec.RPC {
    58  		args = append(args, PolkadotArgRPCPort, fmt.Sprintf("%d", node.Spec.RPCPort))
    59  		args = append(args, PolkadotArgRPCExternal)
    60  		args = append(args, PolkadotArgRPCCors, strings.Join(node.Spec.CORSDomains, ","))
    61  	}
    62  
    63  	if node.Spec.NodePrivateKeySecretName != "" {
    64  		args = append(args, PolkadotArgNodeKeyType, "Ed25519")
    65  		args = append(args, PolkadotArgNodeKeyFile, fmt.Sprintf("%s/kotal_nodekey", shared.PathData(c.HomeDir())))
    66  	}
    67  
    68  	if node.Spec.Telemetry {
    69  		args = append(args, PolkadotArgTelemetryURL, node.Spec.TelemetryURL)
    70  	} else {
    71  		args = append(args, PolkadotArgNoTelemetry)
    72  	}
    73  
    74  	if node.Spec.Prometheus {
    75  		args = append(args, PolkadotArgPrometheusExternal)
    76  		args = append(args, PolkadotArgPrometheusPort, fmt.Sprintf("%d", node.Spec.PrometheusPort))
    77  	} else {
    78  		args = append(args, PolkadotArgNoPrometheus)
    79  	}
    80  
    81  	if node.Spec.Validator {
    82  		args = append(args, PolkadotArgValidator)
    83  	}
    84  
    85  	return
    86  }
    87  
    88  func (c *PolkadotClient) HomeDir() string {
    89  	return PolkadotHomeDir
    90  }