Skip to content

Commit abece42

Browse files
authored
feat(manifest): override sidecar entrypoint and cmd (#2592)
This is done by following the same approach used to override default image settings. Closes #2501 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 1db6fd0 commit abece42

File tree

7 files changed

+161
-8
lines changed

7 files changed

+161
-8
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ func convertSidecar(s convertSidecarOpts) ([]*template.SidecarOpts, error) {
7272
if err := validateSidecarDependsOn(*config, name, s); err != nil {
7373
return nil, err
7474
}
75+
76+
entrypoint, err := convertEntryPoint(config.EntryPoint)
77+
if err != nil {
78+
return nil, err
79+
}
80+
81+
command, err := convertCommand(config.Command)
82+
if err != nil {
83+
return nil, err
84+
}
85+
7586
mp := convertSidecarMountPoints(config.MountPoints)
7687

7788
sidecars = append(sidecars, &template.SidecarOpts{
@@ -86,6 +97,8 @@ func convertSidecar(s convertSidecarOpts) ([]*template.SidecarOpts, error) {
8697
MountPoints: mp,
8798
DockerLabels: config.DockerLabels,
8899
DependsOn: config.DependsOn,
100+
EntryPoint: entrypoint,
101+
Command: command,
89102
})
90103
}
91104
return sidecars, nil

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

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func Test_convertSidecar(t *testing.T) {
2626
inLabels map[string]string
2727
inDependsOn map[string]string
2828
inImg manifest.Image
29+
inImageOverride manifest.ImageOverride
2930
circDepContainers []string
3031

3132
wanted *template.SidecarOpts
@@ -162,19 +163,96 @@ func Test_convertSidecar(t *testing.T) {
162163
},
163164
},
164165
},
166+
"do not specify image override": {
167+
wanted: &template.SidecarOpts{
168+
Name: aws.String("foo"),
169+
CredsParam: mockCredsParam,
170+
Image: mockImage,
171+
Secrets: mockMap,
172+
Variables: mockMap,
173+
Essential: aws.Bool(false),
174+
EntryPoint: nil,
175+
Command: nil,
176+
},
177+
},
178+
"specify entrypoint as a string": {
179+
inImageOverride: manifest.ImageOverride{
180+
EntryPoint: &manifest.EntryPointOverride{String: aws.String("bin")},
181+
},
182+
183+
wanted: &template.SidecarOpts{
184+
Name: aws.String("foo"),
185+
CredsParam: mockCredsParam,
186+
Image: mockImage,
187+
Secrets: mockMap,
188+
Variables: mockMap,
189+
Essential: aws.Bool(false),
190+
EntryPoint: []string{"bin"},
191+
Command: nil,
192+
},
193+
},
194+
"specify entrypoint as a string slice": {
195+
inImageOverride: manifest.ImageOverride{
196+
EntryPoint: &manifest.EntryPointOverride{StringSlice: []string{"bin", "arg"}},
197+
},
198+
199+
wanted: &template.SidecarOpts{
200+
Name: aws.String("foo"),
201+
CredsParam: mockCredsParam,
202+
Image: mockImage,
203+
Secrets: mockMap,
204+
Variables: mockMap,
205+
Essential: aws.Bool(false),
206+
EntryPoint: []string{"bin", "arg"},
207+
Command: nil,
208+
},
209+
},
210+
"specify command as a string": {
211+
inImageOverride: manifest.ImageOverride{
212+
Command: &manifest.CommandOverride{String: aws.String("arg")},
213+
},
214+
215+
wanted: &template.SidecarOpts{
216+
Name: aws.String("foo"),
217+
CredsParam: mockCredsParam,
218+
Image: mockImage,
219+
Secrets: mockMap,
220+
Variables: mockMap,
221+
Essential: aws.Bool(false),
222+
EntryPoint: nil,
223+
Command: []string{"arg"},
224+
},
225+
},
226+
"specify command as a string slice": {
227+
inImageOverride: manifest.ImageOverride{
228+
Command: &manifest.CommandOverride{StringSlice: []string{"arg1", "arg2"}},
229+
},
230+
231+
wanted: &template.SidecarOpts{
232+
Name: aws.String("foo"),
233+
CredsParam: mockCredsParam,
234+
Image: mockImage,
235+
Secrets: mockMap,
236+
Variables: mockMap,
237+
Essential: aws.Bool(false),
238+
EntryPoint: nil,
239+
Command: []string{"arg1", "arg2"},
240+
},
241+
},
165242
}
166243
for name, tc := range testCases {
167244
t.Run(name, func(t *testing.T) {
168245
sidecar := map[string]*manifest.SidecarConfig{
169246
"foo": {
170-
CredsParam: mockCredsParam,
171-
Image: mockImage,
172-
Secrets: mockMap,
173-
Variables: mockMap,
174-
Essential: aws.Bool(tc.inEssential),
175-
Port: tc.inPort,
176-
DockerLabels: tc.inLabels,
177-
DependsOn: tc.inDependsOn,
247+
CredsParam: mockCredsParam,
248+
Image: mockImage,
249+
Secrets: mockMap,
250+
Variables: mockMap,
251+
Essential: aws.Bool(tc.inEssential),
252+
Port: tc.inPort,
253+
DockerLabels: tc.inLabels,
254+
DependsOn: tc.inDependsOn,
255+
ImageOverride: tc.inImageOverride,
178256
},
179257
}
180258
got, err := convertSidecar(convertSidecarOpts{

internal/pkg/manifest/workload.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ type SidecarConfig struct {
438438
MountPoints []SidecarMountPoint `yaml:"mount_points"`
439439
DockerLabels map[string]string `yaml:"labels"`
440440
DependsOn map[string]string `yaml:"depends_on"`
441+
ImageOverride `yaml:",inline"`
441442
}
442443

443444
// TaskConfig represents the resource boundaries and environment variables for the containers in the task.

internal/pkg/template/workload.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ type SidecarOpts struct {
9191
MountPoints []*MountPoint
9292
DockerLabels map[string]string
9393
DependsOn map[string]string
94+
EntryPoint []string
95+
Command []string
9496
}
9597

9698
// StorageOpts holds data structures for rendering Volumes and Mount Points

site/content/docs/developing/sidecars.en.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ sidecars:
4444

4545
```
4646

47+
{% include 'sidecar-config.en.md' %}
48+
49+
<div class="separator"></div>
50+
51+
## Example
52+
4753
Below is an example of specifying the [nginx](https://www.nginx.com/) sidecar container in a load balanced web service manifest.
4854

4955
``` yaml
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
<a id="port" href="#port" class="field">`port`</a> <span class="type">Integer</span>
3+
Port of the container to expose (optional).
4+
5+
<a id="image" href="#image" class="field">`image`</a> <span class="type">String</span>
6+
Image URL for the sidecar container (required).
7+
8+
<a id="credentialsParameter" href="#credentialsParameter" class="field">`credentialsParameter`</a> <span class="type">String</span>
9+
ARN of the secret containing the private repository credentials (optional).
10+
11+
<a id="variables" href="#variables" class="field">`variables`</a> <span class="type">Map</span>
12+
Environment variables for the sidecar container (optional)
13+
14+
<a id="secrets" href="#secrets" class="field">`secrets`</a> <span class="type">Map</span>
15+
Secrets to expose to the sidecar container (optional)
16+
17+
<a id="mount-points" href="#mount-points" class="field">`mount_points`</a> <span class="type">Array of Maps</span>
18+
Mount paths for EFS volumes specified at the service level (optional).
19+
20+
<span class="parent-field">mount_points.</span><a id="mount-points-source-volume" href="#mount-points-source-volume" class="field">`source_volume`</a> <span class="type">String</span>
21+
Source volume to mount in this sidecar (required).
22+
23+
<span class="parent-field">mount_points.</span><a id="mount-points-path" href="#mount-points-path" class="field">`path`</a> <span class="type">String</span>
24+
The path inside the sidecar container at which to mount the volume (required).
25+
26+
<span class="parent-field">mount_points.</span><a id="mount-points-read-only" href="#mount-points-read-only" class="field">`read_only`</a> <span class="type">Boolean</span>
27+
Whether to allow the sidecar read-only access to the volume (default true).
28+
29+
<a id="labels" href="#labels" class="field">`labels`</a> <span class="type">Map</span>
30+
Docker labels to apply to this container (optional).
31+
32+
<a id="depends_on" href="#depends_on" class="field">`depends_on`</a> <span class="type">Map</span>
33+
Container dependencies to apply to this container (optional).
34+
35+
<a id="entrypoint" href="#entrypoint" class="field">`entrypoint`</a> <span class="type">String or Array of Strings</span>
36+
Override the default entrypoint in the sidecar.
37+
```yaml
38+
# String version.
39+
entrypoint: "/bin/entrypoint --p1 --p2"
40+
# Alteratively, as an array of strings.
41+
entrypoint: ["/bin/entrypoint", "--p1", "--p2"]
42+
```
43+
44+
<a id="command" href="#command" class="field">`command`</a> <span class="type">String or Array of Strings</span>
45+
Override the default command in the sidecar.
46+
47+
```yaml
48+
# String version.
49+
command: ps au
50+
# Alteratively, as an array of strings.
51+
command: ["ps", "au"]
52+
```

templates/workloads/partials/cf/sidecars.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Name: {{$sidecar.Name}}
1919
Image: {{$sidecar.Image}}{{if $sidecar.Essential}}
2020
Essential: {{$sidecar.Essential}}{{end}}{{if $sidecar.Port}}
21+
{{include "image-overrides" . | indent 2}}
2122
PortMappings:
2223
- ContainerPort: {{$sidecar.Port}}{{if $sidecar.Protocol}}
2324
Protocol: {{$sidecar.Protocol}}{{end}}{{end}}

0 commit comments

Comments
 (0)