Skip to content

Commit 864ca95

Browse files
alexrasheddfangl
andauthored
add external service ports, additional configs, k8s lambda executor (#64)
Co-authored-by: Daniel Fangl <[email protected]>
1 parent 4416755 commit 864ca95

9 files changed

+160
-24
lines changed

charts/localstack/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ annotations:
22
category: Infrastructure
33
apiVersion: v2
44
appVersion: latest
5-
version: 0.4.3
5+
version: 0.5.0
66
name: localstack
77
description: LocalStack - a fully functional local AWS cloud stack
88
type: application

charts/localstack/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ The following table lists the configurable parameters of the Localstack chart an
106106
|------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------|
107107
| `service.type` | Kubernetes Service type | `NodePort` |
108108
| `service.edgeService.targetPort` | Port number for Localstack edge service | `4566` |
109-
| `service.apiServices[0].targetPort` | Port number for Localstack elasticsearch service | `4571` |
109+
| `service.externalServicePorts.start` | Start of the external service port range (included). service | `4510` |
110+
| `service.externalServicePorts.end` | End of the external service port range (excluded). service | `4560` |
110111
| `service.loadBalancerIP` | loadBalancerIP if Localstack service type is `LoadBalancer` | `nil` |
111112
| `ingress.enabled` | Enable the use of the ingress controller to access Localstack service | `false` |
112113
| `ingress.annotations` | Annotations for the Localstack Ingress | `{}` |

charts/localstack/templates/_helpers.tpl

+35
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,41 @@ Create the name of the service account to use
6060
{{- default "default" .Values.serviceAccount.name }}
6161
{{- end }}
6262
{{- end }}
63+
{{/*
64+
Create the role name for the pods/* role
65+
*/}}
66+
{{- define "localstack.roleName" -}}
67+
{{- if .Values.role.create }}
68+
{{- default (include "localstack.fullname" .) .Values.role.name }}
69+
{{- else }}
70+
{{- default "default" .Values.role.name }}
71+
{{- end }}
72+
{{- end }}
73+
74+
{{/*
75+
Create the RoleBinding name for the service account
76+
*/}}
77+
{{- define "localstack.roleBindingName" -}}
78+
{{- if .Values.role.create }}
79+
{{- default (include "localstack.fullname" .) .Values.role.name }}
80+
{{- else }}
81+
{{- default "default" .Values.role.name }}
82+
{{- end }}
83+
{{- end }}
84+
85+
{{- define "localstack.lambda.prepare_labels" -}}
86+
{{- if .Values.lambda.labels }}
87+
{{- range $key, $value := .Values.lambda.labels -}}
88+
{{ $key }}={{ $value }},
89+
{{- end }}
90+
{{- end }}
91+
{{- end }}
92+
93+
{{- define "localstack.lambda.labels" -}}
94+
{{- if include "localstack.lambda.prepare_labels" . -}}
95+
{{ include "localstack.lambda.prepare_labels" . | trimSuffix "," }}
96+
{{- end }}
97+
{{- end }}
6398

6499
{{/*
65100
Add extra annotations to every resource

charts/localstack/templates/deployment.yaml

+38-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ metadata:
77
{{- include "localstack.labels" . | nindent 4 }}
88
annotations:
99
{{- include "localstack.annotations" . | nindent 4 }}
10+
{{- with .Values.service.annotations }}
11+
{{- tpl (toYaml .) $ | nindent 4 }}
12+
{{- end }}
1013
spec:
1114
replicas: {{ .Values.replicaCount }}
1215
strategy: {{- include "common.tplvalues.render" (dict "value" .Values.updateStrategy "context" $ ) | nindent 4 }}
@@ -39,9 +42,9 @@ spec:
3942
- name: {{ .Values.service.edgeService.name }}
4043
containerPort: {{ .Values.service.edgeService.targetPort }}
4144
protocol: TCP
42-
{{- range .Values.service.apiServices }}
43-
- name: {{ .name }}
44-
containerPort: {{ .targetPort }}
45+
{{- range untilStep (.Values.service.externalServicePorts.start|int) (.Values.service.externalServicePorts.end|int) 1 }}
46+
- name: "ext-svc-{{ . }}"
47+
containerPort: {{ . }}
4548
protocol: TCP
4649
{{- end }}
4750
livenessProbe:
@@ -74,6 +77,14 @@ spec:
7477
env:
7578
- name: DEBUG
7679
value: {{ ternary "1" "0" .Values.debug | quote }}
80+
{{- if .Values.service.externalServicePorts.start }}
81+
- name: EXTERNAL_SERVICE_PORTS_START
82+
value: {{ .Values.service.externalServicePorts.start | quote }}
83+
{{- end }}
84+
{{- if .Values.service.externalServicePorts.end }}
85+
- name: EXTERNAL_SERVICE_PORTS_END
86+
value: {{ .Values.service.externalServicePorts.end | quote }}
87+
{{- end }}
7788
{{- if .Values.kinesisErrorProbability }}
7889
- name: KINESIS_ERROR_PROBABILITY
7990
value: {{ .Values.kinesisErrorProbability | quote }}
@@ -82,6 +93,28 @@ spec:
8293
- name: LAMBDA_EXECUTOR
8394
value: {{ .Values.lambdaExecutor | quote }}
8495
{{- end }}
96+
- name: LOCALSTACK_K8S_SERVICE_NAME
97+
value: {{ include "localstack.fullname" . }}
98+
- name: LOCALSTACK_K8S_NAMESPACE
99+
valueFrom:
100+
fieldRef:
101+
fieldPath: metadata.namespace
102+
{{- if include "localstack.lambda.labels" . }}
103+
- name: LAMBDA_K8S_LABELS
104+
value: {{ include "localstack.lambda.labels" . | quote }}
105+
{{- end }}
106+
{{- if .Values.lambda.executor }}
107+
- name: LAMBDA_RUNTIME_EXECUTOR
108+
value: {{ .Values.lambda.executor | quote }}
109+
{{- end }}
110+
{{- if .Values.lambda.image_prefix }}
111+
- name: LAMBDA_K8S_IMAGE_PREFIX
112+
value: {{ .Values.lambda.image_prefix | quote }}
113+
{{- end }}
114+
{{- if .Values.lambda.environment_timeout }}
115+
- name: LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT
116+
value: {{ .Values.lambda.environment_timeout | quote }}
117+
{{- end }}
85118
{{- if .Values.persistence.enabled }}
86119
- name: DATA_DIR
87120
value: /tmp/localstack/data
@@ -90,6 +123,8 @@ spec:
90123
- name: SERVICES
91124
value: {{ .Values.startServices | quote }}
92125
{{- end }}
126+
- name: OVERRIDE_IN_DOCKER
127+
value: "1"
93128
{{- if .Values.mountDind.enabled }}
94129
{{- if .Values.mountDind.forceTLS }}
95130
- name: DOCKER_HOST

charts/localstack/templates/role.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if .Values.serviceAccount.create -}}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: Role
4+
metadata:
5+
namespace: {{ .Release.Namespace | quote }}
6+
name: {{ include "localstack.roleName" . }}
7+
labels:
8+
{{- include "localstack.labels" . | nindent 4 }}
9+
rules:
10+
- apiGroups: [""] # "" indicates the core API group
11+
resources: ["pods"]
12+
verbs: ["*"]
13+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- if .Values.role.create -}}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: RoleBinding
4+
metadata:
5+
name: {{ include "localstack.roleBindingName" . }}
6+
namespace: {{ .Release.Namespace | quote }}
7+
labels:
8+
{{- include "localstack.labels" . | nindent 4 }}
9+
subjects:
10+
# You can specify more than one "subject"
11+
- kind: ServiceAccount
12+
name: {{ include "localstack.serviceAccountName" . }}
13+
roleRef:
14+
kind: Role
15+
name: {{ include "localstack.roleName" . }}
16+
apiGroup: rbac.authorization.k8s.io
17+
{{- end }}

charts/localstack/templates/service.yaml

+13-7
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,26 @@ spec:
1818
{{- if and (eq .Values.service.type "LoadBalancer") (not (empty .Values.service.loadBalancerIP)) }}
1919
loadBalancerIP: {{ .Values.service.loadBalancerIP }}
2020
{{- end }}
21+
{{- if .Values.service.ipFamilies }}
22+
ipFamilies:
23+
{{- with .Values.service.ipFamilies }}
24+
{{- tpl (toYaml .) $ | nindent 4 }}
25+
{{- end }}
26+
{{- end }}
27+
{{- if .Values.service.ipFamilyPolicy }}
28+
ipFamilyPolicy: {{ .Values.service.ipFamilyPolicy }}
29+
{{- end }}
2130
ports:
2231
- name: {{ .Values.service.edgeService.name }}
2332
port: {{ .Values.service.edgeService.targetPort }}
2433
targetPort: {{ .Values.service.edgeService.targetPort }}
2534
{{- if and (or (eq $.Values.service.type "NodePort") (eq $.Values.service.type "LoadBalancer")) (not (empty .Values.service.edgeService.nodePort)) }}
2635
nodePort: {{ .Values.service.edgeService.nodePort }}
2736
{{- end }}
28-
{{- range .Values.service.apiServices }}
29-
- name: {{ .name }}
30-
port: {{ .targetPort }}
31-
targetPort: {{ .targetPort }}
32-
{{- if and (or (eq $.Values.service.type "NodePort") (eq $.Values.service.type "LoadBalancer")) (not (empty .nodePort)) }}
33-
nodePort: {{ .nodePort }}
34-
{{- end }}
37+
{{- range untilStep (.Values.service.externalServicePorts.start|int) (.Values.service.externalServicePorts.end|int) 1 }}
38+
- name: "external-service-port-{{ . }}"
39+
port: {{ . }}
40+
targetPort: "ext-svc-{{ . }}"
3541
{{- end }}
3642
selector:
3743
{{- include "localstack.selectorLabels" . | nindent 4 }}

charts/localstack/templates/tests/test-connection.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,4 @@ spec:
1616
image: busybox
1717
command: ['wget']
1818
args: ['{{ include "localstack.fullname" . }}:{{ .Values.service.edgeService.targetPort }}/health']
19-
{{- range .Values.service.apiServices -}}
20-
{{- if or (empty $.Values.startServices) (contains .name ($.Values.startServices | default "")) }}
21-
- name: wget-{{ .name }}
22-
image: busybox
23-
command: ['wget']
24-
args: ['{{ include "localstack.fullname" $ }}:{{ .targetPort }}/health']
25-
{{- end -}}
26-
{{- end }}
2719
restartPolicy: Never

charts/localstack/values.yaml

+41-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ serviceAccount:
3535
# If not set and create is true, a name is generated using the fullname template
3636
name: ""
3737

38+
role:
39+
# Specifies whether a role & rolebinding with pods / * permissions should be created for the service account
40+
# Necessary for kubernetes lambda executor
41+
create: true
42+
# Annotations to add to the role and rolebinding
43+
annotations: {}
44+
# The name of the role and rolebinding to use.
45+
# If not set and create is true, a name is generated using the fullname template
46+
name: ""
47+
3848
podAnnotations: {}
3949

4050
podSecurityContext: {}
@@ -86,14 +96,17 @@ readinessProbe:
8696

8797
service:
8898
type: NodePort
99+
annotations: {}
100+
ipFamilies: []
101+
ipFamilyPolicy: ""
102+
externalTrafficPolicy: ""
89103
edgeService:
90104
name: edge
91105
targetPort: 4566
92106
nodePort: 31566
93-
apiServices:
94-
- name: es
95-
targetPort: 4571
96-
nodePort: 31571
107+
externalServicePorts:
108+
start: 4510
109+
end: 4560
97110

98111
ingress:
99112
enabled: false
@@ -147,6 +160,30 @@ resources: {}
147160
# cpu: 100m
148161
# memory: 128Mi
149162

163+
# All settings inside the lambda values section are only applicable to the new ASF lambda provider
164+
lambda:
165+
# The lambda runtime executor.
166+
# Depending on the value, LocalStack will execute lambdas either in docker containers or in kubernetes pods
167+
# The value "kubernetes" depends on the service account and pod role being activated
168+
executor: "kubernetes"
169+
# Image prefix for the kubernetes lambda images. The images will have to be pushed to that repository.
170+
# Only applicable when executor is set to "kubernetes"
171+
# Example: python3.9 runtime -> localstack/lambda-python:3.9
172+
image_prefix: "localstack/lambda-"
173+
# Timeout for spawning new lambda execution environments.
174+
# After that timeout, the environment (in essence pod/docker container) will be killed and restarted
175+
# Increase if spawning pods / docker containers takes longer in your environment
176+
environment_timeout: 60
177+
# Labels which will be assigned to the kubernetes pods spawned by the kubernetes executor.
178+
# They will be set on all spawned pods.
179+
# Only applicable when executor is set to "kubernetes"
180+
labels: {}
181+
# labels:
182+
# label1: value1
183+
# label2: value2
184+
# label3: value3
185+
186+
150187
nodeSelector: {}
151188

152189
tolerations: []

0 commit comments

Comments
 (0)