/
list.go
49 lines (42 loc) · 1.1 KB
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package runtime
import (
"context"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/tensorchord/openmodelz/agent/api/types"
)
func (r *Runtime) InferenceList(ns string) ([]types.InferenceDeployment, error) {
r.mutex.Lock()
res := r.cache
r.mutex.Unlock()
ctrs, err := r.cli.ContainerList(context.TODO(), dockertypes.ContainerListOptions{
Filters: filters.NewArgs(filters.Arg("label", labelVendor+"="+valueVendor)),
})
if err != nil {
return nil, err
}
for _, ctr := range ctrs {
inf := types.InferenceDeployment{
Spec: types.InferenceDeploymentSpec{
Name: ctr.Labels[labelName],
Image: ctr.Image,
Namespace: "default",
},
Status: types.InferenceDeploymentStatus{},
}
if ctr.State == "running" {
inf.Status.Phase = types.PhaseReady
inf.Status.AvailableReplicas = 1
inf.Status.Replicas = 1
} else {
inf.Status.Phase = types.PhaseNotReady
inf.Status.Replicas = 1
}
res[inf.Spec.Name] = inf
}
l := []types.InferenceDeployment{}
for _, inf := range res {
l = append(l, inf)
}
return l, nil
}