Skip to content

Commit

Permalink
Merge branch 'main' into TT-1275-killgrave-requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tateexon authored Jun 14, 2024
2 parents c1269aa + b7cb200 commit c680581
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
28 changes: 14 additions & 14 deletions k8s/pkg/helm/foundry/foundry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/google/uuid"
"github.com/rs/zerolog/log"

"github.com/smartcontractkit/chainlink-testing-framework/k8s/client"
Expand All @@ -12,15 +13,15 @@ import (
)

const (
ChartName = "foundry"
ChartName = "foundry" // Chart name as defined in Chart.yaml
)

type Props struct {
Values map[string]interface{}
}

type Chart struct {
ServiceName string
Name string
AppLabel string
Path string
Version string
Expand All @@ -37,7 +38,7 @@ func (m Chart) IsDeploymentNeeded() bool {
}

func (m Chart) GetName() string {
return ChartName
return m.Name
}

func (m Chart) GetPath() string {
Expand All @@ -57,7 +58,7 @@ func (m Chart) GetValues() *map[string]interface{} {
}

func (m *Chart) ExportData(e *environment.Environment) error {
appInstance := fmt.Sprintf("%s:0", m.ServiceName) // uniquely identifies an instance of an anvil service running in a pod
appInstance := fmt.Sprintf("%s:0", m.Name) // uniquely identifies an instance of an anvil service running in a pod
var err error
m.ForwardedHTTPURL, err = e.Fwd.FindPort(appInstance, ChartName, "http").As(client.LocalConnection, client.HTTP)
if err != nil {
Expand Down Expand Up @@ -108,21 +109,20 @@ func NewVersioned(helmVersion string, props *Props) *Chart {
dp := defaultProps()
config.MustMerge(dp, props)
config.MustMerge(&dp.Values, props.Values)
var serviceName, appLabel string
// If fullnameOverride is set it is used as the service name and app label
var name string
if props.Values["fullnameOverride"] != nil {
serviceName = dp.Values["fullnameOverride"].(string)
appLabel = fmt.Sprintf("app=%s", dp.Values["fullnameOverride"].(string))
// If fullnameOverride is set it is used as the service name and app label
name = dp.Values["fullnameOverride"].(string)
} else {
serviceName = ChartName
appLabel = fmt.Sprintf("app=%s", ChartName)
// Use default name with random suffix to allow multiple charts in the same namespace
name = fmt.Sprintf("anvil-%s", uuid.New().String()[0:5])
}
anvilValues := dp.Values["anvil"].(map[string]any)
return &Chart{
ServiceName: serviceName,
ClusterWSURL: fmt.Sprintf("ws://%s:%s", serviceName, anvilValues["port"].(string)),
ClusterHTTPURL: fmt.Sprintf("http://%s:%s", serviceName, anvilValues["port"].(string)),
AppLabel: appLabel,
Name: name,
AppLabel: fmt.Sprintf("app=%s", name),
ClusterWSURL: fmt.Sprintf("ws://%s:%s", name, anvilValues["port"].(string)),
ClusterHTTPURL: fmt.Sprintf("http://%s:%s", name, anvilValues["port"].(string)),
Path: "chainlink-qa/foundry",
Values: &dp.Values,
Props: dp,
Expand Down
43 changes: 43 additions & 0 deletions k8s/pkg/helm/foundry/foundry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package foundry

import (
"fmt"
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
)

func TestChartNameUniqueness(t *testing.T) {
props := defaultProps()

// Create two Chart instances
chart1 := NewVersioned("", props)
chart2 := NewVersioned("", props)

// Assert that the names of the charts are unique
require.NotEqual(t, chart1.GetName(), chart2.GetName(), "Chart names should be unique")
}

func TestChartNameWithFullNameOverrideUniqueness(t *testing.T) {
// Generate unique names for testing
name1 := fmt.Sprintf("custom-%s", uuid.New().String()[0:5])
name2 := fmt.Sprintf("custom-%s", uuid.New().String()[0:5])

// Create two Chart instances with different fullnameOverride
chart1 := NewVersioned("", &Props{
Values: map[string]interface{}{
"fullnameOverride": name1,
},
})
chart2 := NewVersioned("", &Props{
Values: map[string]interface{}{
"fullnameOverride": name2,
},
})

// Assert that the names of the charts are unique and correct
require.Equal(t, name1, chart1.GetName(), "Chart name should match the fullnameOverride")
require.Equal(t, name2, chart2.GetName(), "Chart name should match the fullnameOverride")
require.NotEqual(t, chart1.GetName(), chart2.GetName(), "Chart names should be unique when fullnameOverrides are different")
}

0 comments on commit c680581

Please sign in to comment.