feat: trigger.enabled + job.run_id lifecycle control (operator v0.1.6, provider v0.1.4)
- TriggerSpec.Enabled bool (default=true): enabled=false масштабирует Deployment до 0
- FunctionJobSpec.RunID int64 (default=0): run_id=0 = skip, >0 = run
- API: PATCH /v1/namespaces/{ns}/triggers/{name} (UpdateTrigger)
- Provider: enabled attribute (Optional, Computed, in-place update)
- Provider: run_id attribute (Optional, Computed, default=0, RequiresReplace)
- operator image: naeel/sless-operator:v0.1.6
- provider: terra.k8c.ru/naeel/sless v0.1.4
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// 2026-03-07
|
||||
// 2026-03-08
|
||||
// client.go — HTTP-клиент для REST API sless оператора.
|
||||
// Намеренно изолирован от terraform-plugin-framework — при переносе в nubes
|
||||
// этот файл кладётся в internal/core/ без изменений.
|
||||
@@ -68,6 +68,14 @@ type TriggerRequest struct {
|
||||
Type string `json:"type"`
|
||||
FunctionRef string `json:"function"`
|
||||
Schedule string `json:"schedule,omitempty"`
|
||||
// Enabled: nil = не передавать (по умолчанию true)
|
||||
Enabled *bool `json:"enabled"`
|
||||
}
|
||||
|
||||
// TriggerUpdateRequest — тело PATCH /v1/namespaces/{ns}/triggers/{name}
|
||||
// Используем *bool чтобы различать nil (не передано) от false (явно выключен).
|
||||
type TriggerUpdateRequest struct {
|
||||
Enabled *bool `json:"enabled"`
|
||||
}
|
||||
|
||||
// TriggerResponse — ответ GET /v1/namespaces/{ns}/triggers/{name}
|
||||
@@ -77,6 +85,7 @@ type TriggerResponse struct {
|
||||
Type string `json:"type"`
|
||||
FunctionRef string `json:"function"`
|
||||
Schedule string `json:"schedule"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Active bool `json:"active"`
|
||||
URL string `json:"url"`
|
||||
Message string `json:"message"`
|
||||
@@ -291,6 +300,23 @@ func (c *Client) DeleteTrigger(ctx context.Context, ns, name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateTrigger — PATCH /v1/namespaces/{ns}/triggers/{name} → 200
|
||||
// Позволяет изменить enabled без пересоздания триггера.
|
||||
func (c *Client) UpdateTrigger(ctx context.Context, ns, name string, req TriggerUpdateRequest) (*TriggerResponse, error) {
|
||||
url := fmt.Sprintf("%s/v1/namespaces/%s/triggers/%s", c.endpoint, ns, name)
|
||||
resp, err := c.doJSON(ctx, http.MethodPatch, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return nil, fmt.Errorf("update trigger: status %d: %s", resp.StatusCode, body)
|
||||
}
|
||||
var tr TriggerResponse
|
||||
return &tr, json.NewDecoder(resp.Body).Decode(&tr)
|
||||
}
|
||||
|
||||
// --- Job CRUD ---
|
||||
|
||||
// JobRequest — тело POST /v1/namespaces/{ns}/jobs
|
||||
@@ -298,6 +324,8 @@ type JobRequest struct {
|
||||
Name string `json:"name"`
|
||||
FunctionRef string `json:"function"`
|
||||
EventJSON string `json:"event_json,omitempty"`
|
||||
// RunID: 0 = создать без запуска, >0 = запустить
|
||||
RunID int64 `json:"run_id"`
|
||||
}
|
||||
|
||||
// JobResponse — ответ GET /v1/namespaces/{ns}/jobs/{name}
|
||||
@@ -306,6 +334,7 @@ type JobResponse struct {
|
||||
Namespace string `json:"namespace"`
|
||||
FunctionRef string `json:"function"`
|
||||
EventJSON string `json:"event_json"`
|
||||
RunID int64 `json:"run_id"`
|
||||
Phase string `json:"phase"`
|
||||
JobName string `json:"job_name"`
|
||||
StartTime string `json:"start_time"`
|
||||
|
||||
Reference in New Issue
Block a user