-
Notifications
You must be signed in to change notification settings - Fork 35
/
helpers.go
61 lines (51 loc) · 1.39 KB
/
helpers.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
package application
import (
"context"
"fmt"
"strings"
"github.com/containerd/typeurl"
"github.com/ehazlett/stellar"
clusterapi "github.com/ehazlett/stellar/api/services/cluster/v1"
nodeapi "github.com/ehazlett/stellar/api/services/node/v1"
)
func (s *service) containerToService(ctx context.Context, c *clusterapi.Container) (*nodeapi.Service, error) {
labels := []string{}
for k, v := range c.Container.Labels {
labels = append(labels, k+"="+v)
}
svc := &nodeapi.Service{
Name: c.Container.ID,
Image: c.Container.Image,
Runtime: c.Container.Runtime,
Snapshotter: c.Container.Snapshotter,
Labels: labels,
Node: s.nodeName(),
}
// add stellar specific data
if ext, ok := c.Container.Extensions[stellar.StellarServiceExtension]; ok {
v, err := typeurl.UnmarshalAny(ext)
if err != nil {
return nil, err
}
s, ok := v.(*nodeapi.Service)
if ok {
svc.Endpoints = s.Endpoints
}
}
return svc, nil
}
func (s *service) getApplicationContainers(name string) ([]*clusterapi.Container, error) {
c, err := s.client(s.agent.Self().Address)
if err != nil {
return nil, err
}
defer c.Close()
containers, err := c.Cluster().Containers(fmt.Sprintf("labels.\"%s\"==\"%s\"", stellar.StellarApplicationLabel, name))
if err != nil {
return nil, err
}
return containers, nil
}
func getAppName(name string) string {
return strings.Split(name, ".")[0]
}