Skip to content

Latest commit

 

History

History

functions-runtime

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Keptn Lifecycle Controller - Function Runtime

Build

docker build -t keptnsandbox/klc-runtime:${VERSION} .

Usage

The Keptn function runtime uses Deno to execute Javascript/Typescript code. The Keptn Lifecycle Toolkit uses this runtime to run KeptnTask for pre- and post-checks. The Keptn Lifecycle Toolkit passes parameters of KeptnTasks and Context information to the runtime via the special environmental variable DATA. It also supports mounting Kubernetes secrets making them accessible via the SECURE_DATA env var. You can then read the data with the following snippet of code.

const data = Deno.env.get("DATA")!;
const secret = Deno.env.get("SECURE_DATA")!;
console.log(data);
console.log(secret);

KeptnTasks can be tested locally with the runtime using the following command. Replace ${VERSION} with the KLT version of your choice.

docker run -v $(pwd)/test.ts:/test.ts -e SCRIPT=/test.ts -e DATA='{ "url":"http://localhost:9090" }' -e SECURE_DATA='{ "token": "myToken"}' -it ghcr.io/keptn/functions-runtime:${VERSION}

Docker with function on webserver (function in this repo)

docker run \
  -e SCRIPT=https://raw.githubusercontent.com/keptn/lifecycle-toolkit/main/functions-runtime/samples/ts/hello-world.ts \
  -it \
  keptnsandbox/klc-runtime:${VERSION}

Docker with function and external data - scheduler

docker run \
  -e SCRIPT=https://raw.githubusercontent.com/keptn/lifecycle-toolkit/main/functions-runtime/samples/ts/scheduler.ts \
  -e DATA='{ "targetDate":"2025-04-16T06:55:31.820Z" }' \
  -it \
  keptnsandbox/klc-runtime:${VERSION}

Docker with function and external secure data - slack

docker run \
  -e SCRIPT=https://raw.githubusercontent.com/keptn/lifecycle-toolkit/main/functions-runtime/samples/ts/slack.ts \
  -e SECURE_DATA='{ "slack_hook":"hook/parts","text":"this is my test message" }' \
  -it \
  keptnsandbox/klc-runtime:${VERSION}

Docker with function and external data - prometheus

docker run \
  -e SCRIPT=https://raw.githubusercontent.com/keptn/lifecycle-toolkit/main/functions-runtime/samples/ts/prometheus.ts \
  -e DATA='{ "url":"http://localhost:9090", "metrics": "up{service=\"kubernetes\"}", "expected_value": "1" }' \
  -it \
  ghcr.keptn.sh/keptn/functions-runtime:${VERSION}