forked from liamjbennett/sous
-
Notifications
You must be signed in to change notification settings - Fork 0
/
targetmanifest.go
70 lines (63 loc) · 1.66 KB
/
targetmanifest.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
package graph
import (
sous "github.com/opentable/sous/lib"
"github.com/pkg/errors"
)
func newTargetManifestID(f *sous.ResolveFilter, discovered *SourceContextDiscovery) (TargetManifestID, error) {
c := discovered.GetContext()
if f == nil { // XXX I think this needs to be supplied anyway by consumers...
f = &sous.ResolveFilter{}
}
var repo, offset = c.PrimaryRemoteURL, c.OffsetDir
if f.Repo != "" {
repo = f.Repo
offset = ""
}
if f.Offset != "" {
if f.Repo == "" {
return TargetManifestID{}, errors.Errorf("-offset doesn't make sense without a -repo or workspace remote")
}
offset = f.Offset
}
if repo == "" {
return TargetManifestID{}, errors.Errorf("no repo specified, please use -repo or run sous inside a git repo with a configured remote")
}
return TargetManifestID{
Source: sous.SourceLocation{
Repo: repo,
Dir: offset,
},
Flavor: f.Flavor,
}, nil
}
func newTargetManifest(auto UserSelectedOTPLDeploySpecs, tmid TargetManifestID, s *sous.State) TargetManifest {
mid := sous.ManifestID(tmid)
m, ok := s.Manifests.Get(mid)
if ok {
return TargetManifest{m}
}
deploySpecs := auto.DeploySpecs
if len(deploySpecs) == 0 {
deploySpecs = defaultDeploySpecs(s.Defs.Clusters)
}
m = &sous.Manifest{
Deployments: deploySpecs,
}
m.SetID(mid)
fls := m.Validate()
sous.RepairAll(fls)
return TargetManifest{m}
}
func defaultDeploySpecs(clusters sous.Clusters) sous.DeploySpecs {
defaults := sous.DeploySpecs{}
for name := range clusters {
defaults[name] = sous.DeploySpec{
DeployConfig: sous.DeployConfig{
Resources: sous.Resources{},
Env: map[string]string{},
NumInstances: 1,
},
}
}
return defaults
}