Skip to content

Commit bd2c70f

Browse files
authored
chore: Adds DependsOn converters and logic (#2421)
Adds dependency logic and conversion functions. Addresses logic/conversions for #2175 . By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 28a1737 commit bd2c70f

File tree

8 files changed

+853
-20
lines changed

8 files changed

+853
-20
lines changed

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ github.com/gobuffalo/logger v1.0.3 h1:YaXOTHNPCvkqqA7w05A4v0k2tCdpr+sgFlgINbQ6gq
340340
github.com/gobuffalo/logger v1.0.3/go.mod h1:SoeejUwldiS7ZsyCBphOGURmWdwUFXs0J7TCjEhjKxM=
341341
github.com/gobuffalo/packd v1.0.0 h1:6ERZvJHfe24rfFmA9OaoKBdC7+c9sydrytMg8SdFGBM=
342342
github.com/gobuffalo/packd v1.0.0/go.mod h1:6VTc4htmJRFB7u1m/4LeMTWjFoYrUiBkU9Fdec9hrhI=
343+
github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg=
343344
github.com/gobuffalo/packr/v2 v2.8.1 h1:tkQpju6i3EtMXJ9uoF5GT6kB+LMTimDWD8Xvbz6zDVA=
344345
github.com/gobuffalo/packr/v2 v2.8.1/go.mod h1:c/PLlOuTU+p3SybaJATW3H6lX/iK7xEz5OeMf+NnJpg=
345346
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=

internal/pkg/deploy/cloudformation/stack/backend_svc.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,19 @@ func (s *BackendService) Template() (string, error) {
7777
if err != nil {
7878
return "", err
7979
}
80-
sidecars, err := convertSidecar(s.manifest.Sidecars)
80+
convSidecarOpts := convertSidecarOpts{
81+
sidecarConfig: s.manifest.Sidecars,
82+
imageConfig: &s.manifest.ImageConfig.Image,
83+
workloadName: aws.StringValue(s.manifest.Name),
84+
}
85+
sidecars, err := convertSidecar(convSidecarOpts)
8186
if err != nil {
8287
return "", fmt.Errorf("convert the sidecar configuration for service %s: %w", s.name, err)
8388
}
89+
dependencies, err := convertImageDependsOn(convSidecarOpts)
90+
if err != nil {
91+
return "", fmt.Errorf("convert the container dependency for service %s: %w", s.name, err)
92+
}
8493

8594
advancedCount, err := convertAdvancedCount(&s.manifest.Count.AdvancedCount)
8695
if err != nil {
@@ -128,6 +137,7 @@ func (s *BackendService) Template() (string, error) {
128137
Network: convertNetworkConfig(s.manifest.Network),
129138
EntryPoint: entrypoint,
130139
Command: command,
140+
DependsOn: dependencies,
131141
})
132142
if err != nil {
133143
return "", fmt.Errorf("parse backend service template: %w", err)

internal/pkg/deploy/cloudformation/stack/lb_web_svc.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,19 @@ func (s *LoadBalancedWebService) Template() (string, error) {
102102
if err != nil {
103103
return "", err
104104
}
105-
sidecars, err := convertSidecar(s.manifest.Sidecars)
105+
convSidecarOpts := convertSidecarOpts{
106+
sidecarConfig: s.manifest.Sidecars,
107+
imageConfig: &s.manifest.ImageConfig.Image,
108+
workloadName: aws.StringValue(s.manifest.Name),
109+
}
110+
sidecars, err := convertSidecar(convSidecarOpts)
106111
if err != nil {
107112
return "", fmt.Errorf("convert the sidecar configuration for service %s: %w", s.name, err)
108113
}
114+
dependencies, err := convertImageDependsOn(convSidecarOpts)
115+
if err != nil {
116+
return "", fmt.Errorf("convert the container dependency for service %s: %w", s.name, err)
117+
}
109118

110119
advancedCount, err := convertAdvancedCount(&s.manifest.Count.AdvancedCount)
111120
if err != nil {
@@ -164,6 +173,7 @@ func (s *LoadBalancedWebService) Template() (string, error) {
164173
Network: convertNetworkConfig(s.manifest.Network),
165174
EntryPoint: entrypoint,
166175
Command: command,
176+
DependsOn: dependencies,
167177
})
168178
if err != nil {
169179
return "", err

internal/pkg/deploy/cloudformation/stack/scheduled_job.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,19 @@ func (j *ScheduledJob) Template() (string, error) {
120120
if err != nil {
121121
return "", err
122122
}
123-
124-
sidecars, err := convertSidecar(j.manifest.Sidecars)
123+
convSidecarOpts := convertSidecarOpts{
124+
sidecarConfig: j.manifest.Sidecars,
125+
imageConfig: &j.manifest.ImageConfig,
126+
workloadName: aws.StringValue(j.manifest.Name),
127+
}
128+
sidecars, err := convertSidecar(convSidecarOpts)
125129
if err != nil {
126130
return "", fmt.Errorf("convert the sidecar configuration for job %s: %w", j.name, err)
127131
}
128-
132+
dependencies, err := convertImageDependsOn(convSidecarOpts)
133+
if err != nil {
134+
return "", fmt.Errorf("convert container dependency for job %s: %w", j.name, err)
135+
}
129136
schedule, err := j.awsSchedule()
130137
if err != nil {
131138
return "", fmt.Errorf("convert schedule for job %s: %w", j.name, err)
@@ -167,6 +174,7 @@ func (j *ScheduledJob) Template() (string, error) {
167174
Network: convertNetworkConfig(j.manifest.Network),
168175
EntryPoint: entrypoint,
169176
Command: command,
177+
DependsOn: dependencies,
170178

171179
EnvControllerLambda: envControllerLambda.String(),
172180
})

internal/pkg/deploy/cloudformation/stack/transformers.go

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,33 @@ var (
5050
errInvalidSpotConfig = errors.New(`"count.spot" and "count.range" cannot be specified together`)
5151
)
5252

53+
type convertSidecarOpts struct {
54+
sidecarConfig map[string]*manifest.SidecarConfig
55+
imageConfig *manifest.Image
56+
workloadName string
57+
}
58+
5359
// convertSidecar converts the manifest sidecar configuration into a format parsable by the templates pkg.
54-
func convertSidecar(s map[string]*manifest.SidecarConfig) ([]*template.SidecarOpts, error) {
55-
if s == nil {
60+
func convertSidecar(s convertSidecarOpts) ([]*template.SidecarOpts, error) {
61+
if s.sidecarConfig == nil {
5662
return nil, nil
5763
}
64+
if err := validateNoCircularDependencies(s); err != nil {
65+
return nil, err
66+
}
5867
var sidecars []*template.SidecarOpts
59-
for name, config := range s {
68+
for name, config := range s.sidecarConfig {
6069
port, protocol, err := parsePortMapping(config.Port)
6170
if err != nil {
6271
return nil, err
6372
}
6473
if err := validateSidecarMountPoints(config.MountPoints); err != nil {
6574
return nil, err
6675
}
76+
convertDependsOnStatus(&s)
77+
if err := validateSidecarDependsOn(*config, name, s); err != nil {
78+
return nil, err
79+
}
6780
mp := convertSidecarMountPoints(config.MountPoints)
6881

6982
sidecars = append(sidecars, &template.SidecarOpts{
@@ -77,11 +90,43 @@ func convertSidecar(s map[string]*manifest.SidecarConfig) ([]*template.SidecarOp
7790
Variables: config.Variables,
7891
MountPoints: mp,
7992
DockerLabels: config.DockerLabels,
93+
DependsOn: config.DependsOn,
8094
})
8195
}
8296
return sidecars, nil
8397
}
8498

99+
// convertDependsOnStatus converts image and sidecar depends on fields to have upper case statuses
100+
func convertDependsOnStatus(s *convertSidecarOpts) {
101+
if s.sidecarConfig != nil {
102+
for _, sidecar := range s.sidecarConfig {
103+
if sidecar.DependsOn == nil {
104+
continue
105+
}
106+
for name, status := range sidecar.DependsOn {
107+
sidecar.DependsOn[name] = strings.ToUpper(status)
108+
}
109+
}
110+
}
111+
if s.imageConfig != nil && s.imageConfig.DependsOn != nil {
112+
for name, status := range s.imageConfig.DependsOn {
113+
s.imageConfig.DependsOn[name] = strings.ToUpper(status)
114+
}
115+
}
116+
}
117+
118+
// convertDependsOn converts an Image DependsOn field to a template DependsOn version
119+
func convertImageDependsOn(s convertSidecarOpts) (map[string]string, error) {
120+
if s.imageConfig == nil || s.imageConfig.DependsOn == nil {
121+
return nil, nil
122+
}
123+
convertDependsOnStatus(&s)
124+
if err := validateImageDependsOn(s); err != nil {
125+
return nil, err
126+
}
127+
return s.imageConfig.DependsOn, nil
128+
}
129+
85130
// Valid sidecar portMapping example: 2000/udp, or 2000 (default to be tcp).
86131
func parsePortMapping(s *string) (port *string, protocol *string, err error) {
87132
if s == nil {

0 commit comments

Comments
 (0)