github.com/kotalco/kotal@v0.3.0/clients/ipfs/go_ipfs_cluster_client.go (about)

     1  package ipfs
     2  
     3  import (
     4  	"strings"
     5  
     6  	ipfsv1alpha1 "github.com/kotalco/kotal/apis/ipfs/v1alpha1"
     7  	"github.com/kotalco/kotal/controllers/shared"
     8  	corev1 "k8s.io/api/core/v1"
     9  )
    10  
    11  // GoIPFSClusterClient is ipfs cluster service client
    12  // https://github.com/ipfs/ipfs-cluster
    13  type GoIPFSClusterClient struct {
    14  	peer *ipfsv1alpha1.ClusterPeer
    15  }
    16  
    17  const (
    18  	//  GoIPFSClusterHomeDir is go ipfs cluster image home dir
    19  	GoIPFSClusterHomeDir = "/home/ipfs-cluster"
    20  )
    21  
    22  // Command returns go ipfs cluster entrypoint
    23  func (c *GoIPFSClusterClient) Command() []string {
    24  	return []string{"ipfs-cluster-service"}
    25  }
    26  
    27  // Command returns environment variables for the client
    28  func (c *GoIPFSClusterClient) Env() []corev1.EnvVar {
    29  	return []corev1.EnvVar{
    30  		{
    31  			Name:  EnvIPFSClusterPath,
    32  			Value: shared.PathData(c.HomeDir()),
    33  		},
    34  		{
    35  			Name:  EnvIPFSClusterPeerName,
    36  			Value: c.peer.Name,
    37  		},
    38  		{
    39  			Name:  EnvIPFSLogging,
    40  			Value: string(c.peer.Spec.Logging),
    41  		},
    42  	}
    43  }
    44  
    45  // Arg returns go ipfs cluster arguments
    46  func (c *GoIPFSClusterClient) Args() (args []string) {
    47  	args = append(args, GoIPFSClusterDaemonArg)
    48  
    49  	if len(c.peer.Spec.BootstrapPeers) != 0 {
    50  		args = append(args, GoIPFSClusterBootstrapArg, strings.Join(c.peer.Spec.BootstrapPeers, ","))
    51  	}
    52  
    53  	return
    54  }
    55  
    56  // HomeDir returns go ipfs cluster image home directory
    57  func (c *GoIPFSClusterClient) HomeDir() string {
    58  	return GoIPFSClusterHomeDir
    59  }