Skip to content

Commit 0df7093

Browse files
committed
Adds Parrot helm chart
1 parent b182126 commit 0df7093

File tree

15 files changed

+291
-42
lines changed

15 files changed

+291
-42
lines changed

lib/charts/parrot/Chart.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v2
2+
name: parrot
3+
version: 0.1.0
4+
appVersion: "0.5.1"
5+
type: application
6+
description: Parrot enables dynamic mocking of HTTP calls.
7+
keywords:
8+
- mocking
9+
- mock-server
10+
- http-mock
11+
- http
12+
- test
13+
- test-server
14+
home: https://github.com/smartcontractkit/chainlink-testing-framework/tree/main/parrot
15+
sources:
16+
- https://github.com/smartcontractkit/chainlink-testing-framework/tree/main/parrot
17+
- https://hub.docker.com/repository/docker/kalverra/parrot/general
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "parrot.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "parrot.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "parrot.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "parrot.labels" -}}
37+
app: {{ include "parrot.fullname" . }}
38+
helm.sh/chart: {{ include "parrot.chart" . }}
39+
{{ include "parrot.selectorLabels" . }}
40+
{{- if .Chart.AppVersion }}
41+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
42+
{{- end }}
43+
app.kubernetes.io/managed-by: {{ .Release.Service }}
44+
{{- end }}
45+
46+
{{/*
47+
Selector labels
48+
*/}}
49+
{{- define "parrot.selectorLabels" -}}
50+
app.kubernetes.io/name: {{ include "parrot.fullname" . }}
51+
app.kubernetes.io/instance: {{ .Release.Name }}
52+
app: {{ include "parrot.fullname" . }}
53+
{{- end }}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: {{ include "parrot.fullname" . }}
5+
labels:
6+
{{- include "parrot.labels" . | nindent 4 }}
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
{{- include "parrot.selectorLabels" . | nindent 6 }}
12+
template:
13+
metadata:
14+
labels:
15+
{{- include "parrot.selectorLabels" . | nindent 8 }}
16+
spec:
17+
restartPolicy: Always
18+
containers:
19+
- name: {{ .Chart.Name }}
20+
image: "{{ .Values.image.repository }}:{{ .Values.image.version }}"
21+
imagePullPolicy: {{ .Values.image.pullPolicy }}
22+
env:
23+
- name: PARROT_PORT
24+
value: "80"
25+
- name: PARROT_LOG_LEVEL
26+
value: "{{ .Values.logLevel }}"
27+
- name: PARROT_HOST
28+
value: "0.0.0.0"
29+
ports:
30+
- name: http
31+
containerPort: {{ .Values.service.port }}
32+
protocol: TCP
33+
{{- if .Values.persistence.enabled }}
34+
volumeMounts:
35+
- name: data
36+
mountPath: {{ .Values.persistence.mountPath }}
37+
{{- end }}
38+
resources:
39+
limits:
40+
memory: {{ .Values.resources.limits.memory }}
41+
cpu: {{ .Values.resources.limits.cpu }}
42+
livenessProbe:
43+
httpGet:
44+
path: /health
45+
port: http
46+
periodSeconds: 30
47+
{{- if .Values.persistence.enabled }}
48+
volumes:
49+
- name: data
50+
persistentVolumeClaim:
51+
claimName: {{ include "parrot.fullname" . }}
52+
{{- end }}
53+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if .Values.persistence.enabled }}
2+
apiVersion: v1
3+
kind: PersistentVolumeClaim
4+
metadata:
5+
name: {{ include "parrot.fullname" . }}
6+
labels:
7+
{{- include "parrot.labels" . | nindent 4 }}
8+
spec:
9+
accessModes:
10+
- {{ .Values.persistence.accessMode | quote }}
11+
resources:
12+
requests:
13+
storage: {{ .Values.persistence.size | quote }}
14+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "parrot.fullname" . }}
5+
labels:
6+
{{- include "parrot.labels" . | nindent 4 }}
7+
spec:
8+
type: {{ .Values.service.type }}
9+
ports:
10+
- name: http
11+
protocol: TCP
12+
port: {{ .Values.service.port }}
13+
targetPort: http
14+
selector:
15+
{{- include "parrot.selectorLabels" . | nindent 4 }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: "{{ include "parrot.fullname" . }}-test-health"
5+
labels:
6+
{{- include "parrot.labels" . | nindent 4 }}
7+
annotations:
8+
"helm.sh/hook": test
9+
spec:
10+
containers:
11+
- name: wget
12+
image: busybox
13+
command: ['wget']
14+
args: ['{{ include "parrot.fullname" . }}:{{ .Values.service.port }}/health']
15+
restartPolicy: Never

lib/charts/parrot/values.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
replicas: 1
2+
3+
image:
4+
repository: kalverra/parrot
5+
version: v0.5.1
6+
imagePullPolicy: IfNotPresent
7+
8+
logLevel: trace
9+
10+
resources:
11+
limits:
12+
cpu: 250m
13+
memory: 256Mi
14+
15+
service:
16+
type: ClusterIP
17+
port: 80
18+
19+
persistence:
20+
enabled: true
21+
accessMode: ReadWriteOnce
22+
size: 1Gi
23+
mountPath: /app

parrot/Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
FROM scratch
22

3-
COPY parrot /parrot
3+
COPY parrot /app/parrot
44
ENV PARROT_PORT=80
5-
ENV PARROT_TRACE=true
5+
ENV PARROT_LOG_LEVEL=trace
6+
ENV PARROT_HOST=0.0.0.0
67
EXPOSE 80
78

8-
HEALTHCHECK --timeout=3s --start-interval=10ms --start-period=5s CMD [ "/parrot", "health" ]
9+
WORKDIR /app
910

10-
ENTRYPOINT [ "/parrot" ]
11+
HEALTHCHECK --timeout=3s --interval=30s --start-interval=1ms --start-period=3s CMD [ "./parrot", "health" ]
12+
13+
ENTRYPOINT [ "./parrot" ]

parrot/cmd/main.go

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@ import (
1313

1414
"github.com/rs/zerolog"
1515
"github.com/rs/zerolog/log"
16-
"github.com/smartcontractkit/chainlink-testing-framework/parrot"
1716
"github.com/spf13/cobra"
17+
18+
"github.com/smartcontractkit/chainlink-testing-framework/parrot"
19+
)
20+
21+
const (
22+
envPort = "PARROT_PORT"
23+
envLogLevel = "PARROT_LOG_LEVEL"
24+
envJSON = "PARROT_JSON"
25+
envRecorders = "PARROT_RECORDERS"
26+
envHost = "PARROT_HOST"
1827
)
1928

2029
func main() {
@@ -23,32 +32,38 @@ func main() {
2332
debug bool
2433
trace bool
2534
silent bool
35+
logLevel string
2636
json bool
2737
recorders []string
38+
host string
2839
)
2940

3041
preRun := func(cmd *cobra.Command, args []string) {
3142
// Check environment variables if flags are not set
3243
if !cmd.Flags().Changed("port") {
33-
if envPort, err := strconv.Atoi(os.Getenv("PARROT_PORT")); err == nil {
44+
if envPort, err := strconv.Atoi(os.Getenv(envPort)); err == nil {
3445
port = envPort
3546
}
3647
}
37-
if !cmd.Flags().Changed("debug") {
38-
debug = os.Getenv("PARROT_DEBUG") == "true"
39-
}
40-
if !cmd.Flags().Changed("trace") {
41-
trace = os.Getenv("PARROT_TRACE") == "true"
48+
if !cmd.Flags().Changed("host") {
49+
if addr := os.Getenv(envHost); addr != "" {
50+
host = addr
51+
}
4252
}
43-
if !cmd.Flags().Changed("silent") {
44-
silent = os.Getenv("PARROT_SILENT") == "true"
53+
if !cmd.Flags().Changed("debug") &&
54+
!cmd.Flags().Changed("trace") &&
55+
!cmd.Flags().Changed("silent") &&
56+
!cmd.Flags().Changed("logLevel") {
57+
if lvl := os.Getenv(envLogLevel); lvl != "" {
58+
logLevel = lvl
59+
}
4560
}
4661
if !cmd.Flags().Changed("json") {
47-
json = os.Getenv("PARROT_JSON") == "true"
62+
json = os.Getenv(envJSON) == "true"
4863
}
4964
if !cmd.Flags().Changed("recorders") {
50-
if envRecorders := os.Getenv("PARROT_RECORDERS"); envRecorders != "" {
51-
recorders = strings.Split(envRecorders, ",")
65+
if r := os.Getenv(envRecorders); r != "" {
66+
recorders = strings.Split(r, ",")
5267
}
5368
}
5469
}
@@ -58,18 +73,25 @@ func main() {
5873
Short: "A server that can register and parrot back dynamic requests",
5974
PreRun: preRun,
6075
RunE: func(cmd *cobra.Command, args []string) error {
61-
options := []parrot.ServerOption{parrot.WithPort(port)}
62-
logLevel := zerolog.InfoLevel
76+
options := []parrot.ServerOption{parrot.WithPort(port), parrot.WithHost(host)}
77+
zerologLevel := zerolog.InfoLevel
6378
if debug {
64-
logLevel = zerolog.DebugLevel
79+
zerologLevel = zerolog.DebugLevel
6580
}
6681
if trace {
67-
logLevel = zerolog.TraceLevel
82+
zerologLevel = zerolog.TraceLevel
6883
}
6984
if silent {
70-
logLevel = zerolog.Disabled
85+
zerologLevel = zerolog.Disabled
86+
}
87+
if logLevel != "" {
88+
parsedLevel, err := zerolog.ParseLevel(logLevel)
89+
if err != nil {
90+
return err
91+
}
92+
zerologLevel = parsedLevel
7193
}
72-
options = append(options, parrot.WithLogLevel(logLevel))
94+
options = append(options, parrot.WithLogLevel(zerologLevel))
7395
if json {
7496
options = append(options, parrot.WithJSONLogs())
7597
}
@@ -94,12 +116,14 @@ func main() {
94116
},
95117
}
96118

97-
rootCmd.PersistentFlags().IntVarP(&port, "port", "p", 0, "Port to run the parrot on (env: PARROT_PORT)")
98-
rootCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable debug output (env: PARROT_DEBUG)")
99-
rootCmd.Flags().BoolVarP(&trace, "trace", "t", false, "Enable trace and debug output (env: PARROT_TRACE)")
100-
rootCmd.Flags().BoolVarP(&silent, "silent", "s", false, "Disable all output (env: PARROT_SILENT)")
101-
rootCmd.Flags().BoolVarP(&json, "json", "j", false, "Output logs in JSON format (env: PARROT_JSON)")
102-
rootCmd.Flags().StringSliceVarP(&recorders, "recorders", "r", nil, "Existing recorders to use (env: PARROT_RECORDERS)")
119+
rootCmd.PersistentFlags().IntVarP(&port, "port", "p", 0, fmt.Sprintf("Port to run the parrot on (env: %s)", envPort))
120+
rootCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable debug output")
121+
rootCmd.Flags().BoolVarP(&trace, "trace", "t", false, "Enable trace and debug output")
122+
rootCmd.Flags().BoolVarP(&silent, "silent", "s", false, "Disable all output")
123+
rootCmd.Flags().StringVarP(&logLevel, "logLevel", "l", "", fmt.Sprintf("Set the log level (env: %s)", envLogLevel))
124+
rootCmd.Flags().BoolVarP(&json, "json", "j", false, fmt.Sprintf("Output logs in JSON format (env: %s)", envJSON))
125+
rootCmd.Flags().StringSliceVarP(&recorders, "recorders", "r", nil, fmt.Sprintf("Existing recorders to use (env: %s)", envRecorders))
126+
rootCmd.Flags().StringVar(&host, "host", "localhost", fmt.Sprintf("Host to run the parrot on. (env: %s)", envHost))
103127

104128
healthCheckCmd := &cobra.Command{
105129
Use: "health",

parrot/examples_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/rs/zerolog"
11+
1112
"github.com/smartcontractkit/chainlink-testing-framework/parrot"
1213
)
1314

@@ -237,7 +238,7 @@ func ExampleRecorder_external() {
237238
recorderHost := "localhost"
238239

239240
// Create a new recorder with our host
240-
recorder, err := parrot.NewRecorder(parrot.WithHost(recorderHost))
241+
recorder, err := parrot.NewRecorder(parrot.WithRecorderHost(recorderHost))
241242
if err != nil {
242243
panic(err)
243244
}

0 commit comments

Comments
 (0)