github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/k8s/pkg/helm/starknet/starknet.go (about)

     1  package starknet
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strconv"
     7  
     8  	"github.com/rs/zerolog/log"
     9  
    10  	"github.com/smartcontractkit/chainlink-testing-framework/libs/k8s/client"
    11  	"github.com/smartcontractkit/chainlink-testing-framework/libs/k8s/config"
    12  	"github.com/smartcontractkit/chainlink-testing-framework/libs/k8s/environment"
    13  	"github.com/smartcontractkit/chainlink-testing-framework/libs/utils/projectpath"
    14  )
    15  
    16  type Props struct {
    17  	NetworkName string   `envconfig:"network_name"`
    18  	HttpURLs    []string `envconfig:"http_url"`
    19  	WsURLs      []string `envconfig:"ws_url"`
    20  	Values      map[string]interface{}
    21  }
    22  
    23  type HelmProps struct {
    24  	Name    string
    25  	Path    string
    26  	Version string
    27  	Values  *map[string]interface{}
    28  }
    29  
    30  type Chart struct {
    31  	HelmProps *HelmProps
    32  	Props     *Props
    33  }
    34  
    35  func (m Chart) IsDeploymentNeeded() bool {
    36  	return true
    37  }
    38  
    39  func (m Chart) GetProps() interface{} {
    40  	return m.Props
    41  }
    42  
    43  func (m Chart) GetName() string {
    44  	return m.HelmProps.Name
    45  }
    46  
    47  func (m Chart) GetPath() string {
    48  	return m.HelmProps.Path
    49  }
    50  
    51  func (m Chart) GetVersion() string {
    52  	return m.HelmProps.Version
    53  }
    54  
    55  func (m Chart) GetValues() *map[string]interface{} {
    56  	return m.HelmProps.Values
    57  }
    58  
    59  func (m Chart) ExportData(e *environment.Environment) error {
    60  	devnetLocalHttp, err := e.Fwd.FindPort("starknet-dev:0", "starknetdev", "http").As(client.LocalConnection, client.HTTP)
    61  	if err != nil {
    62  		return err
    63  	}
    64  	devnetInternalHttp, err := e.Fwd.FindPort("starknet-dev:0", "starknetdev", "http").As(client.RemoteConnection, client.HTTP)
    65  	if err != nil {
    66  		return err
    67  	}
    68  	e.URLs[m.Props.NetworkName] = append(e.URLs[m.Props.NetworkName], devnetLocalHttp)
    69  	e.URLs[m.Props.NetworkName] = append(e.URLs[m.Props.NetworkName], devnetInternalHttp)
    70  	log.Info().Str("Name", "Devnet").Str("URLs", devnetLocalHttp).Msg("Devnet network")
    71  	return nil
    72  }
    73  
    74  func defaultProps() *Props {
    75  	return &Props{
    76  		NetworkName: "starknet-dev",
    77  		Values: map[string]interface{}{
    78  			"replicas": "1",
    79  			"starknet-dev": map[string]interface{}{
    80  				"image": map[string]interface{}{
    81  					"image":   "shardlabs/starknet-devnet",
    82  					"version": "v0.2.6",
    83  				},
    84  				"resources": map[string]interface{}{
    85  					"requests": map[string]interface{}{
    86  						"cpu":    "1000m",
    87  						"memory": "1024Mi",
    88  					},
    89  					"limits": map[string]interface{}{
    90  						"cpu":    "1000m",
    91  						"memory": "1024Mi",
    92  					},
    93  				},
    94  				"seed":      "123",
    95  				"real_node": "false",
    96  			},
    97  		},
    98  	}
    99  }
   100  
   101  func New(props *Props) environment.ConnectedChart {
   102  	return NewVersioned("", props)
   103  }
   104  
   105  func NewVersioned(helmVersion string, props *Props) environment.ConnectedChart {
   106  	if props == nil {
   107  		props = defaultProps()
   108  	}
   109  	chartPath := "chainlink-qa/starknet"
   110  	if b, err := strconv.ParseBool(os.Getenv(config.EnvVarLocalCharts)); err == nil && b {
   111  		chartPath = fmt.Sprintf("%s/starknet", projectpath.ChartsRoot)
   112  	}
   113  	return Chart{
   114  		HelmProps: &HelmProps{
   115  			Name:    "starknet-dev",
   116  			Path:    chartPath,
   117  			Values:  &props.Values,
   118  			Version: helmVersion,
   119  		},
   120  		Props: props,
   121  	}
   122  }