feat: go1.23 runtime support

- runtimes/go1.23/server.go: HTTP-wrapper + job-runner (SLESS_MODE=job)
- runtimes/go1.23/go.mod: module sless/fn (изолирует от корневого go.mod)
- runtimes/go1.23/Dockerfile: multi-stage build (golang:1.23-alpine → alpine:3.20)
- internal/builder/context.go: go1.23 в runtimeBaseImage + generateDockerfile
- controllers/functionjob_controller.go: go1.23 runner (nil cmd + SLESS_MODE=job env)
- api/v1alpha1/function_types.go: enum go1.21 → go1.23
- config/crd/bases/...: CRD обновлён
- terraform/provider: OneOf обновлён
- examples/hello-go: HTTP + job примеры на go1.23
- deployments/k8s/operator.yaml: v0.1.25
This commit is contained in:
“Naeel”
2026-03-11 15:40:47 +04:00
parent babd8e6109
commit a709b38f6b
14 changed files with 290 additions and 24 deletions
+21
View File
@@ -0,0 +1,21 @@
// Создано: 2026-03-11
// handler.go — пример Go serverless функции.
// Пакет должен называться handler, функция — Handle.
// event содержит тело POST запроса (распарсенный JSON) или метаданные GET (_path, _method, _query).
package handler
import "fmt"
// Handle — точка входа функции. Принимает event как map, возвращает любой тип (сериализуется в JSON).
func Handle(event map[string]interface{}) interface{} {
name, ok := event["name"].(string)
if !ok || name == "" {
name = "world"
}
return map[string]interface{}{
"message": fmt.Sprintf("Hello, %s! (Go 1.23)", name),
"runtime": "go1.23",
"event": event,
}
}
+23
View File
@@ -0,0 +1,23 @@
# 2026-03-11
# http.tf — HTTP-функция на Go: принимает запрос, возвращает приветствие.
resource "sless_function" "hello_go_http" {
name = "hello-go-http"
runtime = "go1.23"
entrypoint = "handler.Handle"
memory_mb = 128
timeout_sec = 60
source_dir = "${path.module}/code"
}
resource "sless_trigger" "hello_go_http" {
name = "hello-go-http-trigger"
type = "http"
function = sless_function.hello_go_http.name
enabled = true
}
output "trigger_url" {
value = sless_trigger.hello_go_http.url
}
+28
View File
@@ -0,0 +1,28 @@
# 2026-03-11
# job.tf — одноразовый запуск Go функции с event payload.
resource "sless_function" "hello_go_job" {
name = "hello-go-job"
runtime = "go1.23"
entrypoint = "handler.Handle"
memory_mb = 128
timeout_sec = 60
source_dir = "${path.module}/code"
}
resource "sless_job" "hello_go_run" {
name = "hello-go-run"
function = sless_function.hello_go_job.name
event_json = jsonencode({ name = "Go" })
wait_timeout_sec = 300
run_id = 1
}
output "job_phase" {
value = sless_job.hello_go_run.phase
}
output "job_message" {
value = sless_job.hello_go_run.message
}
+17
View File
@@ -0,0 +1,17 @@
# 2026-03-11
# main.tf — провайдеры для hello-go примера.
terraform {
required_providers {
sless = {
source = "terra.k8c.ru/naeel/sless"
version = "~> 0.1.13"
}
}
}
provider "sless" {
endpoint = "https://sless-api.kube5s.ru"
token = var.token
nubes_endpoint = "https://deck-api.ngcloud.ru/api/v1"
}
+10
View File
@@ -0,0 +1,10 @@
# 2026-03-11
# variables.tf — входные переменные для hello-node примера.
# JWT токен облака (nubes). Передаётся через terraform.tfvars (gitignored).
# Из токена провайдер вычисляет namespace: sless-{sha256[:8]}
variable "token" {
description = "JWT токен облака для аутентификации в sless API"
type = string
sensitive = true
}