From a65def00a4c9a94c8b759d5147b1d566ddd5136c Mon Sep 17 00:00:00 2001 From: outofplace <69466055+outof-place@users.noreply.github.com> Date: Mon, 9 Nov 2026 14:06:23 +0100 Subject: [PATCH] feat(helm): add a Helm chart for running Floci in Kubernetes (#7749) --- .github/ct.yaml | 14 + .github/workflows/helm-chart.yml | 190 +++++++++ README.md | 12 + charts/floci/.helmignore | 14 + charts/floci/Chart.yaml | 26 ++ charts/floci/README.md | 45 ++ charts/floci/ci/default-values.yaml | 5 + charts/floci/ci/persistence-hooks-values.yaml | 16 + charts/floci/ci/tls-values.yaml | 8 + charts/floci/templates/NOTES.txt | 66 +++ charts/floci/templates/_helpers.tpl | 263 ++++++++++++ charts/floci/templates/cleanup-hook.yaml | 84 ++++ charts/floci/templates/deployment.yaml | 143 +++++++ charts/floci/templates/ingress.yaml | 40 ++ .../floci/templates/init-hooks-configmap.yaml | 15 + charts/floci/templates/pvc.yaml | 22 + charts/floci/templates/rbac.yaml | 61 +++ charts/floci/templates/service.yaml | 51 +++ charts/floci/templates/serviceaccount.yaml | 15 + charts/floci/templates/tests/_pod.tpl | 75 ++++ charts/floci/templates/tests/test-api.yaml | 24 ++ charts/floci/templates/tests/test-lambda.yaml | 42 ++ .../__snapshot__/snapshot_test.yaml.snap | 199 +++++++++ charts/floci/tests/deployment_test.yaml | 401 ++++++++++++++++++ charts/floci/tests/hooks_test.yaml | 188 ++++++++ charts/floci/tests/rbac_test.yaml | 165 +++++++ charts/floci/tests/service_ingress_test.yaml | 171 ++++++++ charts/floci/tests/snapshot_test.yaml | 19 + charts/floci/values.schema.json | 236 +++++++++++ charts/floci/values.yaml | 302 +++++++++++++ docs/getting-started/installation.md | 1 + docs/getting-started/kubernetes.md | 277 ++++++++++++ docs/services/lambda.md | 4 +- mkdocs.yml | 1 + 34 files changed, 3194 insertions(+), 1 deletion(-) create mode 100644 .github/ct.yaml create mode 100644 .github/workflows/helm-chart.yml create mode 100644 charts/floci/.helmignore create mode 100644 charts/floci/Chart.yaml create mode 100644 charts/floci/README.md create mode 100644 charts/floci/ci/default-values.yaml create mode 100644 charts/floci/ci/persistence-hooks-values.yaml create mode 100644 charts/floci/ci/tls-values.yaml create mode 100644 charts/floci/templates/NOTES.txt create mode 100644 charts/floci/templates/_helpers.tpl create mode 100644 charts/floci/templates/cleanup-hook.yaml create mode 100644 charts/floci/templates/deployment.yaml create mode 100644 charts/floci/templates/ingress.yaml create mode 100644 charts/floci/templates/init-hooks-configmap.yaml create mode 100644 charts/floci/templates/pvc.yaml create mode 100644 charts/floci/templates/rbac.yaml create mode 100644 charts/floci/templates/service.yaml create mode 100644 charts/floci/templates/serviceaccount.yaml create mode 100644 charts/floci/templates/tests/_pod.tpl create mode 100644 charts/floci/templates/tests/test-api.yaml create mode 100644 charts/floci/templates/tests/test-lambda.yaml create mode 100644 charts/floci/tests/__snapshot__/snapshot_test.yaml.snap create mode 100644 charts/floci/tests/deployment_test.yaml create mode 100644 charts/floci/tests/hooks_test.yaml create mode 100644 charts/floci/tests/rbac_test.yaml create mode 100644 charts/floci/tests/service_ingress_test.yaml create mode 100644 charts/floci/tests/snapshot_test.yaml create mode 100644 charts/floci/values.schema.json create mode 100644 charts/floci/values.yaml create mode 100644 docs/getting-started/kubernetes.md diff --git a/.github/ct.yaml b/.github/ct.yaml new file mode 100644 index 0000000000..70c50db934 --- /dev/null +++ b/.github/ct.yaml @@ -0,0 +1,14 @@ +# chart-testing (ct) configuration for .github/workflows/helm-chart.yml. +# `ct lint` checks every chart under charts/ with helm lint, yamllint and the Chart.yaml +# schema, and fails a change that does not bump the chart version. `ct install` installs +# the chart once per ci/*-values.yaml file in a fresh namespace and runs `helm test`. +remote: origin +target-branch: main +chart-dirs: + - charts +# Chart.yaml lists the project, not individual GitHub accounts. +validate-maintainers: false +check-version-increment: true +# The Lambda test pulls public.ecr.aws/lambda/python:3.12 (about 770 MB unpacked) on its +# first run, so allow more than Helm's default five minutes. +helm-extra-args: --timeout 600s diff --git a/.github/workflows/helm-chart.yml b/.github/workflows/helm-chart.yml new file mode 100644 index 0000000000..5d57dbdce2 --- /dev/null +++ b/.github/workflows/helm-chart.yml @@ -0,0 +1,190 @@ +name: Helm Chart + +# Lints, unit-tests and installs charts/floci, and inventories the image it deploys. +# +# lint helm lint (strict) per CI values file, helm-unittest (its signed release), and +# ct lint, which also fails a pull request that changes the chart without bumping +# its version. +# install ct install on kind, once per supported Kubernetes version: every +# charts/floci/ci/*-values.yaml file is installed into a fresh namespace and +# `helm test` runs the AWS CLI against the Service. Two of those files also +# invoke a Lambda function, which Floci runs as a pod through the chart's RBAC. +# sbom an SPDX SBOM of the Floci image the chart deploys (syft) and a vulnerability +# report from it (grype), both uploaded as artifacts. +# +# The scan reports and never fails the build. The image is a published Floci release: +# its packages are fixed where the image is built (release.yml), not in the chart, so a +# finding in a base image layer would only block unrelated chart changes. Its severity +# counts go to the job summary, where a regression is visible on every chart change. + +on: + pull_request: + paths: + - 'charts/**' + - '.github/ct.yaml' + - '.github/workflows/helm-chart.yml' + push: + branches: + - main + paths: + - 'charts/**' + - '.github/ct.yaml' + - '.github/workflows/helm-chart.yml' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + # Cancel a superseded run only on pull requests; a run on main is left to finish (see ci.yml). + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +env: + # The versions the chart was verified with locally; bump them together. + HELM_VERSION: v4.3.1 + HELM_UNITTEST_VERSION: v1.2.1 + # The key helm-unittest signs its plugin releases with (public-key.asc in its repository). + HELM_UNITTEST_KEY_FINGERPRINT: 853008CD0B0A5A2DA04FF8A5616AD47F65B54AC7 + +jobs: + lint: + name: Lint and unit tests + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + # ct lint diffs against the target branch to find changed charts and check + # that their version was bumped. + fetch-depth: 0 + + - uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 + with: + version: ${{ env.HELM_VERSION }} + + - name: helm lint + run: | + helm lint charts/floci --strict + for values in charts/floci/ci/*-values.yaml; do + helm lint charts/floci --strict --values "$values" + done + + - name: helm-unittest + run: | + # The signed release tarball: Helm 4 checks its .prov signature against + # helm-unittest's public key, and that key must carry the pinned fingerprint, so a + # replaced tarball, signature or key fails here instead of running. + key="$RUNNER_TEMP/helm-unittest.asc" + keyring="$RUNNER_TEMP/helm-unittest.gpg" + curl -fsSL -o "$key" \ + "https://raw.githubusercontent.com/helm-unittest/helm-unittest/$HELM_UNITTEST_VERSION/public-key.asc" + fingerprints="$(gpg --show-keys --with-colons "$key" | awk -F: '$1 == "fpr" { print $10 }')" + if [ "$fingerprints" != "$HELM_UNITTEST_KEY_FINGERPRINT" ]; then + echo "::error::helm-unittest key fingerprint is '$fingerprints', expected $HELM_UNITTEST_KEY_FINGERPRINT" + exit 1 + fi + gpg --dearmor --output "$keyring" "$key" + helm plugin install --keyring "$keyring" \ + "https://github.com/helm-unittest/helm-unittest/releases/download/$HELM_UNITTEST_VERSION/unittest-${HELM_UNITTEST_VERSION#v}.tgz" + helm unittest charts/floci + + - uses: helm/chart-testing-action@720270857a28afd41e2426521a7801db09e9b510 # v2.9.0 + + - name: ct lint + run: ct lint --config .github/ct.yaml + + install: + name: Install on Kubernetes ${{ matrix.kubernetes }} + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + # The oldest and the newest node image kind v0.33.0 publishes. + include: + - kubernetes: v1.34.11 + node_image: kindest/node:v1.34.11@sha256:44e222ee2132dab25ff87301682f89eb82c7880ea3a1bf543bfe9708fd08d67d + - kubernetes: v1.37.0 + node_image: kindest/node:v1.37.0@sha256:a1ed56cfb0e7b93589bdf97c8cd566405a265939e3620fc4f5de89adff580ae5 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + + - uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 + with: + version: ${{ env.HELM_VERSION }} + + - uses: helm/chart-testing-action@720270857a28afd41e2426521a7801db09e9b510 # v2.9.0 + + - uses: helm/kind-action@ea822c7bf1874f08e5a491df991c228edffc3376 # v1.15.2 + with: + version: v0.33.0 + node_image: ${{ matrix.node_image }} + cluster_name: floci-chart + + - name: ct install + # --charts installs the chart on every run, including pushes to main, where there + # is no diff against the target branch to detect it as changed. + run: ct install --config .github/ct.yaml --charts charts/floci + + sbom: + name: SBOM and vulnerability report + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 + with: + version: ${{ env.HELM_VERSION }} + + - name: Resolve the image the chart deploys + id: image + run: | + # Read from the rendered Deployment rather than repeated here, so the report + # always covers the default values' image. + ref="$(helm template floci charts/floci --show-only templates/deployment.yaml \ + | awk '$1 == "image:" { gsub(/"/, "", $2); print $2; exit }')" + [ -n "$ref" ] || { echo "::error::no image found in the rendered Deployment"; exit 1; } + echo "ref=$ref" >> "$GITHUB_OUTPUT" + echo "name=$(echo "$ref" | tr '/:@' '___')" >> "$GITHUB_OUTPUT" + echo "Image: \`$ref\`" >> "$GITHUB_STEP_SUMMARY" + + - name: Generate SBOM (syft) + uses: anchore/sbom-action@66cbf4bc1f1c0d2edc94016e65bc221b6bb0ad6c # v0.24.3 + with: + image: ${{ steps.image.outputs.ref }} + format: spdx-json + output-file: sbom.spdx.json + upload-artifact: false + upload-release-assets: false + + - name: Scan SBOM (grype) + id: scan + uses: anchore/scan-action@27805bf3b4e84b4a5c980df22ed233c00390a439 # v7.4.2 + with: + sbom: sbom.spdx.json + fail-build: false + output-format: json + output-file: grype.json + + - name: Summarize findings + run: | + { + echo "" + echo "| Severity | Findings |" + echo "|---|---|" + jq -r '[.matches[].vulnerability.severity] | group_by(.) | map("| \(.[0]) | \(length) |") | .[]' grype.json + echo "" + echo "Total: $(jq '.matches | length' grype.json). Report only, see the workflow header." + } >> "$GITHUB_STEP_SUMMARY" + + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: sbom-${{ steps.image.outputs.name }} + path: | + sbom.spdx.json + grype.json + retention-days: 30 diff --git a/README.md b/README.md index fa412de6bf..05834a89c8 100644 --- a/README.md +++ b/README.md @@ -896,6 +896,18 @@ services: Without this, services may return URLs using `localhost`, which points to the wrong container from the application container. +### Kubernetes (Helm) + +The chart in [`charts/floci`](charts/floci) runs Floci in a cluster, with Lambda functions as pods and least-privilege RBAC: + +```bash +helm install floci ./charts/floci --namespace floci --create-namespace --wait +helm test floci --namespace floci --logs +aws --endpoint-url http://floci.floci.svc.cluster.local:4566 s3 ls # from any pod +``` + +See [Kubernetes (Helm)](https://floci.io/floci/getting-started/kubernetes/) for values, persistence, init hooks and Lambda on Kubernetes. + ## Community Join the Floci community on [Slack](https://join.slack.com/t/floci/shared_invite/zt-3tjn02s3q-A00kEjJ1cZxsg_imTfy6Cw) or [GitHub Discussions](https://github.com/orgs/floci-io/discussions). Feature ideas, compatibility questions, design tradeoffs, and rough proposals are welcome. diff --git a/charts/floci/.helmignore b/charts/floci/.helmignore new file mode 100644 index 0000000000..09fe7da365 --- /dev/null +++ b/charts/floci/.helmignore @@ -0,0 +1,14 @@ +# Patterns to ignore when building packages. +.DS_Store +.git/ +.gitignore +*.swp +*.bak +*.tmp +*.orig +*~ +.idea/ +.vscode/ +# Chart tests and CI values are not part of the packaged chart. +/tests/ +/ci/ diff --git a/charts/floci/Chart.yaml b/charts/floci/Chart.yaml new file mode 100644 index 0000000000..40be30839b --- /dev/null +++ b/charts/floci/Chart.yaml @@ -0,0 +1,26 @@ +apiVersion: v2 +name: floci +description: Floci, the local AWS emulator, as a single in-cluster endpoint for CI and development clusters +type: application +# Chart version. Bump it on every change under charts/floci: `ct lint` fails a pull +# request that changes the chart without a new version. +version: 0.1.0 +# Floci release the chart deploys by default (image.tag falls back to it). +appVersion: "2.4.0" +kubeVersion: ">=1.25.0-0" +home: https://floci.io +icon: https://raw.githubusercontent.com/floci-io/floci/main/docs/assets/floci.svg +sources: + - https://github.com/floci-io/floci +keywords: + - aws + - emulator + - localstack + - testing + - s3 + - lambda +maintainers: + - name: floci-io + url: https://github.com/floci-io/floci/blob/main/MAINTAINERS.md +annotations: + artifacthub.io/license: MIT diff --git a/charts/floci/README.md b/charts/floci/README.md new file mode 100644 index 0000000000..afabd55353 --- /dev/null +++ b/charts/floci/README.md @@ -0,0 +1,45 @@ +# Floci Helm chart + +Runs [Floci](https://github.com/floci-io/floci), the local AWS emulator, as one pod behind one +Service on port 4566, for CI pipelines and development clusters. Lambda functions run as pods through +Floci's Kubernetes executor, so the cluster needs no Docker socket and no privileged containers. + +```bash +git clone https://github.com/floci-io/floci.git +helm install floci ./floci/charts/floci --namespace floci --create-namespace --wait +helm test floci --namespace floci --logs +``` + +Pods then reach Floci at `http://floci.floci.svc.cluster.local:4566` with any credentials: + +```bash +aws --endpoint-url http://floci.floci.svc.cluster.local:4566 s3 mb s3://my-bucket +``` + +What the chart provides: + +- Deployment with the `Recreate` strategy, an optional PersistentVolumeClaim for `/app/data`, and + probes on `/_floci/health`; readiness waits for the `ready` init hooks (`/_floci/init`). +- Service on 4566, optional port ranges for the TCP proxies of container-backed services, optional + Ingress. +- ServiceAccount, Role and RoleBinding with exactly the permissions the Kubernetes Lambda executor + uses, in the release namespace or a separate Lambda namespace. +- `restricted` Pod Security Standard defaults: non-root, read-only root filesystem, no capabilities. +- `FLOCI_*` settings from values, init hook scripts from values, a JSON schema for the values. +- `helm test` pods that exercise S3, SQS and, optionally, a Lambda invocation, and a pre-delete hook + that removes the Lambda pods Floci created. + +Every value is documented in [`values.yaml`](values.yaml). The full guide, with Lambda, persistence, +TLS and init hook examples, is [Kubernetes (Helm)](https://floci.io/floci/getting-started/kubernetes/) +(`docs/getting-started/kubernetes.md`). + +## Development + +```bash +helm lint charts/floci --strict +helm unittest charts/floci +ct lint --config .github/ct.yaml +ct install --config .github/ct.yaml --charts charts/floci +``` + +Bump `version` in `Chart.yaml` with every change to the chart; `ct lint` enforces it. diff --git a/charts/floci/ci/default-values.yaml b/charts/floci/ci/default-values.yaml new file mode 100644 index 0000000000..8d64ea6d26 --- /dev/null +++ b/charts/floci/ci/default-values.yaml @@ -0,0 +1,5 @@ +# ct install: chart defaults, plus a Python Lambda invocation in `helm test`, which runs +# the function as a pod through the kubernetes executor and the chart's RBAC. +tests: + lambda: + enabled: true diff --git a/charts/floci/ci/persistence-hooks-values.yaml b/charts/floci/ci/persistence-hooks-values.yaml new file mode 100644 index 0000000000..823a842a64 --- /dev/null +++ b/charts/floci/ci/persistence-hooks-values.yaml @@ -0,0 +1,16 @@ +# ct install: state on a PersistentVolumeClaim (storage mode defaults to persistent) and a +# ready hook that seeds resources with the AWS CLI, which needs the compat image. The pod +# only turns Ready after the hook has run, and a failing hook stops Floci, so the install +# itself fails if the hook does. +image: + variant: compat +persistence: + enabled: true + size: 1Gi +initHooks: + ready: + 01-seed.sh: | + #!/bin/sh + set -eu + aws s3api head-bucket --bucket seeded-by-hook 2>/dev/null || aws s3 mb s3://seeded-by-hook + aws ssm put-parameter --name /helm/seeded --value ok --type String --overwrite diff --git a/charts/floci/ci/tls-values.yaml b/charts/floci/ci/tls-values.yaml new file mode 100644 index 0000000000..1ce1bd1857 --- /dev/null +++ b/charts/floci/ci/tls-values.yaml @@ -0,0 +1,8 @@ +# ct install: TLS on. A Lambda invocation then also makes Floci publish its CA bundle as +# the floci-lambda-ca ConfigMap, which exercises the TLS-only RBAC rules. +floci: + tls: + enabled: true +tests: + lambda: + enabled: true diff --git a/charts/floci/templates/NOTES.txt b/charts/floci/templates/NOTES.txt new file mode 100644 index 0000000000..baa1208e2a --- /dev/null +++ b/charts/floci/templates/NOTES.txt @@ -0,0 +1,66 @@ +Floci {{ include "floci.imageTag" . }} is starting in namespace {{ .Release.Namespace }}. + +In-cluster endpoint (for pods in any namespace): + + {{ include "floci.serviceUrl" . }} +{{- if .Values.floci.tls.enabled }} + +TLS is on: the same port also serves HTTPS with Floci's self-signed certificate +(CA at {{ include "floci.serviceUrl" . }}/_floci/ca.pem). +{{- end }} + +URLs in responses (SQS QueueUrl, pre-signed URLs) start with {{ include "floci.effectiveBaseUrl" . }} + +Point the AWS CLI or an SDK at it with any credentials, for example from a pod: + + export AWS_ENDPOINT_URL={{ include "floci.serviceUrl" . }} + export AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test AWS_DEFAULT_REGION={{ .Values.floci.defaultRegion | default "us-east-1" }} + aws s3 mb s3://my-bucket && aws s3 ls + +{{- if .Values.ingress.enabled }} + +Through the Ingress: +{{- range .Values.ingress.hosts }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ .host }}{{ (first .paths).path }} +{{- end }} +{{- else if eq .Values.service.type "LoadBalancer" }} + +Through the LoadBalancer (the address can take a minute to appear): + + kubectl get svc --namespace {{ .Release.Namespace }} {{ include "floci.fullname" . }} +{{- else if eq .Values.service.type "NodePort" }} + +Through the NodePort: + + kubectl get svc --namespace {{ .Release.Namespace }} {{ include "floci.fullname" . }} -o jsonpath='{.spec.ports[0].nodePort}' +{{- else }} + +From your machine: + + kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ include "floci.fullname" . }} 4566:{{ .Values.service.port }} + aws --endpoint-url http://localhost:4566 s3 ls +{{- end }} + +Check the installation with: + + helm test {{ .Release.Name }} --namespace {{ .Release.Namespace }} + +{{- if include "floci.kubernetesExecutor" . }} + +Lambda functions run as pods in namespace {{ include "floci.lambdaNamespace" . }} (label app.kubernetes.io/managed-by=floci). +Floci deletes every Floci Lambda pod there that it did not create, so keep other releases' Lambda pods out of it. +{{- if not .Values.rbac.create }} +rbac.create is false: give ServiceAccount {{ include "floci.serviceAccountName" . }} the pods and pods/log permissions +listed in templates/rbac.yaml in that namespace, or Lambda invocations will fail. +{{- end }} +{{- else }} + +floci.lambda.executor is "docker": Lambda, RDS, ElastiCache and the other container-backed +services need a Docker daemon reachable from the pod (FLOCI_DOCKER_DOCKER_HOST in floci.env). +{{- end }} + +{{- if and (ne (include "floci.storageMode" .) "memory") (not .Values.persistence.enabled) }} + +WARNING: storage mode is {{ include "floci.storageMode" . }} but persistence.enabled is false, so /app/data is an +emptyDir and the state is lost whenever the pod is replaced. +{{- end }} diff --git a/charts/floci/templates/_helpers.tpl b/charts/floci/templates/_helpers.tpl new file mode 100644 index 0000000000..9c3eb95c67 --- /dev/null +++ b/charts/floci/templates/_helpers.tpl @@ -0,0 +1,263 @@ +{{/* +Chart name, truncated to the 63 characters a DNS label allows. +*/}} +{{- define "floci.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Full resource name: "-", or the release name alone when it already +contains the chart name. +*/}} +{{- define "floci.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{- define "floci.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "floci.selectorLabels" -}} +app.kubernetes.io/name: {{ include "floci.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Common labels. app.kubernetes.io/managed-by is Helm here; Floci's own Lambda pods carry +managed-by=floci, and the orphan sweep selects on that value, so the two never overlap. +*/}} +{{- define "floci.labels" -}} +helm.sh/chart: {{ include "floci.chart" . }} +{{ include "floci.selectorLabels" . }} +app.kubernetes.io/version: {{ include "floci.imageTag" . | trunc 63 | trimSuffix "-" | quote }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{- define "floci.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "floci.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Image tag: image.tag or the appVersion, plus "-" when image.variant is set, which +follows the published scheme (2.4.0-compat, latest-compat, nightly-compat). +*/}} +{{- define "floci.imageTag" -}} +{{- $tag := default .Chart.AppVersion .Values.image.tag | toString }} +{{- with .Values.image.variant }} +{{- $tag = printf "%s-%s" $tag . }} +{{- end }} +{{- $tag }} +{{- end }} + +{{- define "floci.image" -}} +{{- if .Values.image.digest }} +{{- printf "%s@%s" .Values.image.repository .Values.image.digest }} +{{- else }} +{{- printf "%s:%s" .Values.image.repository (include "floci.imageTag" .) }} +{{- end }} +{{- end }} + +{{- define "floci.helperImage" -}} +{{- printf "%s:%s" .Values.helperImage.repository .Values.helperImage.tag }} +{{- end }} + +{{- define "floci.cleanupHook" -}} +{{- if and .Values.cleanup.enabled .Values.rbac.create (include "floci.kubernetesExecutor" .) }}true{{ end }} +{{- end }} + +{{- define "floci.lambdaExecutor" -}} +{{- $executor := .Values.floci.lambda.executor | toString }} +{{- if not (has $executor (list "docker" "kubernetes")) }} +{{- fail (printf "floci.lambda.executor must be \"docker\" or \"kubernetes\", got %q" $executor) }} +{{- end }} +{{- $executor }} +{{- end }} + +{{- define "floci.kubernetesExecutor" -}} +{{- if eq (include "floci.lambdaExecutor" .) "kubernetes" }}true{{ end }} +{{- end }} + +{{- define "floci.lambdaNamespace" -}} +{{- default .Release.Namespace .Values.floci.lambda.kubernetes.namespace }} +{{- end }} + +{{/* +The ConfigMap Floci publishes its TLS CA bundle in, in the Lambda namespace. The name is fixed +in Floci (KubernetesPodLauncher.CA_CONFIG_MAP_NAME). +*/}} +{{- define "floci.caConfigMapName" -}} +floci-lambda-ca +{{- end }} + +{{- define "floci.storageMode" -}} +{{- $mode := .Values.floci.storage.mode | toString }} +{{- if not $mode }} +{{- $mode = ternary "persistent" "memory" (.Values.persistence.enabled | default false) }} +{{- end }} +{{- if not (has $mode (list "memory" "persistent" "hybrid" "wal")) }} +{{- fail (printf "floci.storage.mode must be one of memory, persistent, hybrid, wal; got %q" $mode) }} +{{- end }} +{{- $mode }} +{{- end }} + +{{- define "floci.serviceHost" -}} +{{- printf "%s.%s.svc.%s" (include "floci.fullname" .) .Release.Namespace .Values.floci.clusterDomain }} +{{- end }} + +{{/* +Plain-HTTP URL of the Service. Floci answers HTTP on its port even with TLS enabled. +*/}} +{{- define "floci.serviceUrl" -}} +{{- printf "http://%s:%v" (include "floci.serviceHost" .) .Values.service.port }} +{{- end }} + +{{- define "floci.baseUrl" -}} +{{- default (include "floci.serviceUrl" .) .Values.floci.baseUrl }} +{{- end }} + +{{/* +The base URL Floci actually puts in responses, mirroring EmulatorConfig.effectiveBaseUrl(): +floci.hostname replaces the host, and TLS turns http:// into https://. +*/}} +{{- define "floci.effectiveBaseUrl" -}} +{{- $url := include "floci.baseUrl" . }} +{{- with .Values.floci.hostname }} +{{- $url = regexReplaceAll "://[^:/]+(:[0-9]+)?" $url (printf "://%s${1}" .) }} +{{- end }} +{{- if and .Values.floci.tls.enabled (hasPrefix "http://" $url) }} +{{- $url = printf "https://%s" (trimPrefix "http://" $url) }} +{{- end }} +{{- $url }} +{{- end }} + +{{/* +Phase name to hook directory. "stop" is Floci's stop.d (shutdown.d is an alias). +*/}} +{{- define "floci.initHookDirs" -}} +{{- dict "boot" "boot.d" "start" "start.d" "ready" "ready.d" "stop" "stop.d" | toJson }} +{{- end }} + +{{/* +ConfigMap entries for the init hooks, as a JSON list of {key, path, content}. Validates the +phase names and file extensions so a typo fails the render instead of being ignored by +Floci at runtime. +*/}} +{{- define "floci.initHookEntries" -}} +{{- $dirs := include "floci.initHookDirs" . | fromJson }} +{{- $entries := list }} +{{- range $phase, $scripts := .Values.initHooks }} +{{- if not (hasKey $dirs $phase) }} +{{- fail (printf "initHooks.%s is not a hook phase; use boot, start, ready or stop" $phase) }} +{{- end }} +{{- range $file, $content := $scripts }} +{{- if not (regexMatch "^[A-Za-z0-9][A-Za-z0-9._-]*\\.(sh|py)$" $file) }} +{{- fail (printf "initHooks.%s.%s: hook file names must end in .sh or .py and use only letters, digits, '.', '_' and '-'" $phase $file) }} +{{- end }} +{{- $entries = append $entries (dict "key" (printf "%s-%s" $phase $file) "path" (printf "%s/%s" (get $dirs $phase) $file) "content" $content) }} +{{- end }} +{{- end }} +{{- $entries | toJson }} +{{- end }} + +{{- define "floci.hasInitHooks" -}} +{{- if gt (len (include "floci.initHookEntries" . | fromJsonArray)) 0 }}true{{ end }} +{{- end }} + +{{/* +The variables the chart sets itself, each mapped to the value that controls it, as JSON. Other +manifests follow these values: the container port and the probes are fixed at 4566, the Role +and the token mount follow the executor and TLS settings, and the test pods expect the base URL +and region. A variable set behind the chart's back would leave them out of step, so floci.env +and extraEnv cannot set any of these. +*/}} +{{- define "floci.managedEnv" -}} +{{- dict + "FLOCI_PORT" "service.port (the container always listens on 4566)" + "FLOCI_BASE_URL" "floci.baseUrl" + "FLOCI_HOSTNAME" "floci.hostname" + "FLOCI_DEFAULT_REGION" "floci.defaultRegion" + "FLOCI_DEFAULT_ACCOUNT_ID" "floci.defaultAccountId" + "FLOCI_STORAGE_MODE" "floci.storage.mode" + "FLOCI_STORAGE_PERSISTENT_PATH" "persistence.enabled or persistence.existingClaim (the data volume is always mounted at /app/data)" + "FLOCI_TLS_ENABLED" "floci.tls.enabled" + "FLOCI_SERVICES_LAMBDA_EXECUTOR" "floci.lambda.executor" + "FLOCI_SERVICES_LAMBDA_KUBERNETES_NAMESPACE" "floci.lambda.kubernetes.namespace" + "FLOCI_SERVICES_LAMBDA_KUBERNETES_INIT_IMAGE" "floci.lambda.kubernetes.initImage" + "FLOCI_SERVICES_LAMBDA_KUBERNETES_LABELS" "floci.lambda.kubernetes.labels" + "FLOCI_SERVICES_LAMBDA_KUBERNETES_FLOCI_ADDRESS" "floci.lambda.kubernetes.flociAddress" + | toJson }} +{{- end }} + +{{/* +Container environment: the variables the chart derives from its values, then floci.env. +Sorted by name for a stable render. A floci.env or extraEnv entry for a variable the chart +sets fails the render and names the value to use instead. +*/}} +{{- define "floci.env" -}} +{{- $managed := include "floci.managedEnv" . | fromJson }} +{{- range $name, $value := .Values.floci.env }} +{{- if hasKey $managed $name }} +{{- fail (printf "floci.env.%s: the chart sets this variable; use %s instead" $name (get $managed $name)) }} +{{- end }} +{{- end }} +{{- range .Values.extraEnv }} +{{- if hasKey $managed .name }} +{{- fail (printf "extraEnv %s: the chart sets this variable; use %s instead" .name (get $managed .name)) }} +{{- end }} +{{- end }} +{{- $env := dict }} +{{- $_ := set $env "FLOCI_PORT" "4566" }} +{{- $_ := set $env "FLOCI_BASE_URL" (include "floci.baseUrl" .) }} +{{- with .Values.floci.hostname }} +{{- $_ := set $env "FLOCI_HOSTNAME" . }} +{{- end }} +{{- with .Values.floci.defaultRegion }} +{{- $_ := set $env "FLOCI_DEFAULT_REGION" . }} +{{- end }} +{{- with .Values.floci.defaultAccountId }} +{{- $_ := set $env "FLOCI_DEFAULT_ACCOUNT_ID" (toString .) }} +{{- end }} +{{- $_ := set $env "FLOCI_STORAGE_MODE" (include "floci.storageMode" .) }} +{{- $_ := set $env "FLOCI_STORAGE_PERSISTENT_PATH" "/app/data" }} +{{- if .Values.floci.tls.enabled }} +{{- $_ := set $env "FLOCI_TLS_ENABLED" "true" }} +{{- end }} +{{- $_ := set $env "FLOCI_SERVICES_LAMBDA_EXECUTOR" (include "floci.lambdaExecutor" .) }} +{{- if include "floci.kubernetesExecutor" . }} +{{- $k8s := .Values.floci.lambda.kubernetes }} +{{- $_ := set $env "FLOCI_SERVICES_LAMBDA_KUBERNETES_NAMESPACE" (include "floci.lambdaNamespace" .) }} +{{- with $k8s.initImage }} +{{- $_ := set $env "FLOCI_SERVICES_LAMBDA_KUBERNETES_INIT_IMAGE" . }} +{{- end }} +{{- with $k8s.labels }} +{{- $_ := set $env "FLOCI_SERVICES_LAMBDA_KUBERNETES_LABELS" (join "," .) }} +{{- end }} +{{- with $k8s.flociAddress }} +{{- $_ := set $env "FLOCI_SERVICES_LAMBDA_KUBERNETES_FLOCI_ADDRESS" . }} +{{- end }} +{{- end }} +{{- range $name, $value := .Values.floci.env }} +{{- /* YAML numbers arrive as float64, which toString prints as 1e+06; keep integers whole. */}} +{{- if and (kindIs "float64" $value) (eq $value (floor $value)) }} +{{- $value = int64 $value }} +{{- end }} +{{- $_ := set $env $name (toString $value) }} +{{- end }} +{{- range $name := keys $env | sortAlpha }} +- name: {{ $name }} + value: {{ get $env $name | quote }} +{{- end }} +{{- end }} diff --git a/charts/floci/templates/cleanup-hook.yaml b/charts/floci/templates/cleanup-hook.yaml new file mode 100644 index 0000000000..7f72cfd3d0 --- /dev/null +++ b/charts/floci/templates/cleanup-hook.yaml @@ -0,0 +1,84 @@ +{{- if include "floci.cleanupHook" . }} +{{- $script := ` +# Best effort: every failure is logged and the script still exits 0, and every API call is +# time-bounded, so a slow or unreachable API server cannot hold up the uninstall. Uses +# Floci's own ServiceAccount, so it can do nothing Floci cannot. +sa=/var/run/secrets/kubernetes.io/serviceaccount +api=https://kubernetes.default.svc +token="$(cat "$sa/token")" +k() { curl -sS --connect-timeout 5 --max-time 20 --cacert "$sa/ca.crt" -H "Authorization: Bearer $token" "$@"; } + +selector='app.kubernetes.io%2Fmanaged-by%3Dfloci%2Cfloci.io%2Fservice%3Dlambda' +pods="$(k "$api/api/v1/namespaces/$LAMBDA_NAMESPACE/pods?labelSelector=$selector" | + python3 -c 'import json, sys; print(" ".join(p["metadata"]["name"] for p in json.load(sys.stdin).get("items", [])))')" +echo "Lambda pods in $LAMBDA_NAMESPACE: ${pods:-none}" +for pod in $pods; do + code="$(k -o /dev/null -w '%{http_code}' -X DELETE "$api/api/v1/namespaces/$LAMBDA_NAMESPACE/pods/$pod?gracePeriodSeconds=0")" + echo "delete pod $pod: HTTP $code" +done + +# Also with TLS off now: a revision that ran with TLS on may have left the CA ConfigMap. +code="$(k -o /dev/null -w '%{http_code}' -X DELETE "$api/api/v1/namespaces/$LAMBDA_NAMESPACE/configmaps/$CA_CONFIG_MAP")" +echo "delete configmap $CA_CONFIG_MAP: HTTP $code (404 means Floci never ran with TLS here)" +exit 0 +` }} +apiVersion: v1 +kind: Pod +metadata: + name: {{ include "floci.fullname" . }}-cleanup + namespace: {{ .Release.Namespace }} + labels: + {{- include "floci.labels" . | nindent 4 }} + app.kubernetes.io/component: cleanup + annotations: + helm.sh/hook: pre-delete + helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded +spec: + restartPolicy: Never + serviceAccountName: {{ include "floci.serviceAccountName" . }} + automountServiceAccountToken: true + enableServiceLinks: false + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 4 }} + {{- end }} + # Floci's own pod security context, so an override for a platform that assigns its own + # UIDs (OpenShift) covers this pod as well. + {{- with .Values.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 4 }} + {{- end }} + containers: + - name: cleanup + image: {{ include "floci.helperImage" . | quote }} + imagePullPolicy: {{ .Values.helperImage.pullPolicy }} + command: ["/bin/sh", "-c"] + args: + - | + {{- $script | trim | nindent 10 }} + env: + - name: LAMBDA_NAMESPACE + value: {{ include "floci.lambdaNamespace" . | quote }} + - name: CA_CONFIG_MAP + value: {{ include "floci.caConfigMapName" . | quote }} + - name: HOME + value: /tmp + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: + - ALL + resources: + requests: + cpu: 50m + memory: 64Mi + limits: + memory: 128Mi + volumeMounts: + - name: tmp + mountPath: /tmp + volumes: + - name: tmp + emptyDir: {} +{{- end }} diff --git a/charts/floci/templates/deployment.yaml b/charts/floci/templates/deployment.yaml new file mode 100644 index 0000000000..2673062376 --- /dev/null +++ b/charts/floci/templates/deployment.yaml @@ -0,0 +1,143 @@ +{{- $hooks := include "floci.initHookEntries" . | fromJsonArray }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "floci.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "floci.labels" . | nindent 4 }} +spec: + # Floci keeps its state in the pod, so a second replica would be a second, unrelated + # emulator behind the same Service. Recreate stops the old pod before the new one starts: + # a ReadWriteOnce claim can then move between them, and the new pod's sweep of orphaned + # Lambda pods never races a still-running predecessor. + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + {{- include "floci.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- if or $hooks .Values.podAnnotations }} + annotations: + {{- if $hooks }} + checksum/init-hooks: {{ include (print $.Template.BasePath "/init-hooks-configmap.yaml") . | sha256sum }} + {{- end }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- end }} + labels: + {{- include "floci.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + serviceAccountName: {{ include "floci.serviceAccountName" . }} + # Only the kubernetes Lambda executor talks to the Kubernetes API. + automountServiceAccountToken: {{ include "floci.kubernetesExecutor" . | eq "true" }} + # Service links would inject _PORT=tcp://... variables, and for a Service + # named "floci" that is FLOCI_PORT, which Floci reads as its own configuration. + enableServiceLinks: false + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.priorityClassName }} + priorityClassName: {{ . }} + {{- end }} + {{- with .Values.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} + containers: + - name: floci + image: {{ include "floci.image" . | quote }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + ports: + - name: http + containerPort: 4566 + protocol: TCP + env: + {{- include "floci.env" . | trim | nindent 12 }} + {{- with .Values.extraEnv }} + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.extraEnvFrom }} + envFrom: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.startupProbe }} + startupProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + volumeMounts: + - name: data + mountPath: /app/data + - name: tmp + mountPath: /tmp + {{- if $hooks }} + - name: init-hooks + mountPath: /etc/floci/init + readOnly: true + {{- end }} + {{- with .Values.extraVolumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + volumes: + - name: data + {{- if .Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ .Values.persistence.existingClaim | default (printf "%s-data" (include "floci.fullname" .)) }} + {{- else if .Values.dataSizeLimit }} + emptyDir: + sizeLimit: {{ .Values.dataSizeLimit }} + {{- else }} + emptyDir: {} + {{- end }} + - name: tmp + emptyDir: {} + {{- if $hooks }} + - name: init-hooks + configMap: + name: {{ include "floci.fullname" . }}-init-hooks + defaultMode: 0555 + items: + {{- range $hooks }} + - key: {{ .key }} + path: {{ .path }} + {{- end }} + {{- end }} + {{- with .Values.extraVolumes }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/floci/templates/ingress.yaml b/charts/floci/templates/ingress.yaml new file mode 100644 index 0000000000..e7caeaa987 --- /dev/null +++ b/charts/floci/templates/ingress.yaml @@ -0,0 +1,40 @@ +{{- if .Values.ingress.enabled }} +{{- $fullname := include "floci.fullname" . }} +{{- $port := .Values.service.port }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $fullname }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "floci.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.ingress.className }} + ingressClassName: {{ . }} + {{- end }} + {{- with .Values.ingress.tls }} + tls: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - {{- with .host }} + host: {{ . | quote }} + {{- end }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType | default "Prefix" }} + backend: + service: + name: {{ $fullname }} + port: + number: {{ $port }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/floci/templates/init-hooks-configmap.yaml b/charts/floci/templates/init-hooks-configmap.yaml new file mode 100644 index 0000000000..7503665fca --- /dev/null +++ b/charts/floci/templates/init-hooks-configmap.yaml @@ -0,0 +1,15 @@ +{{- $hooks := include "floci.initHookEntries" . | fromJsonArray }} +{{- if $hooks }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "floci.fullname" . }}-init-hooks + namespace: {{ .Release.Namespace }} + labels: + {{- include "floci.labels" . | nindent 4 }} +data: + {{- range $hooks }} + {{ .key }}: |- + {{- .content | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/floci/templates/pvc.yaml b/charts/floci/templates/pvc.yaml new file mode 100644 index 0000000000..0e02908f86 --- /dev/null +++ b/charts/floci/templates/pvc.yaml @@ -0,0 +1,22 @@ +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "floci.fullname" . }}-data + namespace: {{ .Release.Namespace }} + labels: + {{- include "floci.labels" . | nindent 4 }} + {{- with .Values.persistence.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + accessModes: + {{- toYaml .Values.persistence.accessModes | nindent 4 }} + {{- with .Values.persistence.storageClass }} + storageClassName: {{ eq . "-" | ternary "" . | quote }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.size }} +{{- end }} diff --git a/charts/floci/templates/rbac.yaml b/charts/floci/templates/rbac.yaml new file mode 100644 index 0000000000..f2e6f7cc79 --- /dev/null +++ b/charts/floci/templates/rbac.yaml @@ -0,0 +1,61 @@ +{{- if and .Values.rbac.create (include "floci.kubernetesExecutor" .) }} +{{- $namespace := include "floci.lambdaNamespace" . }} +# What the kubernetes Lambda executor calls (see KubernetesApiClient), and nothing more: +# it polls pods with GET rather than watching them, and deletes them one by one. +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "floci.fullname" . }}-lambda + namespace: {{ $namespace }} + labels: + {{- include "floci.labels" . | nindent 4 }} +rules: + # Create Lambda pods, poll them until Running, delete them when idle, and list the ones + # a previous Floci left behind (label selector app.kubernetes.io/managed-by=floci). + - apiGroups: [""] + resources: ["pods"] + verbs: ["create", "get", "list", "delete"] + # Follow each Lambda pod's runtime log into CloudWatch Logs. + - apiGroups: [""] + resources: ["pods/log"] + verbs: ["get"] + {{- if .Values.floci.tls.enabled }} + # With TLS, Floci publishes its CA bundle to Lambda pods through one ConfigMap. + # Create cannot be limited by name; reading and replacing it can. + - apiGroups: [""] + resources: ["configmaps"] + verbs: ["create"] + - apiGroups: [""] + resources: ["configmaps"] + resourceNames: [{{ include "floci.caConfigMapName" . | quote }}] + {{- if include "floci.cleanupHook" . }} + # delete: only the uninstall cleanup hook removes it; Floci itself never does. + verbs: ["get", "update", "delete"] + {{- else }} + verbs: ["get", "update"] + {{- end }} + {{- else if include "floci.cleanupHook" . }} + # Without TLS only the uninstall cleanup hook's delete is left, for the CA ConfigMap an + # earlier revision with TLS on may have created. + - apiGroups: [""] + resources: ["configmaps"] + resourceNames: [{{ include "floci.caConfigMapName" . | quote }}] + verbs: ["delete"] + {{- end }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ include "floci.fullname" . }}-lambda + namespace: {{ $namespace }} + labels: + {{- include "floci.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ include "floci.fullname" . }}-lambda +subjects: + - kind: ServiceAccount + name: {{ include "floci.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} +{{- end }} diff --git a/charts/floci/templates/service.yaml b/charts/floci/templates/service.yaml new file mode 100644 index 0000000000..fca94ab4b5 --- /dev/null +++ b/charts/floci/templates/service.yaml @@ -0,0 +1,51 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "floci.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "floci.labels" . | nindent 4 }} + {{- with .Values.service.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + type: {{ .Values.service.type }} + {{- if and (has .Values.service.type (list "NodePort" "LoadBalancer")) .Values.service.externalTrafficPolicy }} + externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} + {{- end }} + {{- if and (eq .Values.service.type "LoadBalancer") .Values.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{- toYaml .Values.service.loadBalancerSourceRanges | nindent 4 }} + {{- end }} + selector: + {{- include "floci.selectorLabels" . | nindent 4 }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + {{- if and (has .Values.service.type (list "NodePort" "LoadBalancer")) .Values.service.nodePort }} + nodePort: {{ .Values.service.nodePort }} + {{- end }} + {{- range .Values.service.portRanges }} + {{- if not (and .name .start .end) }} + {{- fail "service.portRanges entries need name, start and end" }} + {{- end }} + {{- if gt (int .start) (int .end) }} + {{- fail (printf "service.portRanges %s: start %v is above end %v" .name .start .end) }} + {{- end }} + {{- $name := .name }} + {{- range $port := untilStep (int .start) (int (add1 .end)) 1 }} + - name: {{ printf "%s-%d" $name $port }} + port: {{ $port }} + targetPort: {{ $port }} + protocol: TCP + {{- end }} + {{- end }} + {{- with .Values.service.extraPorts }} + {{- toYaml . | nindent 4 }} + {{- end }} diff --git a/charts/floci/templates/serviceaccount.yaml b/charts/floci/templates/serviceaccount.yaml new file mode 100644 index 0000000000..0569993d97 --- /dev/null +++ b/charts/floci/templates/serviceaccount.yaml @@ -0,0 +1,15 @@ +{{- if .Values.serviceAccount.create }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "floci.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "floci.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +# The pod spec decides whether the token is mounted (only for the kubernetes Lambda executor). +automountServiceAccountToken: false +{{- end }} diff --git a/charts/floci/templates/tests/_pod.tpl b/charts/floci/templates/tests/_pod.tpl new file mode 100644 index 0000000000..921de761c3 --- /dev/null +++ b/charts/floci/templates/tests/_pod.tpl @@ -0,0 +1,75 @@ +{{/* +Shared spec of the `helm test` pods: AWS CLI v2 against the Service's in-cluster DNS name, +under Floci's own pod security context (podSecurityContext) and a restricted container one. Called with a dict holding the +root context ("root"), the test name ("name"), the shell script ("script") and optional +extra volumes and mounts. +*/}} +{{- define "floci.testPod" -}} +{{- $root := .root }} +apiVersion: v1 +kind: Pod +metadata: + name: {{ include "floci.fullname" $root }}-test-{{ .name }} + namespace: {{ $root.Release.Namespace }} + labels: + {{- include "floci.labels" $root | nindent 4 }} + app.kubernetes.io/component: test + annotations: + helm.sh/hook: test + helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded +spec: + restartPolicy: Never + automountServiceAccountToken: false + enableServiceLinks: false + {{- with $root.Values.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 4 }} + {{- end }} + containers: + - name: aws-cli + image: {{ include "floci.helperImage" $root | quote }} + imagePullPolicy: {{ $root.Values.helperImage.pullPolicy }} + command: ["/bin/sh", "-ec"] + args: + - | + {{- .script | trim | nindent 10 }} + env: + - name: FLOCI_ENDPOINT + value: {{ include "floci.serviceUrl" $root | quote }} + - name: FLOCI_EFFECTIVE_BASE_URL + value: {{ include "floci.effectiveBaseUrl" $root | quote }} + - name: AWS_ACCESS_KEY_ID + value: test + - name: AWS_SECRET_ACCESS_KEY + value: test + - name: AWS_DEFAULT_REGION + value: {{ $root.Values.floci.defaultRegion | default "us-east-1" | quote }} + - name: AWS_PAGER + value: "" + - name: HOME + value: /tmp + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: + - ALL + resources: + requests: + cpu: 50m + memory: 128Mi + limits: + memory: 256Mi + volumeMounts: + - name: tmp + mountPath: /tmp + {{- with .volumeMounts }} + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: tmp + emptyDir: {} + {{- with .volumes }} + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/floci/templates/tests/test-api.yaml b/charts/floci/templates/tests/test-api.yaml new file mode 100644 index 0000000000..bb2cfbe547 --- /dev/null +++ b/charts/floci/templates/tests/test-api.yaml @@ -0,0 +1,24 @@ +{{- $script := ` +endpoint="$FLOCI_ENDPOINT" +aws --endpoint-url "$endpoint" sts get-caller-identity + +bucket="helm-test-$(date +%s)" +aws --endpoint-url "$endpoint" s3 mb "s3://$bucket" +echo "hello from helm test" > /tmp/hello.txt +aws --endpoint-url "$endpoint" s3 cp /tmp/hello.txt "s3://$bucket/hello.txt" +aws --endpoint-url "$endpoint" s3 ls "s3://$bucket" +body="$(aws --endpoint-url "$endpoint" s3 cp "s3://$bucket/hello.txt" -)" +[ "$body" = "hello from helm test" ] || { echo "unexpected object body: $body"; exit 1; } +aws --endpoint-url "$endpoint" s3 rb --force "s3://$bucket" + +# QueueUrl is built from the base URL the chart sets, so it must not name localhost. +queue_url="$(aws --endpoint-url "$endpoint" sqs create-queue --queue-name "$bucket" --query QueueUrl --output text)" +echo "QueueUrl: $queue_url" +case "$queue_url" in + "$FLOCI_EFFECTIVE_BASE_URL"/*) ;; + *) echo "QueueUrl does not start with $FLOCI_EFFECTIVE_BASE_URL"; exit 1 ;; +esac +aws --endpoint-url "$endpoint" sqs delete-queue --queue-url "$queue_url" +echo "API smoke test passed" +` }} +{{- include "floci.testPod" (dict "root" . "name" "api" "script" $script) }} diff --git a/charts/floci/templates/tests/test-lambda.yaml b/charts/floci/templates/tests/test-lambda.yaml new file mode 100644 index 0000000000..b8e85b3608 --- /dev/null +++ b/charts/floci/templates/tests/test-lambda.yaml @@ -0,0 +1,42 @@ +{{- if .Values.tests.lambda.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "floci.fullname" . }}-test-lambda + namespace: {{ .Release.Namespace }} + labels: + {{- include "floci.labels" . | nindent 4 }} + app.kubernetes.io/component: test + annotations: + helm.sh/hook: test + helm.sh/hook-weight: "-1" + helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded +data: + index.py: | + def handler(event, context): + return {"message": "hello " + event.get("name", "world")} +--- +{{- $script := ` +endpoint="$FLOCI_ENDPOINT" +fn="helm-test-$(date +%s)" +account="$(aws --endpoint-url "$endpoint" sts get-caller-identity --query Account --output text)" +python3 -c 'import zipfile; z = zipfile.ZipFile("/tmp/function.zip", "w"); z.write("/fixtures/index.py", "index.py"); z.close()' + +aws --endpoint-url "$endpoint" lambda create-function --function-name "$fn" \ + --runtime python3.12 --handler index.handler --timeout 30 \ + --role "arn:aws:iam::$account:role/helm-test" \ + --zip-file fileb:///tmp/function.zip --query State --output text +aws --endpoint-url "$endpoint" lambda wait function-active-v2 --function-name "$fn" + +# The first invocation waits for the node to pull the runtime image and start the pod. +aws --endpoint-url "$endpoint" --cli-read-timeout 600 lambda invoke --function-name "$fn" \ + --cli-binary-format raw-in-base64-out --payload '{"name": "helm"}' /tmp/out.json +cat /tmp/out.json; echo +python3 -c 'import json, sys; body = json.load(open("/tmp/out.json")); sys.exit(0 if body == {"message": "hello helm"} else "unexpected payload: %r" % body)' +aws --endpoint-url "$endpoint" lambda delete-function --function-name "$fn" +echo "Lambda smoke test passed" +` }} +{{- $volumes := list (dict "name" "fixtures" "configMap" (dict "name" (printf "%s-test-lambda" (include "floci.fullname" .)))) }} +{{- $mounts := list (dict "name" "fixtures" "mountPath" "/fixtures" "readOnly" true) }} +{{- include "floci.testPod" (dict "root" . "name" "lambda" "script" $script "volumes" $volumes "volumeMounts" $mounts) }} +{{- end }} diff --git a/charts/floci/tests/__snapshot__/snapshot_test.yaml.snap b/charts/floci/tests/__snapshot__/snapshot_test.yaml.snap new file mode 100644 index 0000000000..0053b04ca4 --- /dev/null +++ b/charts/floci/tests/__snapshot__/snapshot_test.yaml.snap @@ -0,0 +1,199 @@ +matches the default manifests: + 1: | + apiVersion: apps/v1 + kind: Deployment + metadata: + labels: + app.kubernetes.io/instance: floci + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: floci + app.kubernetes.io/version: 0.0.0 + helm.sh/chart: floci-0.0.0 + name: floci + namespace: aws + spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: floci + app.kubernetes.io/name: floci + strategy: + type: Recreate + template: + metadata: + labels: + app.kubernetes.io/instance: floci + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: floci + app.kubernetes.io/version: 0.0.0 + helm.sh/chart: floci-0.0.0 + spec: + automountServiceAccountToken: true + containers: + - env: + - name: FLOCI_BASE_URL + value: http://floci.aws.svc.cluster.local:4566 + - name: FLOCI_PORT + value: "4566" + - name: FLOCI_SERVICES_LAMBDA_EXECUTOR + value: kubernetes + - name: FLOCI_SERVICES_LAMBDA_KUBERNETES_NAMESPACE + value: aws + - name: FLOCI_STORAGE_MODE + value: memory + - name: FLOCI_STORAGE_PERSISTENT_PATH + value: /app/data + image: floci/floci:0.0.0 + imagePullPolicy: IfNotPresent + livenessProbe: + failureThreshold: 3 + httpGet: + path: /_floci/health + port: http + periodSeconds: 10 + timeoutSeconds: 3 + name: floci + ports: + - containerPort: 4566 + name: http + protocol: TCP + readinessProbe: + exec: + command: + - /bin/bash + - -c + - 'exec 3<>/dev/tcp/127.0.0.1/4566 && printf ''GET /_floci/init HTTP/1.0\r\nHost: localhost\r\n\r\n'' >&3 && { IFS= read -r -d '''' response <&3; [[ $response == "HTTP/1."?" 200"*''"ready":true''* ]]; }' + failureThreshold: 3 + periodSeconds: 5 + timeoutSeconds: 3 + resources: + limits: + memory: 1Gi + requests: + cpu: 100m + memory: 128Mi + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + readOnlyRootFilesystem: true + startupProbe: + failureThreshold: 60 + httpGet: + path: /_floci/health + port: http + periodSeconds: 2 + timeoutSeconds: 3 + volumeMounts: + - mountPath: /app/data + name: data + - mountPath: /tmp + name: tmp + enableServiceLinks: false + securityContext: + fsGroup: 1001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 1001 + runAsNonRoot: true + runAsUser: 1001 + seccompProfile: + type: RuntimeDefault + serviceAccountName: floci + terminationGracePeriodSeconds: 30 + volumes: + - emptyDir: {} + name: data + - emptyDir: {} + name: tmp + 2: | + apiVersion: rbac.authorization.k8s.io/v1 + kind: Role + metadata: + labels: + app.kubernetes.io/instance: floci + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: floci + app.kubernetes.io/version: 0.0.0 + helm.sh/chart: floci-0.0.0 + name: floci-lambda + namespace: aws + rules: + - apiGroups: + - "" + resources: + - pods + verbs: + - create + - get + - list + - delete + - apiGroups: + - "" + resources: + - pods/log + verbs: + - get + - apiGroups: + - "" + resourceNames: + - floci-lambda-ca + resources: + - configmaps + verbs: + - delete + 3: | + apiVersion: rbac.authorization.k8s.io/v1 + kind: RoleBinding + metadata: + labels: + app.kubernetes.io/instance: floci + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: floci + app.kubernetes.io/version: 0.0.0 + helm.sh/chart: floci-0.0.0 + name: floci-lambda + namespace: aws + roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: floci-lambda + subjects: + - kind: ServiceAccount + name: floci + namespace: aws + 4: | + apiVersion: v1 + kind: Service + metadata: + labels: + app.kubernetes.io/instance: floci + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: floci + app.kubernetes.io/version: 0.0.0 + helm.sh/chart: floci-0.0.0 + name: floci + namespace: aws + spec: + ports: + - name: http + port: 4566 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/instance: floci + app.kubernetes.io/name: floci + type: ClusterIP + 5: | + apiVersion: v1 + automountServiceAccountToken: false + kind: ServiceAccount + metadata: + labels: + app.kubernetes.io/instance: floci + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: floci + app.kubernetes.io/version: 0.0.0 + helm.sh/chart: floci-0.0.0 + name: floci + namespace: aws diff --git a/charts/floci/tests/deployment_test.yaml b/charts/floci/tests/deployment_test.yaml new file mode 100644 index 0000000000..f8777a7797 --- /dev/null +++ b/charts/floci/tests/deployment_test.yaml @@ -0,0 +1,401 @@ +suite: deployment +templates: + - templates/deployment.yaml + - templates/init-hooks-configmap.yaml +release: + name: floci + namespace: aws +chart: + appVersion: 9.9.9 +tests: + - it: runs one replica of the pinned image with the Recreate strategy + template: templates/deployment.yaml + asserts: + - isKind: + of: Deployment + - equal: + path: spec.replicas + value: 1 + - equal: + path: spec.strategy.type + value: Recreate + - equal: + path: spec.template.spec.containers[0].image + value: floci/floci:9.9.9 + - equal: + path: spec.template.spec.containers[0].ports + value: + - name: http + containerPort: 4566 + protocol: TCP + + - it: disables service links, which would inject FLOCI_PORT for a Service named floci + template: templates/deployment.yaml + asserts: + - equal: + path: spec.template.spec.enableServiceLinks + value: false + + - it: satisfies the restricted Pod Security Standard by default + template: templates/deployment.yaml + asserts: + - equal: + path: spec.template.spec.securityContext.runAsNonRoot + value: true + - equal: + path: spec.template.spec.securityContext.seccompProfile.type + value: RuntimeDefault + - equal: + path: spec.template.spec.containers[0].securityContext + value: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: + - ALL + + - it: mounts writable emptyDirs for /app/data and /tmp under the read-only root filesystem + template: templates/deployment.yaml + asserts: + - contains: + path: spec.template.spec.containers[0].volumeMounts + content: + name: data + mountPath: /app/data + - contains: + path: spec.template.spec.containers[0].volumeMounts + content: + name: tmp + mountPath: /tmp + - contains: + path: spec.template.spec.volumes + content: + name: data + emptyDir: {} + + - it: derives the Floci environment from the values, sorted by name + template: templates/deployment.yaml + asserts: + - equal: + path: spec.template.spec.containers[0].env + value: + - name: FLOCI_BASE_URL + value: http://floci.aws.svc.cluster.local:4566 + - name: FLOCI_PORT + value: "4566" + - name: FLOCI_SERVICES_LAMBDA_EXECUTOR + value: kubernetes + - name: FLOCI_SERVICES_LAMBDA_KUBERNETES_NAMESPACE + value: aws + - name: FLOCI_STORAGE_MODE + value: memory + - name: FLOCI_STORAGE_PERSISTENT_PATH + value: /app/data + + - it: passes other floci.env settings through as strings, integers kept whole + template: templates/deployment.yaml + set: + floci.env: + FLOCI_SERVICES_LAMBDA_CONTAINER_IDLE_TIMEOUT_SECONDS: 300 + FLOCI_SERVICES_S3_MAX_OBJECT_BYTES: 1000000 + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: FLOCI_SERVICES_LAMBDA_CONTAINER_IDLE_TIMEOUT_SECONDS + value: "300" + - contains: + path: spec.template.spec.containers[0].env + content: + name: FLOCI_SERVICES_S3_MAX_OBJECT_BYTES + value: "1000000" + + - it: maps the Lambda, TLS and identity settings to their FLOCI_* variables + template: templates/deployment.yaml + set: + floci.baseUrl: https://floci.example.test + floci.hostname: floci.example.test + floci.defaultRegion: eu-central-1 + floci.defaultAccountId: "123456789012" + floci.tls.enabled: true + floci.lambda.kubernetes.namespace: lambdas + floci.lambda.kubernetes.initImage: busybox:1.37 + floci.lambda.kubernetes.labels: [team=platform, env=ci] + floci.lambda.kubernetes.flociAddress: 10.0.0.7 + asserts: + - equal: + path: spec.template.spec.containers[0].env + value: + - name: FLOCI_BASE_URL + value: https://floci.example.test + - name: FLOCI_DEFAULT_ACCOUNT_ID + value: "123456789012" + - name: FLOCI_DEFAULT_REGION + value: eu-central-1 + - name: FLOCI_HOSTNAME + value: floci.example.test + - name: FLOCI_PORT + value: "4566" + - name: FLOCI_SERVICES_LAMBDA_EXECUTOR + value: kubernetes + - name: FLOCI_SERVICES_LAMBDA_KUBERNETES_FLOCI_ADDRESS + value: 10.0.0.7 + - name: FLOCI_SERVICES_LAMBDA_KUBERNETES_INIT_IMAGE + value: busybox:1.37 + - name: FLOCI_SERVICES_LAMBDA_KUBERNETES_LABELS + value: team=platform,env=ci + - name: FLOCI_SERVICES_LAMBDA_KUBERNETES_NAMESPACE + value: lambdas + - name: FLOCI_STORAGE_MODE + value: memory + - name: FLOCI_STORAGE_PERSISTENT_PATH + value: /app/data + - name: FLOCI_TLS_ENABLED + value: "true" + + - it: rejects a floci.env entry for a variable the chart sets, naming the value to use + template: templates/deployment.yaml + set: + floci.env: + FLOCI_TLS_ENABLED: true + asserts: + - failedTemplate: + errorMessage: "floci.env.FLOCI_TLS_ENABLED: the chart sets this variable; use floci.tls.enabled instead" + + - it: rejects FLOCI_PORT, since the container port and the probes stay on 4566 + template: templates/deployment.yaml + set: + floci.env: + FLOCI_PORT: 4567 + asserts: + - failedTemplate: + errorMessage: "floci.env.FLOCI_PORT: the chart sets this variable; use service.port (the container always listens on 4566) instead" + + - it: rejects an executor setting the chart derives, even when the chart does not set it + template: templates/deployment.yaml + set: + floci.lambda.executor: docker + floci.env: + FLOCI_SERVICES_LAMBDA_KUBERNETES_NAMESPACE: lambdas + asserts: + - failedTemplate: + errorMessage: "floci.env.FLOCI_SERVICES_LAMBDA_KUBERNETES_NAMESPACE: the chart sets this variable; use floci.lambda.kubernetes.namespace instead" + + - it: rejects the same variables in extraEnv + template: templates/deployment.yaml + set: + extraEnv: + - name: FLOCI_SERVICES_LAMBDA_EXECUTOR + valueFrom: + configMapKeyRef: + name: floci-settings + key: executor + asserts: + - failedTemplate: + errorMessage: "extraEnv FLOCI_SERVICES_LAMBDA_EXECUTOR: the chart sets this variable; use floci.lambda.executor instead" + + - it: passes other extraEnv entries through + template: templates/deployment.yaml + set: + extraEnv: + - name: FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__PASSWORD + valueFrom: + secretKeyRef: + name: registry + key: password + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__PASSWORD + valueFrom: + secretKeyRef: + name: registry + key: password + + - it: mounts the ServiceAccount token only for the kubernetes executor + template: templates/deployment.yaml + asserts: + - equal: + path: spec.template.spec.automountServiceAccountToken + value: true + - equal: + path: spec.template.spec.serviceAccountName + value: floci + + - it: drops the token and the Lambda pod settings for the docker executor + template: templates/deployment.yaml + set: + floci.lambda.executor: docker + asserts: + - equal: + path: spec.template.spec.automountServiceAccountToken + value: false + - contains: + path: spec.template.spec.containers[0].env + content: + name: FLOCI_SERVICES_LAMBDA_EXECUTOR + value: docker + - notContains: + path: spec.template.spec.containers[0].env + content: + name: FLOCI_SERVICES_LAMBDA_KUBERNETES_NAMESPACE + value: aws + + - it: puts /app/data on the chart's claim and switches to persistent storage + template: templates/deployment.yaml + set: + persistence.enabled: true + asserts: + - contains: + path: spec.template.spec.volumes + content: + name: data + persistentVolumeClaim: + claimName: floci-data + - contains: + path: spec.template.spec.containers[0].env + content: + name: FLOCI_STORAGE_MODE + value: persistent + + - it: uses an existing claim and keeps an explicit storage mode + template: templates/deployment.yaml + set: + persistence.enabled: true + persistence.existingClaim: shared-data + floci.storage.mode: wal + asserts: + - contains: + path: spec.template.spec.volumes + content: + name: data + persistentVolumeClaim: + claimName: shared-data + - contains: + path: spec.template.spec.containers[0].env + content: + name: FLOCI_STORAGE_MODE + value: wal + + - it: caps the data emptyDir when dataSizeLimit is set + template: templates/deployment.yaml + set: + dataSizeLimit: 2Gi + asserts: + - contains: + path: spec.template.spec.volumes + content: + name: data + emptyDir: + sizeLimit: 2Gi + + - it: appends the variant to the tag and prefers a digest + template: templates/deployment.yaml + set: + image.variant: compat + asserts: + - equal: + path: spec.template.spec.containers[0].image + value: floci/floci:9.9.9-compat + - equal: + path: metadata.labels["app.kubernetes.io/version"] + value: 9.9.9-compat + + - it: pins the image by digest + template: templates/deployment.yaml + set: + image.digest: sha256:0000000000000000000000000000000000000000000000000000000000000000 + asserts: + - equal: + path: spec.template.spec.containers[0].image + value: floci/floci@sha256:0000000000000000000000000000000000000000000000000000000000000000 + + - it: probes the health endpoint and gates readiness on the ready hooks + template: templates/deployment.yaml + asserts: + - equal: + path: spec.template.spec.containers[0].startupProbe.httpGet.path + value: /_floci/health + - equal: + path: spec.template.spec.containers[0].livenessProbe.httpGet.path + value: /_floci/health + - matchRegex: + path: spec.template.spec.containers[0].readinessProbe.exec.command[2] + pattern: GET /_floci/init HTTP/1.0.*"ready":true + + - it: mounts init hooks per phase and rolls the pod when they change + template: templates/deployment.yaml + set: + initHooks: + ready: + 01-seed.sh: "echo seed" + boot: + 00-check.py: "print('boot')" + asserts: + - contains: + path: spec.template.spec.containers[0].volumeMounts + content: + name: init-hooks + mountPath: /etc/floci/init + readOnly: true + - contains: + path: spec.template.spec.volumes + content: + name: init-hooks + configMap: + name: floci-init-hooks + defaultMode: 0555 + items: + - key: boot-00-check.py + path: boot.d/00-check.py + - key: ready-01-seed.sh + path: ready.d/01-seed.sh + - exists: + path: spec.template.metadata.annotations["checksum/init-hooks"] + + - it: renders the hook scripts into the ConfigMap + template: templates/init-hooks-configmap.yaml + set: + initHooks: + ready: + 01-seed.sh: "#!/bin/sh\necho seed\n" + asserts: + - equal: + path: data["ready-01-seed.sh"] + value: "#!/bin/sh\necho seed" + + - it: renders no hook ConfigMap, mount or checksum without hooks + asserts: + - hasDocuments: + count: 0 + template: templates/init-hooks-configmap.yaml + - notExists: + path: spec.template.metadata.annotations + template: templates/deployment.yaml + + - it: rejects an unknown hook phase + set: + initHooks: + readyy: + 01-seed.sh: "echo" + asserts: + - failedTemplate: + errorPattern: "additional properties 'readyy' not allowed" + + - it: rejects a hook Floci would ignore + template: templates/init-hooks-configmap.yaml + set: + initHooks: + ready: + seed.txt: "echo" + asserts: + - failedTemplate: + errorMessage: "initHooks.ready.seed.txt: hook file names must end in .sh or .py and use only letters, digits, '.', '_' and '-'" + + - it: rejects an unknown executor + set: + floci.lambda.executor: k8s + asserts: + - failedTemplate: + errorPattern: "value must be one of 'docker', 'kubernetes'" diff --git a/charts/floci/tests/hooks_test.yaml b/charts/floci/tests/hooks_test.yaml new file mode 100644 index 0000000000..26202b260b --- /dev/null +++ b/charts/floci/tests/hooks_test.yaml @@ -0,0 +1,188 @@ +suite: helm test pods, cleanup hook and notes +templates: + - templates/tests/test-api.yaml + - templates/tests/test-lambda.yaml + - templates/cleanup-hook.yaml + - templates/NOTES.txt +release: + name: floci + namespace: aws +tests: + - it: runs the API smoke test against the Service DNS name + template: templates/tests/test-api.yaml + asserts: + - equal: + path: metadata.annotations["helm.sh/hook"] + value: test + - contains: + path: spec.containers[0].env + content: + name: FLOCI_ENDPOINT + value: http://floci.aws.svc.cluster.local:4566 + - equal: + path: spec.automountServiceAccountToken + value: false + - equal: + path: spec.containers[0].securityContext.readOnlyRootFilesystem + value: true + + - it: runs the test pods and the cleanup hook under Floci's pod security context + templates: + - templates/tests/test-api.yaml + - templates/cleanup-hook.yaml + asserts: + - equal: + path: spec.securityContext + value: + runAsNonRoot: true + runAsUser: 1001 + runAsGroup: 1001 + fsGroup: 1001 + fsGroupChangePolicy: OnRootMismatch + seccompProfile: + type: RuntimeDefault + + - it: drops the fixed IDs from every pod with the documented OpenShift override + templates: + - templates/tests/test-api.yaml + - templates/tests/test-lambda.yaml + - templates/cleanup-hook.yaml + set: + tests.lambda.enabled: true + podSecurityContext: + runAsUser: null + runAsGroup: null + fsGroup: null + documentSelector: + path: kind + value: Pod + matchMany: true + asserts: + - equal: + path: spec.securityContext + value: + runAsNonRoot: true + fsGroupChangePolicy: OnRootMismatch + seccompProfile: + type: RuntimeDefault + + - it: expects https response URLs when TLS is on + template: templates/tests/test-api.yaml + set: + floci.tls.enabled: true + asserts: + - contains: + path: spec.containers[0].env + content: + name: FLOCI_EFFECTIVE_BASE_URL + value: https://floci.aws.svc.cluster.local:4566 + + - it: applies floci.hostname to the expected response URLs + template: templates/tests/test-api.yaml + set: + floci.hostname: floci.example.test + asserts: + - contains: + path: spec.containers[0].env + content: + name: FLOCI_EFFECTIVE_BASE_URL + value: http://floci.example.test:4566 + + - it: runs the Lambda test only when asked + template: templates/tests/test-lambda.yaml + asserts: + - hasDocuments: + count: 0 + + - it: ships the function source in a ConfigMap created before the test pod + template: templates/tests/test-lambda.yaml + set: + tests.lambda.enabled: true + asserts: + - hasDocuments: + count: 2 + - equal: + path: metadata.annotations["helm.sh/hook-weight"] + value: "-1" + documentSelector: + path: kind + value: ConfigMap + - contains: + path: spec.volumes + content: + name: fixtures + configMap: + name: floci-test-lambda + documentSelector: + path: kind + value: Pod + + - it: cleans up runtime objects before uninstall, under Floci's ServiceAccount + template: templates/cleanup-hook.yaml + asserts: + - equal: + path: metadata.annotations["helm.sh/hook"] + value: pre-delete + - equal: + path: spec.serviceAccountName + value: floci + - contains: + path: spec.containers[0].env + content: + name: LAMBDA_NAMESPACE + value: aws + # Also with TLS off: an earlier revision with TLS on may have created it. + - contains: + path: spec.containers[0].env + content: + name: CA_CONFIG_MAP + value: floci-lambda-ca + + - it: cleans up the Lambda namespace with TLS + template: templates/cleanup-hook.yaml + set: + floci.tls.enabled: true + floci.lambda.kubernetes.namespace: lambdas + asserts: + - contains: + path: spec.containers[0].env + content: + name: CA_CONFIG_MAP + value: floci-lambda-ca + - contains: + path: spec.containers[0].env + content: + name: LAMBDA_NAMESPACE + value: lambdas + + - it: skips the cleanup hook when it has nothing to do or no permissions + template: templates/cleanup-hook.yaml + set: + floci.lambda.executor: docker + asserts: + - hasDocuments: + count: 0 + + - it: skips the cleanup hook when disabled + template: templates/cleanup-hook.yaml + set: + cleanup.enabled: false + asserts: + - hasDocuments: + count: 0 + + - it: prints the in-cluster endpoint and the Lambda namespace + template: templates/NOTES.txt + asserts: + - matchRegexRaw: + pattern: "export AWS_ENDPOINT_URL=http://floci.aws.svc.cluster.local:4566" + - matchRegexRaw: + pattern: "Lambda functions run as pods in namespace aws" + + - it: warns when a durable storage mode has no volume + template: templates/NOTES.txt + set: + floci.storage.mode: hybrid + asserts: + - matchRegexRaw: + pattern: "WARNING: storage mode is hybrid but persistence.enabled is false" diff --git a/charts/floci/tests/rbac_test.yaml b/charts/floci/tests/rbac_test.yaml new file mode 100644 index 0000000000..0a74770a27 --- /dev/null +++ b/charts/floci/tests/rbac_test.yaml @@ -0,0 +1,165 @@ +suite: rbac and service account +templates: + - templates/rbac.yaml + - templates/serviceaccount.yaml +release: + name: floci + namespace: aws +tests: + - it: grants only the pod calls the kubernetes Lambda executor makes + template: templates/rbac.yaml + documentSelector: + path: kind + value: Role + set: + cleanup.enabled: false + asserts: + - equal: + path: metadata.namespace + value: aws + - equal: + path: rules + value: + - apiGroups: [""] + resources: ["pods"] + verbs: ["create", "get", "list", "delete"] + - apiGroups: [""] + resources: ["pods/log"] + verbs: ["get"] + + - it: lets the cleanup hook delete a CA ConfigMap left from TLS, by name, with TLS off + template: templates/rbac.yaml + documentSelector: + path: kind + value: Role + asserts: + - equal: + path: rules + value: + - apiGroups: [""] + resources: ["pods"] + verbs: ["create", "get", "list", "delete"] + - apiGroups: [""] + resources: ["pods/log"] + verbs: ["get"] + - apiGroups: [""] + resources: ["configmaps"] + resourceNames: ["floci-lambda-ca"] + verbs: ["delete"] + + - it: binds the Role to the chart's ServiceAccount + template: templates/rbac.yaml + documentSelector: + path: kind + value: RoleBinding + asserts: + - equal: + path: roleRef.name + value: floci-lambda + - equal: + path: subjects + value: + - kind: ServiceAccount + name: floci + namespace: aws + + - it: adds the CA ConfigMap rules, scoped by name, with TLS + template: templates/rbac.yaml + documentSelector: + path: kind + value: Role + set: + floci.tls.enabled: true + asserts: + - contains: + path: rules + content: + apiGroups: [""] + resources: ["configmaps"] + verbs: ["create"] + - contains: + path: rules + content: + apiGroups: [""] + resources: ["configmaps"] + resourceNames: ["floci-lambda-ca"] + verbs: ["get", "update", "delete"] + + - it: leaves out delete on the CA ConfigMap without the cleanup hook + template: templates/rbac.yaml + documentSelector: + path: kind + value: Role + set: + floci.tls.enabled: true + cleanup.enabled: false + asserts: + - contains: + path: rules + content: + apiGroups: [""] + resources: ["configmaps"] + resourceNames: ["floci-lambda-ca"] + verbs: ["get", "update"] + + - it: creates the Role and binding in a separate Lambda namespace + template: templates/rbac.yaml + set: + floci.lambda.kubernetes.namespace: lambdas + asserts: + - equal: + path: metadata.namespace + value: lambdas + - equal: + path: subjects[0].namespace + value: aws + documentSelector: + path: kind + value: RoleBinding + + - it: creates no RBAC for the docker executor or when disabled + template: templates/rbac.yaml + set: + floci.lambda.executor: docker + asserts: + - hasDocuments: + count: 0 + + - it: creates no RBAC when rbac.create is false + template: templates/rbac.yaml + set: + rbac.create: false + asserts: + - hasDocuments: + count: 0 + + - it: creates a ServiceAccount that does not mount its token by itself + template: templates/serviceaccount.yaml + set: + serviceAccount.annotations: + eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/floci + asserts: + - isKind: + of: ServiceAccount + - equal: + path: automountServiceAccountToken + value: false + - equal: + path: metadata.annotations["eks.amazonaws.com/role-arn"] + value: arn:aws:iam::123456789012:role/floci + + - it: uses an existing ServiceAccount when create is false + set: + serviceAccount.create: false + serviceAccount.name: shared + asserts: + - hasDocuments: + count: 0 + template: templates/serviceaccount.yaml + - equal: + path: subjects[0].name + value: shared + template: templates/rbac.yaml + documentSelector: + path: kind + value: RoleBinding diff --git a/charts/floci/tests/service_ingress_test.yaml b/charts/floci/tests/service_ingress_test.yaml new file mode 100644 index 0000000000..605d2a6f31 --- /dev/null +++ b/charts/floci/tests/service_ingress_test.yaml @@ -0,0 +1,171 @@ +suite: service, ingress and persistence +templates: + - templates/service.yaml + - templates/ingress.yaml + - templates/pvc.yaml +release: + name: floci + namespace: aws +tests: + - it: exposes the API port as a ClusterIP Service + template: templates/service.yaml + asserts: + - equal: + path: spec.type + value: ClusterIP + - equal: + path: spec.ports + value: + - name: http + port: 4566 + targetPort: http + protocol: TCP + - equal: + path: spec.selector + value: + app.kubernetes.io/name: floci + app.kubernetes.io/instance: floci + + - it: publishes each port of a range as its own Service port + template: templates/service.yaml + set: + service.portRanges: + - name: elasticache + start: 6379 + end: 6399 + - name: rds + start: 7001 + end: 7003 + asserts: + - lengthEqual: + path: spec.ports + count: 25 + - contains: + path: spec.ports + content: + name: elasticache-6399 + port: 6399 + targetPort: 6399 + protocol: TCP + - contains: + path: spec.ports + content: + name: rds-7001 + port: 7001 + targetPort: 7001 + protocol: TCP + + - it: rejects a range whose start is above its end + template: templates/service.yaml + set: + service.portRanges: + - name: rds + start: 7099 + end: 7001 + asserts: + - failedTemplate: + errorMessage: "service.portRanges rds: start 7099 is above end 7001" + + - it: sets the node port and traffic policy for NodePort + template: templates/service.yaml + set: + service.type: NodePort + service.nodePort: 30566 + service.externalTrafficPolicy: Local + asserts: + - equal: + path: spec.ports[0].nodePort + value: 30566 + - equal: + path: spec.externalTrafficPolicy + value: Local + + - it: ignores the node port for ClusterIP + template: templates/service.yaml + set: + service.nodePort: 30566 + asserts: + - notExists: + path: spec.ports[0].nodePort + + - it: renders no Ingress by default + template: templates/ingress.yaml + asserts: + - hasDocuments: + count: 0 + + - it: routes the Ingress hosts to the Service port + template: templates/ingress.yaml + set: + service.port: 80 + ingress.enabled: true + ingress.className: nginx + ingress.hosts: + - host: floci.example.test + paths: + - path: / + ingress.tls: + - hosts: [floci.example.test] + secretName: floci-tls + asserts: + - equal: + path: spec.ingressClassName + value: nginx + - equal: + path: spec.rules + value: + - host: floci.example.test + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: floci + port: + number: 80 + - equal: + path: spec.tls[0].secretName + value: floci-tls + + - it: creates a claim only when persistence is on and no claim is given + template: templates/pvc.yaml + asserts: + - hasDocuments: + count: 0 + + - it: creates the claim with the requested class and size + template: templates/pvc.yaml + set: + persistence.enabled: true + persistence.size: 2Gi + persistence.storageClass: fast + asserts: + - equal: + path: metadata.name + value: floci-data + - equal: + path: spec.storageClassName + value: fast + - equal: + path: spec.resources.requests.storage + value: 2Gi + + - it: turns storageClass "-" into an empty storageClassName + template: templates/pvc.yaml + set: + persistence.enabled: true + persistence.storageClass: "-" + asserts: + - equal: + path: spec.storageClassName + value: "" + + - it: skips the claim for an existing one + template: templates/pvc.yaml + set: + persistence.enabled: true + persistence.existingClaim: shared-data + asserts: + - hasDocuments: + count: 0 diff --git a/charts/floci/tests/snapshot_test.yaml b/charts/floci/tests/snapshot_test.yaml new file mode 100644 index 0000000000..d2a09acf5a --- /dev/null +++ b/charts/floci/tests/snapshot_test.yaml @@ -0,0 +1,19 @@ +# Snapshots of the default render. A change to them is intended only when the chart's +# output is meant to change: review the diff, then refresh with `helm unittest -u charts/floci`. +suite: default render snapshot +templates: + - templates/deployment.yaml + - templates/service.yaml + - templates/serviceaccount.yaml + - templates/rbac.yaml +release: + name: floci + namespace: aws +# Fixed so a chart or app version bump does not churn the snapshots. +chart: + version: 0.0.0 + appVersion: 0.0.0 +tests: + - it: matches the default manifests + asserts: + - matchSnapshot: {} diff --git a/charts/floci/values.schema.json b/charts/floci/values.schema.json new file mode 100644 index 0000000000..61474b8a25 --- /dev/null +++ b/charts/floci/values.schema.json @@ -0,0 +1,236 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Floci chart values", + "type": "object", + "additionalProperties": false, + "definitions": { + "stringMap": { + "type": "object", + "additionalProperties": { "type": "string" } + }, + "image": { + "type": "object", + "additionalProperties": false, + "required": ["repository", "tag"], + "properties": { + "repository": { "type": "string", "minLength": 1 }, + "tag": { "type": "string" }, + "pullPolicy": { "type": "string", "enum": ["Always", "IfNotPresent", "Never"] } + } + }, + "hookScripts": { + "type": ["object", "null"], + "additionalProperties": { "type": "string" } + }, + "probe": { + "type": ["object", "null"] + } + }, + "properties": { + "global": { "type": "object" }, + "nameOverride": { "type": "string" }, + "fullnameOverride": { "type": "string" }, + "image": { + "type": "object", + "additionalProperties": false, + "properties": { + "repository": { "type": "string", "minLength": 1 }, + "tag": { "type": "string" }, + "variant": { "type": "string" }, + "digest": { "type": "string", "pattern": "^$|^sha256:[a-f0-9]{64}$" }, + "pullPolicy": { "type": "string", "enum": ["Always", "IfNotPresent", "Never"] } + } + }, + "imagePullSecrets": { "type": "array", "items": { "type": "object" } }, + "floci": { + "type": "object", + "additionalProperties": false, + "properties": { + "baseUrl": { "type": "string", "pattern": "^$|^https?://" }, + "hostname": { "type": "string" }, + "clusterDomain": { "type": "string", "minLength": 1 }, + "defaultRegion": { "type": "string" }, + "defaultAccountId": { + "description": "A string, so leading zeros survive; quote it in YAML.", + "type": "string", + "pattern": "^$|^[0-9]{12}$" + }, + "storage": { + "type": "object", + "additionalProperties": false, + "properties": { + "mode": { "type": "string", "enum": ["", "memory", "persistent", "hybrid", "wal"] } + } + }, + "tls": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { "type": "boolean" } + } + }, + "lambda": { + "type": "object", + "additionalProperties": false, + "properties": { + "executor": { "type": "string", "enum": ["docker", "kubernetes"] }, + "kubernetes": { + "type": "object", + "additionalProperties": false, + "properties": { + "namespace": { "type": "string" }, + "initImage": { "type": "string" }, + "labels": { "type": "array", "items": { "type": "string", "pattern": "^[^=,]+=[^,]*$" } }, + "flociAddress": { "type": "string", "pattern": "^$|^[A-Za-z0-9.-]+$" } + } + } + } + }, + "env": { + "type": "object", + "propertyNames": { "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" }, + "additionalProperties": { "type": ["string", "number", "boolean"] } + } + } + }, + "extraEnv": { "type": "array", "items": { "type": "object", "required": ["name"] } }, + "extraEnvFrom": { "type": "array", "items": { "type": "object" } }, + "initHooks": { + "type": "object", + "additionalProperties": false, + "properties": { + "boot": { "$ref": "#/definitions/hookScripts" }, + "start": { "$ref": "#/definitions/hookScripts" }, + "ready": { "$ref": "#/definitions/hookScripts" }, + "stop": { "$ref": "#/definitions/hookScripts" } + } + }, + "serviceAccount": { + "type": "object", + "additionalProperties": false, + "properties": { + "create": { "type": "boolean" }, + "name": { "type": "string" }, + "annotations": { "$ref": "#/definitions/stringMap" } + } + }, + "rbac": { + "type": "object", + "additionalProperties": false, + "properties": { + "create": { "type": "boolean" } + } + }, + "persistence": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { "type": "boolean" }, + "existingClaim": { "type": "string" }, + "storageClass": { "type": "string" }, + "accessModes": { + "type": "array", + "minItems": 1, + "items": { "type": "string", "enum": ["ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany", "ReadWriteOncePod"] } + }, + "size": { "type": "string", "minLength": 1 }, + "annotations": { "$ref": "#/definitions/stringMap" } + } + }, + "dataSizeLimit": { "type": "string" }, + "service": { + "type": "object", + "additionalProperties": false, + "properties": { + "type": { "type": "string", "enum": ["ClusterIP", "NodePort", "LoadBalancer"] }, + "port": { "type": "integer", "minimum": 1, "maximum": 65535 }, + "nodePort": { "type": ["integer", "string"] }, + "annotations": { "$ref": "#/definitions/stringMap" }, + "labels": { "$ref": "#/definitions/stringMap" }, + "loadBalancerSourceRanges": { "type": "array", "items": { "type": "string" } }, + "externalTrafficPolicy": { "type": "string", "enum": ["", "Cluster", "Local"] }, + "portRanges": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "required": ["name", "start", "end"], + "properties": { + "name": { "type": "string", "pattern": "^[a-z]([a-z0-9-]*[a-z0-9])?$" }, + "start": { "type": "integer", "minimum": 1, "maximum": 65535 }, + "end": { "type": "integer", "minimum": 1, "maximum": 65535 } + } + } + }, + "extraPorts": { "type": "array", "items": { "type": "object" } } + } + }, + "ingress": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { "type": "boolean" }, + "className": { "type": "string" }, + "annotations": { "$ref": "#/definitions/stringMap" }, + "hosts": { + "type": "array", + "items": { + "type": "object", + "properties": { + "host": { "type": "string" }, + "paths": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "required": ["path"], + "properties": { + "path": { "type": "string" }, + "pathType": { "type": "string", "enum": ["Prefix", "Exact", "ImplementationSpecific"] } + } + } + } + } + } + }, + "tls": { "type": "array", "items": { "type": "object" } } + } + }, + "podSecurityContext": { "type": ["object", "null"] }, + "securityContext": { "type": ["object", "null"] }, + "resources": { "type": ["object", "null"] }, + "startupProbe": { "$ref": "#/definitions/probe" }, + "livenessProbe": { "$ref": "#/definitions/probe" }, + "readinessProbe": { "$ref": "#/definitions/probe" }, + "terminationGracePeriodSeconds": { "type": "integer", "minimum": 0 }, + "podAnnotations": { "$ref": "#/definitions/stringMap" }, + "podLabels": { "$ref": "#/definitions/stringMap" }, + "priorityClassName": { "type": "string" }, + "nodeSelector": { "$ref": "#/definitions/stringMap" }, + "tolerations": { "type": "array", "items": { "type": "object" } }, + "affinity": { "type": "object" }, + "extraVolumes": { "type": "array", "items": { "type": "object", "required": ["name"] } }, + "extraVolumeMounts": { "type": "array", "items": { "type": "object", "required": ["name", "mountPath"] } }, + "helperImage": { "$ref": "#/definitions/image" }, + "cleanup": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { "type": "boolean" } + } + }, + "tests": { + "type": "object", + "additionalProperties": false, + "properties": { + "lambda": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { "type": "boolean" } + } + } + } + } + } +} diff --git a/charts/floci/values.yaml b/charts/floci/values.yaml new file mode 100644 index 0000000000..4e60acb86d --- /dev/null +++ b/charts/floci/values.yaml @@ -0,0 +1,302 @@ +# Default values for the Floci chart. +# +# Floci runs as a single pod behind one Service on port 4566. State lives in that pod +# (in memory, or under /app/data with persistence), so the chart always runs one +# replica and replaces it with the Recreate strategy. +# +# Install and usage examples: docs/getting-started/kubernetes.md, or +# https://floci.io/floci/getting-started/kubernetes/ + +# -- Overrides the chart name used in resource names and the app.kubernetes.io/name label. +nameOverride: "" +# -- Overrides the full resource name (defaults to "-floci", or the release name +# when it already contains "floci"). +fullnameOverride: "" + +image: + # -- Image repository. floci/floci is the native image on UBI 9 micro (bash and coreutils + # only). public.ecr.aws/floci/floci carries the same images. + repository: floci/floci + # -- Image tag. Empty means the chart's appVersion. + tag: "" + # -- Image variant appended to the tag as "-". "compat" adds Python 3, the AWS + # CLI and boto3, which init hooks that call `aws` need; "baseline" is the ARM64 build + # for CPUs without LSE (release tags only). + variant: "" + # -- Image digest ("sha256:..."). When set it pins the image and takes precedence over the tag. + digest: "" + # -- Image pull policy. + pullPolicy: IfNotPresent + +# -- Pull secrets for the Floci image, as a list of {name: }. +imagePullSecrets: [] + +floci: + # -- FLOCI_BASE_URL, the URL Floci embeds in responses (SQS QueueUrl, pre-signed URLs). + # Empty means the in-cluster Service address, + # http://..svc.:. Set it to the Ingress + # URL when clients reach Floci from outside the cluster. + baseUrl: "" + # -- FLOCI_HOSTNAME, which overrides only the hostname part of the base URL. + hostname: "" + # -- Cluster DNS domain used to build the default base URL. + clusterDomain: cluster.local + # -- FLOCI_DEFAULT_REGION. Empty keeps Floci's default (us-east-1). + defaultRegion: "" + # -- FLOCI_DEFAULT_ACCOUNT_ID. Empty keeps Floci's default (000000000000). + defaultAccountId: "" + + storage: + # -- FLOCI_STORAGE_MODE: memory, persistent, hybrid or wal. Empty selects "persistent" + # when persistence.enabled is true and "memory" otherwise. + mode: "" + + tls: + # -- FLOCI_TLS_ENABLED. Floci then serves HTTPS and plain HTTP on the same port 4566 + # with a self-signed certificate (download its CA from /_floci/ca.pem). + enabled: false + + lambda: + # -- FLOCI_SERVICES_LAMBDA_EXECUTOR. "kubernetes" runs every Lambda execution + # environment as a pod in lambda.kubernetes.namespace and needs the RBAC below. + # "docker" needs a Docker daemon reachable from the pod (set FLOCI_DOCKER_DOCKER_HOST + # in floci.env), which most clusters do not offer. + executor: kubernetes + kubernetes: + # -- Namespace Lambda pods are created in. Empty means the release namespace. Use one + # release per Lambda namespace: Floci's orphan sweep and the uninstall cleanup hook + # delete every Floci Lambda pod in it, and the CA ConfigMap name is fixed. + namespace: "" + # -- Init container image that downloads function code into the pod (needs sh, wget + # and unzip). Empty keeps Floci's default (busybox:1.36). + initImage: "" + # -- Extra labels for Lambda pods, as "key=value" strings. + labels: [] + # -- Address Lambda pods use to reach Floci. Empty lets Floci advertise its own pod + # IP, which is right for an in-cluster install. + flociAddress: "" + + # -- Any other Floci setting, as FLOCI_* environment variables (see + # docs/configuration/environment-variables.md). Values are rendered as strings. The + # variables the chart sets from the settings above, and FLOCI_PORT (the container always + # listens on 4566), fail the render here; the error names the value to set instead. + env: {} + # FLOCI_SERVICES_SQS_ENDPOINT_STRATEGY: aws + # FLOCI_SERVICES_LAMBDA_CONTAINER_IDLE_TIMEOUT_SECONDS: "300" + +# -- Extra container environment variables in Kubernetes EnvVar form (for valueFrom). The +# variables the chart sets are refused here as in floci.env. +extraEnv: [] + # - name: FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__PASSWORD + # valueFrom: + # secretKeyRef: {name: registry, key: password} + +# -- Extra environment sources (ConfigMaps or Secrets) in Kubernetes EnvFromSource form. +extraEnvFrom: [] + +# -- Initialization hook scripts, mounted under /etc/floci/init/.d. Each phase maps +# a file name (ending in .sh or .py) to its content. Scripts run in lexicographic order +# and a failing boot, start or ready hook stops Floci (docs/configuration/initialization-hooks.md). +# Scripts that call the AWS CLI or boto3 need the "-compat" image tag. +initHooks: + boot: {} + start: {} + ready: {} + # 01-seed.sh: | + # #!/bin/sh + # set -eu + # aws s3 mb s3://my-bucket + stop: {} + +serviceAccount: + # -- Create a ServiceAccount for Floci. Its token is mounted only for the kubernetes + # Lambda executor, the one feature that calls the Kubernetes API. + create: true + # -- ServiceAccount name. Empty means the full name when create is true, "default" otherwise. + name: "" + # -- Annotations for the ServiceAccount. + annotations: {} + +rbac: + # -- Create the Role and RoleBinding the kubernetes Lambda executor needs, in the Lambda + # namespace: pods create/get/list/delete, pods/log get and, with TLS, the floci-lambda-ca + # ConfigMap (plus its delete for the cleanup hook, with or without TLS). Nothing is + # created for the docker executor. + create: true + +persistence: + # -- Keep /app/data on a PersistentVolumeClaim. Without it /app/data is an emptyDir and + # state is gone when the pod is replaced. + enabled: false + # -- Use an existing claim instead of creating one. + existingClaim: "" + # -- StorageClass of the created claim. Empty uses the cluster default, "-" sets + # storageClassName to "" (no dynamic provisioning). + storageClass: "" + # -- Access modes of the created claim. + accessModes: + - ReadWriteOnce + # -- Size of the created claim. + size: 8Gi + # -- Annotations for the created claim (for example helm.sh/resource-policy: keep). + annotations: {} + +# -- Size limit of the emptyDir that holds /app/data when persistence is disabled +# (for example "2Gi"). Empty means no limit. +dataSizeLimit: "" + +service: + # -- Service type. + type: ClusterIP + # -- Service port for the AWS API endpoint. The container always listens on 4566. + port: 4566 + # -- Node port for NodePort and LoadBalancer services. Empty lets Kubernetes choose. + nodePort: "" + # -- Annotations for the Service. + annotations: {} + # -- Extra labels for the Service. + labels: {} + # -- Source ranges allowed through a LoadBalancer. + loadBalancerSourceRanges: [] + # -- externalTrafficPolicy for NodePort and LoadBalancer services (Cluster or Local). + externalTrafficPolicy: "" + # -- Port ranges published as one Service port each, for the TCP proxies Floci runs in + # its own process for container-backed services, as docker-compose.yml maps them. They + # only carry traffic when Floci can reach a Docker daemon (FLOCI_DOCKER_DOCKER_HOST). + portRanges: [] + # - name: elasticache # 6379-6399, FLOCI_SERVICES_ELASTICACHE_PROXY_BASE_PORT/_MAX_PORT + # start: 6379 + # end: 6399 + # - name: rds # 7001-7099, FLOCI_SERVICES_RDS_PROXY_BASE_PORT/_MAX_PORT + # start: 7001 + # end: 7099 + # -- Extra Service ports in Kubernetes ServicePort form. + extraPorts: [] + +ingress: + # -- Expose the API endpoint through an Ingress. + enabled: false + # -- IngressClass name. + className: "" + # -- Annotations for the Ingress. Large S3 uploads may need a body size annotation for + # your controller. + annotations: {} + # -- Hosts and paths routed to the Service. + hosts: + - host: floci.local + paths: + - path: / + pathType: Prefix + # -- TLS configuration, in Kubernetes IngressTLS form. + tls: [] + +# -- Pod security context of Floci, the `helm test` pods and the uninstall cleanup hook. +# The defaults satisfy the "restricted" Pod Security Standard. On OpenShift, which assigns +# each namespace its own UID range, set runAsUser, runAsGroup and fsGroup to null: Helm +# merges a map given here into these defaults, so leaving the keys out keeps them. +podSecurityContext: + runAsNonRoot: true + runAsUser: 1001 + runAsGroup: 1001 + fsGroup: 1001 + fsGroupChangePolicy: OnRootMismatch + seccompProfile: + type: RuntimeDefault + +# -- Container security context. Floci writes only to /app/data and /tmp, which the chart +# mounts as volumes, so the root filesystem stays read-only. +securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: + - ALL + +# -- Resource requests and limits. Floci keeps state in memory, so raise the memory limit +# for large S3 objects or many Lambda functions in memory storage mode. +resources: + requests: + cpu: 100m + memory: 128Mi + limits: + memory: 1Gi + +# -- Startup probe. /_floci/health answers once the HTTP server is up; boot hooks run +# before that, so the budget (2 minutes) covers them. +startupProbe: + httpGet: + path: /_floci/health + port: http + periodSeconds: 2 + timeoutSeconds: 3 + failureThreshold: 60 + +# -- Liveness probe on /_floci/health. +livenessProbe: + httpGet: + path: /_floci/health + port: http + periodSeconds: 10 + timeoutSeconds: 3 + failureThreshold: 3 + +# -- Readiness probe. Ready once /_floci/init reports the ready phase complete, so the +# Service only sends traffic after every start and ready hook has run. The image has no +# curl, so the probe speaks HTTP/1.0 through bash's /dev/tcp like docker/healthcheck.sh. +readinessProbe: + exec: + command: + - /bin/bash + - -c + - >- + exec 3<>/dev/tcp/127.0.0.1/4566 && + printf 'GET /_floci/init HTTP/1.0\r\nHost: localhost\r\n\r\n' >&3 && + { IFS= read -r -d '' response <&3; [[ $response == "HTTP/1."?" 200"*'"ready":true'* ]]; } + periodSeconds: 5 + timeoutSeconds: 3 + failureThreshold: 3 + +# -- Seconds Floci gets to run stop hooks and shut down. +terminationGracePeriodSeconds: 30 + +# -- Extra pod annotations. +podAnnotations: {} +# -- Extra pod labels. +podLabels: {} +# -- PriorityClass of the pod. +priorityClassName: "" +# -- Node selector. +nodeSelector: {} +# -- Tolerations. +tolerations: [] +# -- Affinity rules. +affinity: {} + +# -- Extra volumes for the pod. +extraVolumes: [] +# -- Extra volume mounts for the Floci container. +extraVolumeMounts: [] + +# -- Image for the `helm test` pods and the uninstall cleanup hook: AWS CLI v2 on Amazon +# Linux 2023, which also brings sh, curl and python3. Both pods run under podSecurityContext. +helperImage: + repository: amazon/aws-cli + tag: "2.39.6" + pullPolicy: IfNotPresent + +cleanup: + # -- Run a pre-delete hook, under Floci's ServiceAccount, that deletes every Floci Lambda + # pod in the Lambda namespace and the floci-lambda-ca ConfigMap, the objects Floci creates + # at runtime (so use one release per Lambda namespace). Helm removes the + # ServiceAccount while Floci is still shutting down, so Floci's own drain of warm pods + # can no longer authenticate and those pods would stay behind until the next install's + # orphan sweep. Best effort: its script always exits 0 and bounds every API call. If the + # hook pod itself cannot run (its image cannot be pulled), `helm uninstall --no-hooks` + # skips it. Applies to the kubernetes executor with rbac.create. + enabled: true + +tests: + lambda: + # -- Also run a Python Lambda function in `helm test`. With the kubernetes executor this + # starts a real Lambda pod, so the node pulls public.ecr.aws/lambda/python:3.12. + enabled: false diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md index 12770e4a85..6c3bda143d 100644 --- a/docs/getting-started/installation.md +++ b/docs/getting-started/installation.md @@ -1,6 +1,7 @@ # Installation Floci can be run three ways: as a Docker image, as a pre-built native binary, or built from source. +To run it in a Kubernetes cluster, use the Helm chart: see [Kubernetes (Helm)](kubernetes.md). ## Docker (Recommended) diff --git a/docs/getting-started/kubernetes.md b/docs/getting-started/kubernetes.md new file mode 100644 index 0000000000..0416d7b85b --- /dev/null +++ b/docs/getting-started/kubernetes.md @@ -0,0 +1,277 @@ +# Kubernetes (Helm) + +The Helm chart in [`charts/floci`](https://github.com/floci-io/floci/tree/main/charts/floci) runs +Floci as one pod behind one Service, for CI pipelines and development clusters where Docker Compose +is not an option. Lambda functions run as pods through the +[Kubernetes executor](../services/lambda.md#kubernetes-executor), so the cluster needs no Docker +socket and no privileged containers. + +The defaults satisfy the `restricted` Pod Security Standard: Floci runs as UID 1001 with a read-only +root filesystem, no capabilities and the `RuntimeDefault` seccomp profile. + +## Install + +The chart is not published to a chart repository yet, so install it from a checkout: + +```bash +git clone https://github.com/floci-io/floci.git +helm install floci ./floci/charts/floci --namespace floci --create-namespace --wait +helm test floci --namespace floci --logs +``` + +`helm test` runs the AWS CLI in a pod against the Service: it creates an S3 bucket, writes and reads +an object, and checks that SQS returns a `QueueUrl` on the Service's address. Add +`--set tests.lambda.enabled=true` to the install to also create and invoke a Python Lambda function, +which starts a real Lambda pod. + +Test pods are deleted as soon as they pass. Helm 4 prints their logs first; Helm 3 prints logs only +for a failed test, whose pod is kept. + +Requirements: Kubernetes 1.25 or later and Helm 3 or 4. The chart has been verified with Helm 4.3.1 +and 3.22.1, on kind (Kubernetes 1.34 and 1.37) and OrbStack (Kubernetes 1.36). + +## Use it from the cluster + +Every pod reaches Floci at `http://-floci..svc.cluster.local:4566`, or +`http://floci..svc.cluster.local:4566` when the release is named `floci`, with any +credentials: + +```bash +kubectl run aws-cli --rm -it --restart=Never --image amazon/aws-cli:2.39.6 \ + --env AWS_ACCESS_KEY_ID=test --env AWS_SECRET_ACCESS_KEY=test --env AWS_DEFAULT_REGION=us-east-1 \ + --command -- sh -c ' + endpoint=http://floci.floci.svc.cluster.local:4566 + aws --endpoint-url "$endpoint" s3 mb s3://demo-bucket + aws --endpoint-url "$endpoint" s3 ls' +``` + +For an application, set the endpoint once in its environment; AWS SDKs and the AWS CLI v2 read it: + +```yaml +env: + - name: AWS_ENDPOINT_URL + value: http://floci.floci.svc.cluster.local:4566 + - name: AWS_ACCESS_KEY_ID + value: test + - name: AWS_SECRET_ACCESS_KEY + value: test + - name: AWS_REGION + value: us-east-1 +``` + +URLs Floci puts in responses, such as SQS `QueueUrl` and pre-signed S3 URLs, use the Service address +too: the chart sets `FLOCI_BASE_URL` to it. Clients outside the cluster can use a port-forward: + +```bash +kubectl port-forward --namespace floci svc/floci 4566:4566 +aws --endpoint-url http://localhost:4566 s3 ls +``` + +or an Ingress (`ingress.enabled=true`); then set `floci.baseUrl` to the Ingress URL so the URLs in +responses point there. + +## Configuration + +[`values.yaml`](https://github.com/floci-io/floci/blob/main/charts/floci/values.yaml) documents every +value. The ones most installs touch: + +| Value | Default | Description | +|---|---|---| +| `image.repository` / `image.tag` | `floci/floci` / chart `appVersion` | Image to run. | +| `image.variant` | `""` | Appended to the tag: `compat` adds Python 3, the AWS CLI and boto3 for init hooks. | +| `floci.baseUrl` | Service URL | `FLOCI_BASE_URL`, the base of URLs in responses. | +| `floci.storage.mode` | `memory`, or `persistent` with persistence | `FLOCI_STORAGE_MODE`. | +| `floci.tls.enabled` | `false` | `FLOCI_TLS_ENABLED`: HTTPS and HTTP on port 4566. | +| `floci.lambda.executor` | `kubernetes` | `kubernetes` runs Lambda pods; `docker` needs a Docker daemon. | +| `floci.lambda.kubernetes.namespace` | release namespace | Where Lambda pods run. | +| `floci.env` | `{}` | Any other `FLOCI_*` variable (see [Environment Variables](../configuration/environment-variables.md)). | +| `initHooks.` | `{}` | Hook scripts per phase (`boot`, `start`, `ready`, `stop`). | +| `persistence.enabled` | `false` | Keep `/app/data` on a PersistentVolumeClaim. | +| `rbac.create` | `true` | Role and RoleBinding for the Kubernetes executor. | +| `service.type` / `service.port` | `ClusterIP` / `4566` | Service exposure. | +| `ingress.enabled` | `false` | Ingress to the Service. | +| `resources` | 100m CPU, 128Mi requested; 1Gi memory limit | Raise the limit for large in-memory data. | + +Any other `FLOCI_*` setting can go in `floci.env`: + +```yaml +floci: + defaultRegion: eu-central-1 + env: + FLOCI_SERVICES_SQS_ENDPOINT_STRATEGY: aws + FLOCI_SERVICES_LAMBDA_CONTAINER_IDLE_TIMEOUT_SECONDS: 300 +``` + +The variables the chart sets itself cannot go there or in `extraEnv`, because other manifests follow +the values behind them: the Role and the ServiceAccount token follow `floci.lambda.executor` and +`floci.tls.enabled`, and the container port and the probes are fixed at 4566, so `FLOCI_PORT` is +refused too (`service.port` changes the Service port). The render fails and names the value to set: + +``` +Error: execution error at (floci/templates/deployment.yaml:68:16): floci.env.FLOCI_TLS_ENABLED: the chart sets this variable; use floci.tls.enabled instead +``` + +The chart ships a JSON schema, so a misspelled key or a wrong type fails `helm install` instead of +being ignored. Pass account IDs as strings (`--set-string floci.defaultAccountId=123456789012`). + +## Lambda on Kubernetes + +With the default `floci.lambda.executor=kubernetes`, each Lambda execution environment is a pod in +`floci.lambda.kubernetes.namespace`: an init container downloads the function code from Floci, and +the runtime container polls Floci's Runtime API. See +[Kubernetes executor](../services/lambda.md#kubernetes-executor) for how it works and its limits. + +```bash +cat > handler.py <<'PY' +def handler(event, context): + return {"hello": event.get("name", "world")} +PY +zip function.zip handler.py +aws --endpoint-url http://localhost:4566 lambda create-function --function-name hello \ + --runtime python3.12 --handler handler.handler --zip-file fileb://function.zip \ + --role arn:aws:iam::000000000000:role/lambda +aws --endpoint-url http://localhost:4566 lambda wait function-active-v2 --function-name hello +aws --endpoint-url http://localhost:4566 --cli-read-timeout 600 lambda invoke --function-name hello \ + --cli-binary-format raw-in-base64-out --payload '{"name": "kubernetes"}' out.json +kubectl get pods --namespace floci -l app.kubernetes.io/managed-by=floci +``` + +The first invocation waits while the node pulls the runtime image (`public.ecr.aws/lambda/python:3.12` +is about 770 MB unpacked); warm pods are reused and removed after the idle timeout. + +What the chart sets up for it: + +- **RBAC, least privilege.** A Role in the Lambda namespace allows exactly what the executor calls: + `pods` `create`, `get`, `list`, `delete` and `pods/log` `get`. With TLS it adds `configmaps` + `create` and, for the one ConfigMap named `floci-lambda-ca`, `get` and `update`. The cleanup hook + below adds `delete` on that one ConfigMap, with or without TLS. The ServiceAccount token is mounted + only when the Kubernetes executor is on. With `rbac.create=false`, grant these yourself. +- **A separate Lambda namespace** (`floci.lambda.kubernetes.namespace`). The Role and RoleBinding are + created there. Lambda pods carry no security context of their own, so a namespace that enforces the + `restricted` Pod Security Standard rejects them; keep Floci in a `restricted` namespace and run + Lambda pods in one that allows `baseline`. +- **Network.** Lambda pods connect back to the Floci pod's IP on port 4566 and on the Runtime API + range 12000 to 12499. A NetworkPolicy around Floci must allow both from the Lambda namespace. +- **Uninstall cleanup.** Helm removes the ServiceAccount while Floci is still shutting down, so Floci + can no longer delete the Lambda pods that are warm at that moment. A `pre-delete` hook + (`cleanup.enabled`, on by default) deletes them, and the `floci-lambda-ca` ConfigMap, first. It + runs under Floci's ServiceAccount, bounds every API call and always exits 0; if its pod cannot + run at all (for example, the image cannot be pulled), `helm uninstall --no-hooks` skips it. + +### One release per Lambda namespace + +Floci treats every Lambda pod in its Lambda namespace as its own: the first time a Floci process +launches a Lambda pod, it deletes the ones it did not create (pods labelled +`app.kubernetes.io/managed-by=floci` and `floci.io/service=lambda`), and the uninstall hook deletes +all of them along with the `floci-lambda-ca` ConfigMap, whose name is fixed. Two releases that share +a Lambda namespace would delete each other's warm Lambda pods after every restart and on uninstall, +and with TLS each would overwrite the other's CA in that ConfigMap. Give every release a Lambda +namespace of its own. The default is the release namespace, so two releases in one namespace each +need their own `floci.lambda.kubernetes.namespace`: + +```bash +helm install ci-a ./floci/charts/floci -n ci --set floci.lambda.kubernetes.namespace=ci-a-lambda +helm install ci-b ./floci/charts/floci -n ci --set floci.lambda.kubernetes.namespace=ci-b-lambda +``` + +The Lambda namespaces must exist before the install, since the chart creates its Role in them. + +## Persistence + +```yaml +persistence: + enabled: true + size: 8Gi +``` + +`/app/data` then lives on a PersistentVolumeClaim and the storage mode becomes `persistent`, so S3, +DynamoDB, SSM and the other services keep their state across pod restarts. Choose another mode with +`floci.storage.mode` (see [Storage Modes](../configuration/storage.md)). The Deployment always uses +the `Recreate` strategy, so a `ReadWriteOnce` claim can move to the new pod. Without persistence +`/app/data` is an `emptyDir`. + +## Initialization hooks + +Scripts under `initHooks` are mounted into `/etc/floci/init/.d` +(see [Initialization Hooks](../configuration/initialization-hooks.md)). Scripts that call `aws` +need the `compat` image variant: + +```yaml +image: + variant: compat +initHooks: + ready: + 01-seed.sh: | + #!/bin/sh + set -eu + aws s3api head-bucket --bucket assets 2>/dev/null || aws s3 mb s3://assets + aws ssm put-parameter --name /app/mode --value test --type String --overwrite +``` + +The readiness probe passes only once `/_floci/init` reports the `ready` phase complete, so the +Service sends no traffic before the hooks have seeded their resources. A failing hook stops Floci. +With persistence, hooks run again on every restart, so keep them idempotent as above. + +## TLS + +`floci.tls.enabled=true` makes port 4566 serve HTTPS as well as HTTP, with Floci's self-signed +certificate. Its CA is at `http://:4566/_floci/ca.pem`. URLs in responses then start with +`https://`. Lambda pods receive the CA through the `floci-lambda-ca` ConfigMap; the +[Kubernetes executor limitations](../services/lambda.md#limitations) explain the certificate names. + +## Services that need Docker + +RDS, ElastiCache, OpenSearch, MSK, ECS, EKS and the other container-backed services start Docker +containers, and Kubernetes offers no Docker daemon. Without one they keep their control plane only +(Floci logs which services are affected at startup). If Floci can reach a Docker daemon, set +`FLOCI_DOCKER_DOCKER_HOST` in `floci.env` and publish the ports of the proxies Floci runs in its own +process, as `docker-compose.yml` maps them: + +```yaml +floci: + env: + FLOCI_DOCKER_DOCKER_HOST: tcp://docker.example.internal:2375 +service: + portRanges: + - name: elasticache + start: 6379 + end: 6399 + - name: rds + start: 7001 + end: 7099 +``` + +OpenSearch is not in that list: its data plane is published by the Docker daemon, not by Floci +(see [Ports Reference](../configuration/ports.md)). + +## OpenShift + +OpenShift assigns each namespace its own UID range, so drop the fixed IDs. Helm merges a map you pass +into the chart's defaults, so a key you leave out keeps its default; set the IDs to `null` instead: + +```yaml +podSecurityContext: + runAsUser: null + runAsGroup: null + fsGroup: null +``` + +The `helm test` pods and the uninstall cleanup hook use the same `podSecurityContext`, so this one +override covers them too. + +## Testing the chart + +The chart's checks run in the **Helm Chart** workflow (`.github/workflows/helm-chart.yml`) on every +change under `charts/`. Locally: + +```bash +helm lint charts/floci --strict +helm unittest charts/floci # helm-unittest plugin; -u refreshes the snapshots +ct lint --config .github/ct.yaml # also requires a version bump in Chart.yaml +ct install --config .github/ct.yaml --charts charts/floci # needs a cluster, for example kind +``` + +`ct install` installs the chart once per `charts/floci/ci/*-values.yaml` file and runs `helm test`. +The workflow also writes an SPDX SBOM of the deployed image with syft and a grype vulnerability +report, both kept as run artifacts. The report never fails the build: the image is a published +release, and its packages are fixed where the image is built. diff --git a/docs/services/lambda.md b/docs/services/lambda.md index ceb5501e0a..c2a99e6976 100644 --- a/docs/services/lambda.md +++ b/docs/services/lambda.md @@ -869,7 +869,9 @@ subjects: #### Running Floci in-cluster -A minimal Deployment (namespace `floci` assumed, RBAC from above bound to the +The Helm chart in `charts/floci` sets all of this up, with the RBAC above, a Lambda +namespace of your choice and `helm test` checks: see +[Kubernetes (Helm)](../getting-started/kubernetes.md). Without Helm, a minimal Deployment (namespace `floci` assumed, RBAC from above bound to the `floci` ServiceAccount): ```yaml diff --git a/mkdocs.yml b/mkdocs.yml index 2332e1079d..25164c54ff 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -76,6 +76,7 @@ nav: - Getting Started: - Quick Start: getting-started/quick-start.md - Installation: getting-started/installation.md + - Kubernetes (Helm): getting-started/kubernetes.md - AWS CLI & SDK Setup: getting-started/aws-setup.md - Terraform: getting-started/terraform.md - Migrate from LocalStack: getting-started/migrate-from-localstack.md