Skip to content

Commit c945498

Browse files
committed
Add /models/prune
Uses docker/model-distribution#78. Signed-off-by: Dorin Geman <[email protected]>
1 parent 47a0fae commit c945498

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23.7
55
require (
66
github.com/containerd/containerd/v2 v2.0.4
77
github.com/containerd/platforms v1.0.0-rc.1
8-
github.com/docker/model-distribution v0.0.0-20250512190053-b3792c042d57
8+
github.com/docker/model-distribution v0.0.0-20250521123835-b72b1c87354a
99
github.com/jaypipes/ghw v0.16.0
1010
github.com/opencontainers/go-digest v1.0.0
1111
github.com/opencontainers/image-spec v1.1.1

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZ
3939
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
4040
github.com/docker/model-distribution v0.0.0-20250512190053-b3792c042d57 h1:ZqfKknb+0/uJid8XLFwSl/osjE+WuS6o6I3dh3ZqO4U=
4141
github.com/docker/model-distribution v0.0.0-20250512190053-b3792c042d57/go.mod h1:dThpO9JoG5Px3i+rTluAeZcqLGw8C0qepuEL4gL2o/c=
42+
github.com/docker/model-distribution v0.0.0-20250521121637-af0fc7f16ad1 h1:akgUvCRqic2fLyq5zhWF1I6xunWXHwKaQBZYRStpqf0=
43+
github.com/docker/model-distribution v0.0.0-20250521121637-af0fc7f16ad1/go.mod h1:dThpO9JoG5Px3i+rTluAeZcqLGw8C0qepuEL4gL2o/c=
44+
github.com/docker/model-distribution v0.0.0-20250521123835-b72b1c87354a h1:VMwswLhzJVPhovYLlYEyzVYMjEqWDewcyKoKA8q89PY=
45+
github.com/docker/model-distribution v0.0.0-20250521123835-b72b1c87354a/go.mod h1:dThpO9JoG5Px3i+rTluAeZcqLGw8C0qepuEL4gL2o/c=
4246
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
4347
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
4448
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=

pkg/inference/models/manager.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (m *Manager) routeHandlers() map[string]http.HandlerFunc {
9898
"GET " + inference.ModelsPrefix + "/{name...}": m.handleGetModel,
9999
"DELETE " + inference.ModelsPrefix + "/{name...}": m.handleDeleteModel,
100100
"POST " + inference.ModelsPrefix + "/{nameAndAction...}": m.handleModelAction,
101+
"DELETE " + inference.ModelsPrefix + "/prune": m.handlePrune,
101102
"GET " + inference.InferencePrefix + "/{backend}/v1/models": m.handleOpenAIGetModels,
102103
"GET " + inference.InferencePrefix + "/{backend}/v1/models/{name...}": m.handleOpenAIGetModel,
103104
"GET " + inference.InferencePrefix + "/v1/models": m.handleOpenAIGetModels,
@@ -400,6 +401,20 @@ func (m *Manager) handlePushModel(w http.ResponseWriter, r *http.Request, model
400401
}
401402
}
402403

404+
// handlePrune handles DELETE <inference-prefix>/models/prune requests.
405+
func (m *Manager) handlePrune(w http.ResponseWriter, _ *http.Request) {
406+
if m.distributionClient == nil {
407+
http.Error(w, "model distribution service unavailable", http.StatusServiceUnavailable)
408+
return
409+
}
410+
411+
if err := m.distributionClient.ResetStore(); err != nil {
412+
m.log.Warnf("Failed to prune models: %v", err)
413+
http.Error(w, err.Error(), http.StatusInternalServerError)
414+
return
415+
}
416+
}
417+
403418
// GetDiskUsage returns the disk usage of the model store.
404419
func (m *Manager) GetDiskUsage() (float64, error, int) {
405420
if m.distributionClient == nil {

0 commit comments

Comments
 (0)