upload.go:
- Update → Patch (MergeFrom) to avoid resourceVersion conflict when operator
modifies Function between Get() and Update()
terraform provider v0.1.1:
- trigger_resource.go: trToModel returns StringNull() for empty schedule
(fixes 'provider produced inconsistent result' for http triggers)
- main.go: bump version to 0.1.1
examples/pg-query:
- handler.py: fix column name started_at → created_at (matches migrations/001)
- main.tf: pin provider to ~> 0.1.1
.gitignore: add terraform state, lock, .terraform/, handler.zip
doc/errors/log.md: documented all 5 errors from this session:
- resourceVersion conflict → use Patch
- terraform inconsistent result for schedule → StringNull
- terraform import not implemented → delete+recreate workaround
- wrong column name → check migrations before writing handlers
- Deployment not restarting after image rebuild → rollout restart / TODO: restartedAt annotation
doc/progress.md: terraform apply e2e ✅
65 lines
1.9 KiB
Terraform
65 lines
1.9 KiB
Terraform
# 2026-03-07
|
|
# main.tf — e2e тест: создать serverless функцию, которая читает из PostgreSQL.
|
|
#
|
|
# Использование:
|
|
# 1. Убедиться что оператор запущен локально: source hack/local.env && go run main.go
|
|
# 2. zip handler.py + requirements.txt:
|
|
# zip handler.zip handler.py requirements.txt
|
|
# 3. terraform init && terraform apply
|
|
# 4. После apply (ждёт ~2 мин пока kaniko соберёт образ):
|
|
# curl -s -X POST <url_из_trigger> -d '{}'
|
|
#
|
|
# Функция подключается к postgres.sless.svc.cluster.local:5432 изнутри кластера.
|
|
# PG_DSN задаётся как env_var ресурса sless_function.
|
|
|
|
terraform {
|
|
required_providers {
|
|
sless = {
|
|
source = "terra.k8c.ru/naeel/sless"
|
|
version = "~> 0.1.1"
|
|
}
|
|
}
|
|
}
|
|
|
|
provider "sless" {
|
|
endpoint = "http://localhost:9090"
|
|
token = "dev-token-change-me"
|
|
}
|
|
|
|
resource "sless_function" "pg_query" {
|
|
namespace = "default"
|
|
name = "pg-query"
|
|
runtime = "python3.11"
|
|
entrypoint = "handler.handle"
|
|
memory_mb = 128
|
|
timeout_sec = 30
|
|
|
|
# DSN для подключения к postgres внутри кластера
|
|
# Хост: postgres.sless.svc.cluster.local (Service в namespace sless)
|
|
env_vars = {
|
|
PG_DSN = "postgres://sless:sless-pg-password@postgres.sless.svc.cluster.local:5432/sless?sslmode=disable"
|
|
}
|
|
|
|
code_path = "${path.module}/handler.zip"
|
|
code_hash = filemd5("${path.module}/handler.zip")
|
|
}
|
|
|
|
resource "sless_trigger" "pg_query_http" {
|
|
namespace = "default"
|
|
name = "pg-query-http"
|
|
type = "http"
|
|
function = sless_function.pg_query.name
|
|
}
|
|
|
|
output "function_phase" {
|
|
value = sless_function.pg_query.phase
|
|
}
|
|
|
|
output "function_image" {
|
|
value = sless_function.pg_query.image_ref
|
|
}
|
|
|
|
output "trigger_url" {
|
|
value = sless_trigger.pg_query_http.url
|
|
}
|