fix: stage0 quick fixes (operator v0.1.19)

- TriggerReconciler: RequeueAfter 15s когда Function не Ready
  (ранее зависал без повторного reconcile)
- FunctionJobReconciler: RequeueAfter 15s когда Function не Ready
- UpdateFunction: добавлена валидация runtime/entrypoint/memory_mb
  (ранее мог затереть spec нулями при частичном обновлении)
- CronJob: curlimages/curl:latest → curlimages/curl:8.5.0 (pin version)
- Config: удалён FunctionNamespacePrefix (мёртвое поле, нигде не использовалось)
- Invocations endpoint: возвращает 501 вместо пустого списка
  (SaveInvocation нигде не вызывается — честный ответ клиенту)
- Собран образ naeel/sless-operator:v0.1.19
This commit is contained in:
“Naeel”
2026-03-10 17:36:48 +04:00
parent 7d6f8d6079
commit 408f58a9e2
5 changed files with 32 additions and 72 deletions
+10
View File
@@ -160,6 +160,16 @@ func (h *Handler) UpdateFunction(w http.ResponseWriter, r *http.Request) {
return
}
// Валидация обязательных полей — PUT семантика, нельзя обнулять критичные поля
if req.Runtime == "" || req.Entrypoint == "" {
writeJSON(w, http.StatusBadRequest, errResp("runtime and entrypoint are required"))
return
}
if req.MemoryMB <= 0 || req.MemoryMB > 4096 {
writeJSON(w, http.StatusBadRequest, errResp("memory_mb must be between 1 and 4096"))
return
}
// Обновляем только изменяемые поля spec
fn.Spec.Runtime = req.Runtime
fn.Spec.Entrypoint = req.Entrypoint
+9 -54
View File
@@ -1,61 +1,16 @@
// Изменено: 2026-03-07
// invocations.go — GET-handlers для логов вызовов функций.
// Данные читаются из PostgreSQL (invocations таблица).
// POST /invoke остаётся для будущего прямого вызова (v2).
// Изменено: 2026-03-10
// invocations.go — stub для истории вызовов.
// Реальная запись вызовов не реализована — SaveInvocation нигде не вызывается.
// Endpoint возвращает 501 чтобы не вводить в заблуждение пустым списком.
// Реализовать когда появится реальный use case (биллинг, дебаг).
package handler
import (
"net/http"
"strconv"
)
// invocationResponse — ответ при чтении записи вызова.
type invocationResponse struct {
ID string `json:"id"`
FunctionName string `json:"function_name"`
Namespace string `json:"namespace"`
Status string `json:"status"`
DurationMs int32 `json:"duration_ms"`
HTTPStatus *int32 `json:"http_status,omitempty"` // nil для cron триггеров
Logs string `json:"logs,omitempty"`
TriggerType string `json:"trigger_type"`
CreatedAt string `json:"created_at"`
}
import "net/http"
// ListInvocations — GET /v1/namespaces/{namespace}/functions/{name}/invocations
// Возвращает последние limit вызовов (default 50, max 200).
// Пока не реализовано: SaveInvocation не вызывается нигде в коде.
// Возвращает 501 чтобы клиент знал что фича не реализована, а не просто нет данных.
func (h *Handler) ListInvocations(w http.ResponseWriter, r *http.Request) {
ns := namespace(r)
fnName := pathVar(r, "name")
limit := 50
if q := r.URL.Query().Get("limit"); q != "" {
if v, err := strconv.Atoi(q); err == nil && v > 0 && v <= 200 {
limit = v
}
}
rows, err := h.PG.ListInvocations(r.Context(), fnName, ns, limit)
if err != nil {
h.Log.Error("list invocations", "fn", fnName, "ns", ns, "err", err)
writeJSON(w, http.StatusInternalServerError, errResp(err.Error()))
return
}
result := make([]invocationResponse, 0, len(rows))
for _, row := range rows {
result = append(result, invocationResponse{
ID: row.ID,
FunctionName: row.FunctionName,
Namespace: row.Namespace,
Status: row.Status,
DurationMs: row.DurationMs,
HTTPStatus: row.HTTPStatus,
Logs: row.Logs,
TriggerType: row.TriggerType,
CreatedAt: row.CreatedAt.Format("2006-01-02T15:04:05Z"),
})
}
writeJSON(w, http.StatusOK, result)
writeJSON(w, http.StatusNotImplemented, errResp("invocation history not implemented yet"))
}