v1.3.49: edit modal — remove mode toggle, show archive name, timeout-only save; add PUT /functions/:name/timeout

This commit is contained in:
“Naeel”
2026-05-04 07:03:43 +04:00
parent 6ac22d5f55
commit f97fd8a744
4 changed files with 61 additions and 7 deletions
+45
View File
@@ -310,6 +310,12 @@ func (s *Server) handleFunctionsAction(w http.ResponseWriter, r *http.Request) {
return
}
// /functions/:name/timeout — обновление только таймаута (без замены архива/кода)
if len(parts) == 2 && parts[1] == "timeout" && r.Method == http.MethodPut {
s.handleUpdateFunctionTimeout(w, r, name)
return
}
// /functions/:name/archive — обновление через zip-архив
if len(parts) == 2 && parts[1] == "archive" && r.Method == http.MethodPut {
s.handleUpdateFunctionArchive(w, r, name)
@@ -760,6 +766,45 @@ func (s *Server) handleUpdateFunctionCode(w http.ResponseWriter, r *http.Request
})
}
// handleUpdateFunctionTimeout обновляет только spec.functionTimeout функции (без замены кода/архива).
func (s *Server) handleUpdateFunctionTimeout(w http.ResponseWriter, r *http.Request, name string) {
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
defer cancel()
ns := s.userNS(r)
var req struct {
Timeout int64 `json:"timeout"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeJSONError(w, http.StatusBadRequest, fmt.Sprintf("decode request: %v", err))
return
}
timeout := normalizeFunctionTimeout(req.Timeout)
fn, err := s.dyn.Resource(fission.FunctionGVR).Namespace(ns).Get(ctx, name, metav1.GetOptions{})
if err != nil {
writeJSONError(w, http.StatusBadGateway, fmt.Sprintf("get function %q: %v", name, err))
return
}
if err := unstructured.SetNestedField(fn.Object, timeout, "spec", "functionTimeout"); err != nil {
writeJSONError(w, http.StatusInternalServerError, fmt.Sprintf("set timeout: %v", err))
return
}
now := time.Now().UTC().Format(time.RFC3339)
ann := fn.GetAnnotations()
if ann == nil {
ann = map[string]string{}
}
ann[functionUpdatedAtAnnotation] = now
fn.SetAnnotations(ann)
if _, err := s.dyn.Resource(fission.FunctionGVR).Namespace(ns).Update(ctx, fn, metav1.UpdateOptions{}); err != nil {
writeJSONError(w, http.StatusBadGateway, fmt.Sprintf("update function %q: %v", name, err))
return
}
writeAnyJSON(w, http.StatusOK, map[string]any{"updated": true, "timeout": timeout})
}
// handleInvokeFunction вызывает функцию через Fission router.
// Определяет реальный URL из HTTPTrigger, выбирает метод (POST/GET).
func (s *Server) handleInvokeFunction(w http.ResponseWriter, r *http.Request, name string) {