github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/k8s/examples/deployment_part/sol.go (about)

     1  package deployment_part
     2  
     3  import (
     4  	"github.com/rs/zerolog/log"
     5  
     6  	"github.com/smartcontractkit/chainlink-testing-framework/libs/k8s/client"
     7  	"github.com/smartcontractkit/chainlink-testing-framework/libs/k8s/environment"
     8  )
     9  
    10  type Props struct {
    11  	NetworkName string   `envconfig:"network_name"`
    12  	HttpURLs    []string `envconfig:"http_url"`
    13  	WsURLs      []string `envconfig:"ws_url"`
    14  	Values      map[string]interface{}
    15  }
    16  
    17  type HelmProps struct {
    18  	Name    string
    19  	Path    string
    20  	Version string
    21  	Values  *map[string]interface{}
    22  }
    23  
    24  type Chart struct {
    25  	HelmProps *HelmProps
    26  	Props     *Props
    27  }
    28  
    29  func (m Chart) IsDeploymentNeeded() bool {
    30  	return true
    31  }
    32  
    33  func (m Chart) GetProps() interface{} {
    34  	return m.Props
    35  }
    36  
    37  func (m Chart) GetName() string {
    38  	return m.HelmProps.Name
    39  }
    40  
    41  func (m Chart) GetPath() string {
    42  	return m.HelmProps.Path
    43  }
    44  
    45  func (m Chart) GetVersion() string {
    46  	return m.HelmProps.Version
    47  }
    48  
    49  func (m Chart) GetValues() *map[string]interface{} {
    50  	return m.HelmProps.Values
    51  }
    52  
    53  func (m Chart) ExportData(e *environment.Environment) error {
    54  	netLocal, err := e.Fwd.FindPort("sol:0", "sol-val", "http-rpc").As(client.LocalConnection, client.HTTP)
    55  	if err != nil {
    56  		return err
    57  	}
    58  	netLocalWS, err := e.Fwd.FindPort("sol:0", "sol-val", "ws-rpc").As(client.LocalConnection, client.WS)
    59  	if err != nil {
    60  		return err
    61  	}
    62  	netInternal, err := e.Fwd.FindPort("sol:0", "sol-val", "http-rpc").As(client.RemoteConnection, client.HTTP)
    63  	if err != nil {
    64  		return err
    65  	}
    66  	e.URLs[m.Props.NetworkName] = []string{netLocal, netLocalWS}
    67  	if e.Cfg.InsideK8s {
    68  		e.URLs[m.Props.NetworkName] = []string{netInternal}
    69  	}
    70  	log.Info().Str("Name", m.Props.NetworkName).Str("URLs", netLocal).Msg("Solana network")
    71  	return nil
    72  }
    73  
    74  func defaultProps() *Props {
    75  	return &Props{
    76  		NetworkName: "sol",
    77  		Values: map[string]interface{}{
    78  			"replicas": "1",
    79  			"sol": map[string]interface{}{
    80  				"image": map[string]interface{}{
    81  					"image":   "solanalabs/solana",
    82  					"version": "v1.9.14",
    83  				},
    84  				"resources": map[string]interface{}{
    85  					"requests": map[string]interface{}{
    86  						"cpu":    "2000m",
    87  						"memory": "4000Mi",
    88  					},
    89  					"limits": map[string]interface{}{
    90  						"cpu":    "2000m",
    91  						"memory": "4000Mi",
    92  					},
    93  				},
    94  			},
    95  		},
    96  	}
    97  }
    98  
    99  func New(props *Props) environment.ConnectedChart {
   100  	if props == nil {
   101  		props = defaultProps()
   102  	}
   103  	return Chart{
   104  		HelmProps: &HelmProps{
   105  			Name:   "sol",
   106  			Path:   "chainlink-qa/solana-validator",
   107  			Values: &props.Values,
   108  		},
   109  		Props: props,
   110  	}
   111  }