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

     1  package kafka_rest
     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  }
    18  
    19  type Chart struct {
    20  	Name    string
    21  	Path    string
    22  	Version string
    23  	Props   *Props
    24  	Values  *map[string]interface{}
    25  }
    26  
    27  func (m Chart) IsDeploymentNeeded() bool {
    28  	return true
    29  }
    30  
    31  func (m Chart) GetName() string {
    32  	return m.Name
    33  }
    34  
    35  func (m Chart) GetPath() string {
    36  	return m.Path
    37  }
    38  
    39  func (m Chart) GetVersion() string {
    40  	return m.Version
    41  }
    42  
    43  func (m Chart) GetProps() interface{} {
    44  	return m.Props
    45  }
    46  
    47  func (m Chart) GetValues() *map[string]interface{} {
    48  	return m.Values
    49  }
    50  
    51  func (m Chart) ExportData(e *environment.Environment) error {
    52  	urls := make([]string, 0)
    53  	local, err := e.Fwd.FindPort("cp-kafka-rest:0", "kafka-rest", "http").As(client.LocalConnection, client.HTTP)
    54  	if err != nil {
    55  		return err
    56  	}
    57  	remote, err := e.Fwd.FindPort("cp-kafka-rest:0", "kafka-rest", "http").As(client.RemoteConnection, client.HTTP)
    58  	if err != nil {
    59  		return err
    60  	}
    61  	if e.Cfg.InsideK8s {
    62  		urls = append(urls, remote, remote)
    63  	} else {
    64  		urls = append(urls, local, remote)
    65  	}
    66  	e.URLs["cp-kafka-rest"] = urls
    67  	log.Info().Str("URL", local).Msg("KafkaRest local connection")
    68  	log.Info().Str("URL", remote).Msg("KafkaRest remote connection")
    69  	return nil
    70  }
    71  
    72  func defaultProps() map[string]interface{} {
    73  	return map[string]interface{}{}
    74  }
    75  
    76  func New(props map[string]interface{}) environment.ConnectedChart {
    77  	return NewVersioned("", props)
    78  }
    79  
    80  // NewVersioned enables choosing a specific helm chart version
    81  func NewVersioned(helmVersion string, props map[string]interface{}) environment.ConnectedChart {
    82  	dp := defaultProps()
    83  	config.MustMerge(&dp, props)
    84  	chartPath := "chainlink-qa/kafka-rest"
    85  	if b, err := strconv.ParseBool(os.Getenv(config.EnvVarLocalCharts)); err == nil && b {
    86  		chartPath = fmt.Sprintf("%s/kafka-rest", projectpath.ChartsRoot)
    87  	}
    88  	return Chart{
    89  		Name:    "cp-kafka-rest",
    90  		Path:    chartPath,
    91  		Values:  &dp,
    92  		Version: helmVersion,
    93  	}
    94  }