feat: add prebuild invalidation via last_invalidated_at timestamp (#20582)

Updates #17917
This commit is contained in:
Marcin Tojek
2025-11-20 17:12:25 +01:00
committed by GitHub
parent c2319e5b4e
commit d004710a74
27 changed files with 637 additions and 23 deletions
+31
View File
@@ -513,3 +513,34 @@ func (c *Client) StarterTemplates(ctx context.Context) ([]TemplateExample, error
var templateExamples []TemplateExample
return templateExamples, json.NewDecoder(res.Body).Decode(&templateExamples)
}
type InvalidatePresetsResponse struct {
Invalidated []InvalidatedPreset `json:"invalidated"`
}
type InvalidatedPreset struct {
TemplateName string `json:"template_name"`
TemplateVersionName string `json:"template_version_name"`
PresetName string `json:"preset_name"`
}
// InvalidateTemplatePresets invalidates all presets for the
// template's active version by setting last_invalidated_at timestamp.
// The reconciler will then mark these prebuilds as expired and create new ones.
func (c *Client) InvalidateTemplatePresets(ctx context.Context, template uuid.UUID) (InvalidatePresetsResponse, error) {
res, err := c.Request(ctx, http.MethodPost,
fmt.Sprintf("/api/v2/templates/%s/prebuilds/invalidate", template),
nil,
)
if err != nil {
return InvalidatePresetsResponse{}, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return InvalidatePresetsResponse{}, ReadBodyAsError(res)
}
var response InvalidatePresetsResponse
return response, json.NewDecoder(res.Body).Decode(&response)
}