fix(api): DELETE несуществующего ресурса — 404 вместо 204 (function/service/trigger/job)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// Изменено: 2026-03-18 (добавлены created_at, last_built_at в functionResponse и fnToResponse)
|
||||
// Изменено: 2026-03-21 (fix: DeleteFunction возвращает 404 вместо 204 при отсутствующем объекте)
|
||||
// functions.go — CRUD handlers для Function CRD.
|
||||
// Принимает JSON, создаёт/обновляет/удаляет k8s ресурсы Function.
|
||||
// Namespace берётся из URL: /v1/namespaces/{namespace}/functions/{name}
|
||||
@@ -30,24 +31,24 @@ type functionRequest struct {
|
||||
|
||||
// functionResponse — ответ при чтении функции.
|
||||
type functionResponse struct {
|
||||
Name string `json:"name"`
|
||||
Namespace string `json:"namespace"`
|
||||
Runtime string `json:"runtime"`
|
||||
Entrypoint string `json:"entrypoint"`
|
||||
MemoryMB int32 `json:"memory_mb"`
|
||||
TimeoutSec int32 `json:"timeout_sec"`
|
||||
Env map[string]string `json:"env_vars"`
|
||||
S3Bucket string `json:"s3_bucket"`
|
||||
S3Key string `json:"s3_key"`
|
||||
Phase slessv1alpha1.FunctionPhase `json:"phase"`
|
||||
ImageRef string `json:"image_ref"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Namespace string `json:"namespace"`
|
||||
Runtime string `json:"runtime"`
|
||||
Entrypoint string `json:"entrypoint"`
|
||||
MemoryMB int32 `json:"memory_mb"`
|
||||
TimeoutSec int32 `json:"timeout_sec"`
|
||||
Env map[string]string `json:"env_vars"`
|
||||
S3Bucket string `json:"s3_bucket"`
|
||||
S3Key string `json:"s3_key"`
|
||||
Phase slessv1alpha1.FunctionPhase `json:"phase"`
|
||||
ImageRef string `json:"image_ref"`
|
||||
Message string `json:"message,omitempty"`
|
||||
// CreatedAt — время создания CRD объекта (metadata.creationTimestamp).
|
||||
// Пустое значение = "0001-01-01T00:00:00Z" сериализуется в "", опускаем через omitempty.
|
||||
CreatedAt string `json:"created_at,omitempty"`
|
||||
CreatedAt string `json:"created_at,omitempty"`
|
||||
// LastBuiltAt — время последней успешной сборки образа (status.lastBuiltAt).
|
||||
// nil если сборки ещё не было.
|
||||
LastBuiltAt string `json:"last_built_at,omitempty"`
|
||||
LastBuiltAt string `json:"last_built_at,omitempty"`
|
||||
}
|
||||
|
||||
// fnToResponse конвертирует CRD в ответ API.
|
||||
@@ -233,7 +234,7 @@ func (h *Handler) DeleteFunction(w http.ResponseWriter, r *http.Request) {
|
||||
fn := &slessv1alpha1.Function{}
|
||||
if err := h.K8s.Get(r.Context(), client.ObjectKey{Name: name, Namespace: ns}, fn); err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
writeJSON(w, http.StatusNotFound, errResp("function not found"))
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusInternalServerError, errResp(err.Error()))
|
||||
|
||||
Reference in New Issue
Block a user