- FunctionJobReconciler: added KubeClient field (kubernetes.Interface) - getJobPodOutput(): reads pod logs via typed client after job succeeds - main.go: inject kubernetes.NewForConfigOrDie into FunctionJobReconciler - rbac.yaml: add pods/pods/log get/list/watch permissions - examples/simple-python/: job->function chain demo (Python) - examples/simple-node/: job->function chain demo (Node.js) sless_job.X.message now contains the return value of the function
41 lines
1.6 KiB
HCL
41 lines
1.6 KiB
HCL
# Создано: 2026-03-09
|
||
# time-display.tf — постоянная HTTP-функция, получающая данные от джоба.
|
||
# JOB_TIME берётся из sless_job.run_getter.message (stdout джоба) —
|
||
# это JSON строка {"time": "..."}, terraform передаёт её в env целиком.
|
||
# Функция парсит её через os.environ, а не через event — демонстрирует
|
||
# паттерн "данные вычислены один раз при деплое, используются на каждый запрос".
|
||
|
||
# Упаковываем код функции в zip
|
||
data "archive_file" "time_display_zip" {
|
||
type = "zip"
|
||
source_dir = "${path.module}/code/time_display"
|
||
output_path = "${path.module}/dist/time_display.zip"
|
||
}
|
||
|
||
# HTTP-функция: постоянный Deployment, читает JOB_TIME из env
|
||
resource "sless_function" "time_display" {
|
||
namespace = "default"
|
||
name = "simple-py-time-display"
|
||
runtime = "python3.11"
|
||
entrypoint = "time_display.show_time"
|
||
memory_mb = 64
|
||
|
||
# Значение вычислено джобом при apply и зафиксировано в state
|
||
env_vars = {
|
||
JOB_TIME = sless_job.run_getter.message
|
||
}
|
||
|
||
code_path = data.archive_file.time_display_zip.output_path
|
||
code_hash = filesha256("${path.module}/code/time_display/time_display.py")
|
||
|
||
depends_on = [sless_job.run_getter]
|
||
}
|
||
|
||
# HTTP-триггер — публикует функцию по URL
|
||
resource "sless_trigger" "display_http" {
|
||
namespace = "default"
|
||
name = "simple-py-display-http"
|
||
type = "http"
|
||
function = sless_function.time_display.name
|
||
}
|