Skip to content

Commit b123355

Browse files
committed
Parrot K8s compatibility
1 parent 36cb050 commit b123355

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed

lib/docker/test_env/parrot.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
tcwait "github.com/testcontainers/testcontainers-go/wait"
1313

1414
"github.com/smartcontractkit/chainlink-testing-framework/lib/docker"
15+
"github.com/smartcontractkit/chainlink-testing-framework/lib/k8s/environment"
16+
helm_parrot "github.com/smartcontractkit/chainlink-testing-framework/lib/k8s/pkg/helm/parrot"
1517
"github.com/smartcontractkit/chainlink-testing-framework/lib/logging"
1618
"github.com/smartcontractkit/chainlink-testing-framework/lib/mirror"
1719
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"
@@ -67,6 +69,13 @@ func ConnectParrot(url string) *Parrot {
6769
}
6870
}
6971

72+
// ConnectParrotTestEnv connects to an existing Parrot server in a running test environment.
73+
func ConnectParrotTestEnv(e *environment.Environment) *Parrot {
74+
return &Parrot{
75+
Client: parrot.NewClient(e.URLs[helm_parrot.LocalURLsKey][0]),
76+
}
77+
}
78+
7079
// WithTestInstance configures the MockServer with a test logger and test context.
7180
// It returns the updated MockServer instance for use in testing scenarios.
7281
func (p *Parrot) WithTestInstance(t *testing.T) *Parrot {

lib/k8s/pkg/helm/parrot/parrot.go

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package parrot
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strconv"
7+
8+
"github.com/smartcontractkit/chainlink-testing-framework/lib/k8s/client"
9+
"github.com/smartcontractkit/chainlink-testing-framework/lib/k8s/config"
10+
"github.com/smartcontractkit/chainlink-testing-framework/lib/k8s/environment"
11+
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/projectpath"
12+
13+
"github.com/rs/zerolog/log"
14+
)
15+
16+
const (
17+
LocalURLsKey = "parrot_local"
18+
InternalURLsKey = "parrot_internal"
19+
)
20+
21+
type Props struct {
22+
}
23+
24+
type Chart struct {
25+
Name string
26+
Path string
27+
Version string
28+
Props *Props
29+
Values *map[string]interface{}
30+
}
31+
32+
func (m Chart) IsDeploymentNeeded() bool {
33+
return true
34+
}
35+
36+
func (m Chart) GetName() string {
37+
return m.Name
38+
}
39+
40+
func (m Chart) GetPath() string {
41+
return m.Path
42+
}
43+
44+
func (m Chart) GetVersion() string {
45+
return m.Version
46+
}
47+
48+
func (m Chart) GetProps() interface{} {
49+
return m.Props
50+
}
51+
52+
func (m Chart) GetValues() *map[string]interface{} {
53+
return m.Values
54+
}
55+
56+
func (m Chart) GetLabels() map[string]string {
57+
return map[string]string{
58+
"chain.link/component": "parrot",
59+
}
60+
}
61+
62+
func (m Chart) ExportData(e *environment.Environment) error {
63+
parrotLocal, err := e.Fwd.FindPort("parrot:0", "parrot", "http").As(client.LocalConnection, client.HTTP)
64+
if err != nil {
65+
return err
66+
}
67+
services, err := e.Client.ListServices(e.Cfg.Namespace, fmt.Sprintf("app=%s", m.Name))
68+
if err != nil {
69+
return err
70+
}
71+
var parrotInternal string
72+
if services != nil && len(services.Items) != 0 {
73+
parrotInternal = fmt.Sprintf("http://%s:80", services.Items[0].Name)
74+
} else {
75+
parrotInternal, err = e.Fwd.FindPort("parrot:0", "parrot", "http").As(client.RemoteConnection, client.HTTP)
76+
if err != nil {
77+
return err
78+
}
79+
}
80+
if e.Cfg.InsideK8s {
81+
parrotLocal = parrotInternal
82+
}
83+
84+
e.URLs[LocalURLsKey] = []string{parrotLocal}
85+
e.URLs[InternalURLsKey] = []string{parrotInternal}
86+
log.Info().Str("Local Connection", parrotLocal).Str("Internal Connection", parrotInternal).Msg("Parrot")
87+
return nil
88+
}
89+
90+
func defaultProps() map[string]interface{} {
91+
internalRepo := os.Getenv(config.EnvVarInternalDockerRepo)
92+
mockserverRepo := "parrot"
93+
if internalRepo != "" {
94+
mockserverRepo = fmt.Sprintf("%s/parrot", internalRepo)
95+
}
96+
97+
return map[string]interface{}{
98+
"replicaCount": "1",
99+
"service": map[string]interface{}{
100+
"type": "NodePort",
101+
"port": "1080",
102+
},
103+
"app": map[string]interface{}{
104+
"logLevel": "INFO",
105+
"serverPort": "1080",
106+
"mountedConfigMapName": "mockserver-config",
107+
"propertiesFileName": "mockserver.properties",
108+
"readOnlyRootFilesystem": "false",
109+
"resources": map[string]interface{}{
110+
"requests": map[string]interface{}{
111+
"cpu": "200m",
112+
"memory": "256Mi",
113+
},
114+
"limits": map[string]interface{}{
115+
"cpu": "200m",
116+
"memory": "256Mi",
117+
},
118+
},
119+
},
120+
"image": map[string]interface{}{
121+
"repository": mockserverRepo,
122+
"version": "5.15.0",
123+
"snapshot": false,
124+
"pullPolicy": "IfNotPresent",
125+
},
126+
}
127+
}
128+
129+
func New(props map[string]interface{}) environment.ConnectedChart {
130+
return NewVersioned("", props)
131+
}
132+
133+
// NewVersioned enables choosing a specific helm chart version
134+
func NewVersioned(helmVersion string, props map[string]interface{}) environment.ConnectedChart {
135+
dp := defaultProps()
136+
config.MustMerge(&dp, props)
137+
chartPath := "chainlink-qa/parrot"
138+
if b, err := strconv.ParseBool(os.Getenv(config.EnvVarLocalCharts)); err == nil && b {
139+
chartPath = fmt.Sprintf("%s/parrot", projectpath.ChartsRoot)
140+
}
141+
return Chart{
142+
Name: "parrot",
143+
Path: chartPath,
144+
Values: &dp,
145+
Version: helmVersion,
146+
}
147+
}

0 commit comments

Comments
 (0)