forked from rancher/rancher-compose-executor
/
sidekick.go
61 lines (47 loc) · 1.29 KB
/
sidekick.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 rancher
import (
"golang.org/x/net/context"
"github.com/rancher/rancher-compose-executor/config"
"github.com/rancher/rancher-compose-executor/project"
)
type Sidekick struct {
project.EmptyService
name string
serviceConfig *config.ServiceConfig
context *Context
}
func NewSidekick(name string, serviceConfig *config.ServiceConfig, context *Context) *Sidekick {
return &Sidekick{
name: name,
serviceConfig: serviceConfig,
context: context,
}
}
func (s *Sidekick) Name() string {
return s.name
}
func (s *Sidekick) primaries() []string {
return s.context.SidekickInfo.sidekickToPrimaries[s.name]
}
func (s *Sidekick) Config() *config.ServiceConfig {
links := []string{}
for _, primary := range s.primaries() {
links = append(links, primary)
}
config := *s.serviceConfig
config.Links = links
config.VolumesFrom = []string{}
return &config
}
func (s *Sidekick) DependentServices() []project.ServiceRelationship {
dependentServices := project.DefaultDependentServices(s.context.Project, s)
for i, dependentService := range dependentServices {
if dependentService.Type == project.RelTypeLink {
dependentServices[i].Optional = true
}
}
return dependentServices
}
func (s *Sidekick) Log(ctx context.Context, follow bool) error {
return nil
}