forked from rancher/rio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps_services.go
80 lines (71 loc) · 1.75 KB
/
ps_services.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package ps
import (
"github.com/rancher/rio/cli/pkg/clicontext"
"github.com/rancher/rio/cli/pkg/tables"
"github.com/rancher/rio/cli/pkg/types"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/services"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
type ServiceData struct {
ID string
Created string
Service *riov1.Service
Endpoint string
External string
}
func (p *Ps) apps(ctx *clicontext.CLIContext) error {
var appDataList []runtime.Object
appDatas := map[string]tables.AppData{}
appObjs, err := ctx.List(types.AppType)
if err != nil {
return err
}
for _, v := range appObjs {
app := v.(*riov1.App)
appDatas[app.Namespace+"/"+app.Name] = tables.AppData{
ObjectMeta: app.ObjectMeta,
App: app,
Revisions: map[string]*riov1.Service{},
}
}
svcObjs, err := ctx.List(types.ServiceType)
if err != nil {
return err
}
for _, v := range svcObjs {
svc := v.(*riov1.Service)
appName, version := services.AppAndVersion(svc)
key := svc.Namespace + "/" + appName
app, ok := appDatas[key]
if !ok {
app = tables.AppData{
App: riov1.NewApp(svc.Namespace, appName, riov1.App{
ObjectMeta: v1.ObjectMeta{
CreationTimestamp: svc.CreationTimestamp,
},
Spec: riov1.AppSpec{
Revisions: []riov1.Revision{
{
Scale: svc.Spec.Scale,
Version: version,
},
},
},
}),
Revisions: map[string]*riov1.Service{},
}
appDatas[key] = app
}
app.Revisions[version] = svc
}
for _, v := range appDatas {
copy := v
copy.Namespace = v.App.Namespace
copy.Name = v.App.Name
appDataList = append(appDataList, ©)
}
writer := tables.NewApp(ctx)
return writer.Write(appDataList)
}