Skip to content

Commit

Permalink
feat: add helm charts for provisioner (#3133)
Browse files Browse the repository at this point in the history
Co-authored-by: Juho Makinen <[email protected]>
  • Loading branch information
stuartwdouglas and jvmakine authored Oct 16, 2024
1 parent dae4903 commit 1cff731
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 11 deletions.
15 changes: 8 additions & 7 deletions backend/provisioner/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func RegistryFromConfigFile(ctx context.Context, file *os.File, controller ftlv1
config := provisionerPluginConfig{}
bytes, err := io.ReadAll(bufio.NewReader(file))
if err != nil {
return nil, fmt.Errorf("error reading plugin configuration: %w", err)
return nil, fmt.Errorf("error reading plugin configuration from %s: %w", file.Name(), err)
}
if err := toml.Unmarshal(bytes, &config); err != nil {
return nil, fmt.Errorf("error parsing plugin configuration: %w", err)
Expand All @@ -180,50 +180,51 @@ func RegistryFromConfigFile(ctx context.Context, file *os.File, controller ftlv1

func (s *Service) GetArtefactDiffs(ctx context.Context, req *connect.Request[ftlv1.GetArtefactDiffsRequest]) (*connect.Response[ftlv1.GetArtefactDiffsResponse], error) {
resp, err := s.controllerClient.GetArtefactDiffs(ctx, req)

if err != nil {
return nil, fmt.Errorf("call to ftl-controller failed: %w", err)
}
return resp, nil
return connect.NewResponse(resp.Msg), nil
}

func (s *Service) ReplaceDeploy(ctx context.Context, req *connect.Request[ftlv1.ReplaceDeployRequest]) (*connect.Response[ftlv1.ReplaceDeployResponse], error) {
resp, err := s.controllerClient.ReplaceDeploy(ctx, req)
if err != nil {
return nil, fmt.Errorf("call to ftl-controller failed: %w", err)
}
return resp, nil
return connect.NewResponse(resp.Msg), nil
}

func (s *Service) Status(ctx context.Context, req *connect.Request[ftlv1.StatusRequest]) (*connect.Response[ftlv1.StatusResponse], error) {
resp, err := s.controllerClient.Status(ctx, req)
if err != nil {
return nil, fmt.Errorf("call to ftl-controller failed: %w", err)
}
return resp, nil
return connect.NewResponse(resp.Msg), nil
}

func (s *Service) UpdateDeploy(ctx context.Context, req *connect.Request[ftlv1.UpdateDeployRequest]) (*connect.Response[ftlv1.UpdateDeployResponse], error) {
resp, err := s.controllerClient.UpdateDeploy(ctx, req)
if err != nil {
return nil, fmt.Errorf("call to ftl-controller failed: %w", err)
}
return resp, nil
return connect.NewResponse(resp.Msg), nil
}

func (s *Service) UploadArtefact(ctx context.Context, req *connect.Request[ftlv1.UploadArtefactRequest]) (*connect.Response[ftlv1.UploadArtefactResponse], error) {
resp, err := s.controllerClient.UploadArtefact(ctx, req)
if err != nil {
return nil, fmt.Errorf("call to ftl-controller failed: %w", err)
}
return resp, nil
return connect.NewResponse(resp.Msg), nil
}

func (s *Service) GetSchema(ctx context.Context, req *connect.Request[ftlv1.GetSchemaRequest]) (*connect.Response[ftlv1.GetSchemaResponse], error) {
resp, err := s.controllerClient.GetSchema(ctx, req)
if err != nil {
return nil, fmt.Errorf("call to ftl-controller failed: %w", err)
}
return resp, nil
return connect.NewResponse(resp.Msg), nil
}

func (s *Service) PullSchema(ctx context.Context, req *connect.Request[ftlv1.PullSchemaRequest], to *connect.ServerStream[ftlv1.PullSchemaResponse]) error {
Expand Down
5 changes: 5 additions & 0 deletions charts/ftl/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ app.kubernetes.io/name: {{ include "ftl.fullname" . }}
app.kubernetes.io/component: runner
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
{{- define "ftl-provisioner.selectorLabels" -}}
app.kubernetes.io/name: {{ include "ftl.fullname" . }}
app.kubernetes.io/component: provisioner
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
1 change: 1 addition & 0 deletions charts/ftl/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ spec:
containers:
- name: app
image: "{{ .Values.controller.image.repository }}:{{ .Values.controller.image.tag | default $version }}"
imagePullPolicy: {{ .Values.controller.image.pullPolicy }}
{{- if .Values.controller.envFrom }}
envFrom:
{{- if .Values.controller.envFrom }}
Expand Down
9 changes: 9 additions & 0 deletions charts/ftl/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ spec:
name: ftl-controller-ingress
port:
number: 8891
{{- if .Values.provisioner.enabled }}
- path: /xyz.block.ftl.v1beta1.provisioner.ProvisionerService/
pathType: Prefix
backend:
service:
name: ftl-provisioner
port:
number: 8893
{{- end }}
{{- range $host := .Values.ingress.hosts }}
- host: "{{ $host.host }}"
http:
Expand Down
26 changes: 26 additions & 0 deletions charts/ftl/templates/provisioner-services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- if .Values.provisioner.enabled }}
apiVersion: v1
kind: Service
metadata:
labels:
{{- include "ftl.labels" . | nindent 4 }}
name: {{ include "ftl.fullname" . }}-provisioner
{{- if .Values.provisioner.service.annotations }}
annotations:
{{- toYaml .Values.provisioner.service.annotations | nindent 4 }}
{{- end }}
spec:
ports:
{{- range .Values.provisioner.service.ports }}
- name: {{ .name }}
port: {{ .port }}
protocol: {{ .protocol | default "TCP" }}
{{- if .appProtocol }}
appProtocol: {{ .appProtocol }}
{{- end }}
targetPort: {{ .targetPort }}
{{- end }}
selector:
{{- include "ftl-provisioner.selectorLabels" . | nindent 4 }}
type: {{ .Values.provisioner.service.type | default "ClusterIP" }}
{{- end }}
78 changes: 78 additions & 0 deletions charts/ftl/templates/provisioner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{{- if .Values.provisioner.enabled }}
{{ $version := printf "v%s" .Chart.Version -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "ftl.fullname" . }}-provisioner
labels:
{{- include "ftl.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.provisioner.replicas }}
revisionHistoryLimit: {{ .Values.provisioner.revisionHistoryLimit }}
selector:
matchLabels:
{{- include "ftl-provisioner.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "ftl-provisioner.selectorLabels" . | nindent 8 }}
{{- if .Values.provisioner.podAnnotations }}
annotations:
{{- toYaml .Values.provisioner.podAnnotations | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ .Values.provisioner.serviceAccountName }}
containers:
- name: app
image: "{{ .Values.provisioner.image.repository }}:{{ .Values.provisioner.image.tag | default $version }}"
imagePullPolicy: {{ .Values.provisioner.image.pullPolicy }}
{{- if .Values.provisioner.envFrom }}
envFrom:
{{- if .Values.provisioner.envFrom }}
{{- toYaml .Values.provisioner.envFrom | nindent 12 }}
{{- end }}
{{- else if or .Values.secrets.logEncryptionKey .Values.secrets.asyncEncryptionKey }}
envFrom:
- secretRef:
name: {{ include "ftl.fullname" . }}-secrets
{{- end }}
env:
{{- if .Values.provisioner.env }}
{{- toYaml .Values.provisioner.env | nindent 12 }}
{{- end }}
ports:
{{- range .Values.provisioner.ports }}
- name: {{ .name }}
containerPort: {{ .containerPort }}
protocol: {{ .protocol | default "TCP" }}
{{- end }}
readinessProbe:
{{- if .Values.provisioner.readinessProbe }}
{{- toYaml .Values.provisioner.readinessProbe | nindent 12 }}
{{- else }}
httpGet:
path: /healthz
port: 8893
initialDelaySeconds: 1
periodSeconds: 2
timeoutSeconds: 2
successThreshold: 1
failureThreshold: 15
{{- end }}
{{- if .Values.provisioner.nodeSelector }}
nodeSelector:
{{- toYaml .Values.provisioner.nodeSelector | nindent 8 }}
{{- end }}
{{- if .Values.provisioner.affinity }}
affinity:
{{- toYaml .Values.provisioner.affinity | nindent 8 }}
{{- end }}
{{- if .Values.provisioner.topologySpreadConstraints }}
topologySpreadConstraints:
{{- toYaml .Values.provisioner.topologySpreadConstraints | nindent 8 }}
{{- end }}
{{- if .Values.provisioner.tolerations }}
tolerations:
{{- toYaml .Values.provisioner.tolerations | nindent 8 }}
{{- end }}
{{- end }}
53 changes: 53 additions & 0 deletions charts/ftl/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ controller:

image:
repository: "ftl0/ftl-controller"
pullPolicy: IfNotPresent

envFrom: null
dbConnectionString: "postgres://$(endpoint):$(port)/tbd?sslmode=disable&user=$(username)&password=$(password)"
Expand Down Expand Up @@ -86,6 +87,58 @@ controller:
topologySpreadConstraints: null
tolerations: null

provisioner:
enabled: false
replicas: 1
revisionHistoryLimit: 0

image:
repository: "ftl0/ftl-provisioner"
pullPolicy: IfNotPresent

envFrom: null
serviceAccountName: ftl

env:
- name: MY_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: FTL_PROVISIONER_BIND
value: "http://$(MY_POD_IP):8893"
- name: FTL_ENDPOINT
value: "http://ftl-controller:8892"
- name: LOG_LEVEL
value: "debug"
- name: LOG_JSON
value: "true"
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP

ports:
- name: http
containerPort: 8893
protocol: TCP

readinessProbe: null

service:
type: ClusterIP
annotations: null
ports:
- name: "http-8893"
port: 80
protocol: TCP
targetPort: 8893

podAnnotations: null
nodeSelector: null
affinity: null
topologySpreadConstraints: null
tolerations: null

runner:
revisionHistoryLimit: 0

Expand Down
14 changes: 14 additions & 0 deletions deployment/Dockerfile.provisioner.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ubuntu:24.04

WORKDIR /root/

COPY docker-build/ftl-provisioner .
COPY docker-build/ftl-provisioner-cloudformation /plugins/
COPY docker-build/ftl .
EXPOSE 8893
# Temp hack, this should be a configmap
COPY ftl-provisioner-config.toml /plugins/config.toml
ENV FTL_PROVISIONER_PLUGIN_CONFIG_FILE="/plugins/config.toml"
ENV PATH="$PATH:/plugins/"

CMD ["/root/ftl-provisioner"]
13 changes: 9 additions & 4 deletions deployment/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ start: setup full-deploy

rm: teardown

full-deploy: build-controller build-runner setup-cluster
full-deploy: build-controller build-runner build-provisioner setup-cluster
#!/bin/bash
kubectl rollout restart deployment ftl-controller || true # if this exists already restart it to get the latest image
just apply || sleep 5 # wait for CRDs to be created, the initial apply will usually fail
Expand All @@ -41,7 +41,7 @@ setup-registry:
setup-cluster: setup-registry
#!/bin/bash
if [ -z "$(k3d cluster list | grep ftl)" ]; then
k3d cluster create ftl --api-port 6550 -p "8892:80@loadbalancer" -p "8891:80@loadbalancer" --agents 2 \
k3d cluster create ftl --api-port 6550 -p "8892:80@loadbalancer" -p "8891:80@loadbalancer" -p "8893:80@loadbalancer" --agents 2 \
--registry-use {{registry_full}} \
--registry-config '{{mirrors}}'
fi
Expand Down Expand Up @@ -108,7 +108,7 @@ build-executables:
# it is way faster than building in the docker files
java -version #make sure hermit has downloaded Java
mkdir -p "docker-build"
cd ../ && GOARCH=amd64 GOOS=linux CGO_ENABLED=0 just build ftl-controller ftl-runner ftl-initdb ftl
cd ../ && GOARCH=amd64 GOOS=linux CGO_ENABLED=0 just build ftl-controller ftl-runner ftl-initdb ftl ftl-provisioner ftl-provisioner-cloudformation
cp ../build/release/* ./docker-build/

build-controller: build-executables setup-registry setup-cluster
Expand All @@ -121,7 +121,12 @@ build-runner: build-executables setup-registry setup-cluster
docker tag ftl-runner:latest {{registry_local}}/ftl-runner:latest
docker push {{registry_local}}/ftl-runner:latest

build: build-controller build-runner
build-provisioner: build-executables setup-registry setup-cluster
docker build --platform linux/amd64 -t ftl-provisioner:latest -f Dockerfile.provisioner.test .
docker tag ftl-provisioner:latest {{registry_local}}/ftl-provisioner:latest
docker push {{registry_local}}/ftl-provisioner:latest

build: build-controller build-runner build-provisioner

deploy path:
#!/usr/bin/env bash
Expand Down
5 changes: 5 additions & 0 deletions deployment/ftl-provisioner-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
default = "controller"
plugins = [
{ id = "cloudformation", resources = ["postgres"] },
{ id = "controller", resources = ["module"] },
]
9 changes: 9 additions & 0 deletions deployment/values-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,14 @@ controller:
ports:
- name: "http-8891"
port: 8891
provisioner:
enabled: true
image:
repository: "ftl:5000/ftl-provisioner"
tag: "latest"
service:
ports:
- name: "http-8893"
port: 8893
istio:
enabled: true
13 changes: 13 additions & 0 deletions deployment/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ controller:
image:
repository: "ftl:5000/ftl-controller"
tag: "latest"
pullPolicy: Always
service:
ports:
- name: "http-8892"
Expand All @@ -16,6 +17,18 @@ controller:
ports:
- name: "http-8891"
port: 8891


provisioner:
enabled: true
image:
repository: "ftl:5000/ftl-provisioner"
tag: "latest"
pullPolicy: Always
service:
ports:
- name: "http-8893"
port: 8893
istio:
enabled: true

1 change: 1 addition & 0 deletions ftl-provisioner-config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
default = "controller"
plugins = [
{ id = "cloudformation", resources = ["postgres"] },
{ id = "controller", resources = ["module"] },
Expand Down

0 comments on commit 1cff731

Please sign in to comment.