-
Notifications
You must be signed in to change notification settings - Fork 179
/
resource.go
73 lines (57 loc) · 1.57 KB
/
resource.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
package local
import (
"fmt"
"github.com/convox/rack/pkg/manifest"
"github.com/convox/rack/pkg/structs"
am "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (p *Provider) ResourceGet(app, name string) (*structs.Resource, error) {
d, err := p.Cluster.AppsV1().Deployments(p.AppNamespace(app)).Get(fmt.Sprintf("resource-%s", name), am.GetOptions{})
if err != nil {
return nil, err
}
cm, err := p.Cluster.CoreV1().ConfigMaps(p.AppNamespace(app)).Get(fmt.Sprintf("resource-%s", name), am.GetOptions{})
if err != nil {
return nil, err
}
status := "running"
if d.Status.ReadyReplicas < 1 {
status = "pending"
}
r := &structs.Resource{
Name: name,
Status: status,
Type: d.ObjectMeta.Labels["kind"],
Url: cm.Data["URL"],
}
return r, nil
}
func (p *Provider) ResourceList(app string) (structs.Resources, error) {
lopts := am.ListOptions{
LabelSelector: fmt.Sprintf("app=%s,type=resource", app),
}
ds, err := p.Cluster.AppsV1().Deployments(p.AppNamespace(app)).List(lopts)
if err != nil {
return nil, err
}
rs := structs.Resources{}
for _, d := range ds.Items {
r, err := p.ResourceGet(app, d.ObjectMeta.Labels["resource"])
if err != nil {
return nil, err
}
rs = append(rs, *r)
}
return rs, nil
}
func (p *Provider) ResourceRender(app string, r manifest.Resource) ([]byte, error) {
params := map[string]interface{}{
"App": app,
"Namespace": p.AppNamespace(app),
"Name": r.Name,
"Parameters": r.Options,
"Password": "foo",
"Rack": p.Rack,
}
return p.RenderTemplate(fmt.Sprintf("resource/%s", r.Type), params)
}