Skip to content

Commit

Permalink
feat(manifest): override sidecar entrypoint and cmd (#2592)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
buddhike authored Jul 15, 2021
1 parent 1db6fd0 commit abece42
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 8 deletions.
13 changes: 13 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ func convertSidecar(s convertSidecarOpts) ([]*template.SidecarOpts, error) {
if err := validateSidecarDependsOn(*config, name, s); err != nil {
return nil, err
}

entrypoint, err := convertEntryPoint(config.EntryPoint)
if err != nil {
return nil, err
}

command, err := convertCommand(config.Command)
if err != nil {
return nil, err
}

mp := convertSidecarMountPoints(config.MountPoints)

sidecars = append(sidecars, &template.SidecarOpts{
Expand All @@ -86,6 +97,8 @@ func convertSidecar(s convertSidecarOpts) ([]*template.SidecarOpts, error) {
MountPoints: mp,
DockerLabels: config.DockerLabels,
DependsOn: config.DependsOn,
EntryPoint: entrypoint,
Command: command,
})
}
return sidecars, nil
Expand Down
94 changes: 86 additions & 8 deletions internal/pkg/deploy/cloudformation/stack/transformers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Test_convertSidecar(t *testing.T) {
inLabels map[string]string
inDependsOn map[string]string
inImg manifest.Image
inImageOverride manifest.ImageOverride
circDepContainers []string

wanted *template.SidecarOpts
Expand Down Expand Up @@ -162,19 +163,96 @@ func Test_convertSidecar(t *testing.T) {
},
},
},
"do not specify image override": {
wanted: &template.SidecarOpts{
Name: aws.String("foo"),
CredsParam: mockCredsParam,
Image: mockImage,
Secrets: mockMap,
Variables: mockMap,
Essential: aws.Bool(false),
EntryPoint: nil,
Command: nil,
},
},
"specify entrypoint as a string": {
inImageOverride: manifest.ImageOverride{
EntryPoint: &manifest.EntryPointOverride{String: aws.String("bin")},
},

wanted: &template.SidecarOpts{
Name: aws.String("foo"),
CredsParam: mockCredsParam,
Image: mockImage,
Secrets: mockMap,
Variables: mockMap,
Essential: aws.Bool(false),
EntryPoint: []string{"bin"},
Command: nil,
},
},
"specify entrypoint as a string slice": {
inImageOverride: manifest.ImageOverride{
EntryPoint: &manifest.EntryPointOverride{StringSlice: []string{"bin", "arg"}},
},

wanted: &template.SidecarOpts{
Name: aws.String("foo"),
CredsParam: mockCredsParam,
Image: mockImage,
Secrets: mockMap,
Variables: mockMap,
Essential: aws.Bool(false),
EntryPoint: []string{"bin", "arg"},
Command: nil,
},
},
"specify command as a string": {
inImageOverride: manifest.ImageOverride{
Command: &manifest.CommandOverride{String: aws.String("arg")},
},

wanted: &template.SidecarOpts{
Name: aws.String("foo"),
CredsParam: mockCredsParam,
Image: mockImage,
Secrets: mockMap,
Variables: mockMap,
Essential: aws.Bool(false),
EntryPoint: nil,
Command: []string{"arg"},
},
},
"specify command as a string slice": {
inImageOverride: manifest.ImageOverride{
Command: &manifest.CommandOverride{StringSlice: []string{"arg1", "arg2"}},
},

wanted: &template.SidecarOpts{
Name: aws.String("foo"),
CredsParam: mockCredsParam,
Image: mockImage,
Secrets: mockMap,
Variables: mockMap,
Essential: aws.Bool(false),
EntryPoint: nil,
Command: []string{"arg1", "arg2"},
},
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
sidecar := map[string]*manifest.SidecarConfig{
"foo": {
CredsParam: mockCredsParam,
Image: mockImage,
Secrets: mockMap,
Variables: mockMap,
Essential: aws.Bool(tc.inEssential),
Port: tc.inPort,
DockerLabels: tc.inLabels,
DependsOn: tc.inDependsOn,
CredsParam: mockCredsParam,
Image: mockImage,
Secrets: mockMap,
Variables: mockMap,
Essential: aws.Bool(tc.inEssential),
Port: tc.inPort,
DockerLabels: tc.inLabels,
DependsOn: tc.inDependsOn,
ImageOverride: tc.inImageOverride,
},
}
got, err := convertSidecar(convertSidecarOpts{
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/manifest/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ type SidecarConfig struct {
MountPoints []SidecarMountPoint `yaml:"mount_points"`
DockerLabels map[string]string `yaml:"labels"`
DependsOn map[string]string `yaml:"depends_on"`
ImageOverride `yaml:",inline"`
}

// TaskConfig represents the resource boundaries and environment variables for the containers in the task.
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/template/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type SidecarOpts struct {
MountPoints []*MountPoint
DockerLabels map[string]string
DependsOn map[string]string
EntryPoint []string
Command []string
}

// StorageOpts holds data structures for rendering Volumes and Mount Points
Expand Down
6 changes: 6 additions & 0 deletions site/content/docs/developing/sidecars.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ sidecars:

```

{% include 'sidecar-config.en.md' %}

<div class="separator"></div>

## Example

Below is an example of specifying the [nginx](https://www.nginx.com/) sidecar container in a load balanced web service manifest.

``` yaml
Expand Down
52 changes: 52 additions & 0 deletions site/content/docs/include/sidecar-config.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

<a id="port" href="#port" class="field">`port`</a> <span class="type">Integer</span>
Port of the container to expose (optional).

<a id="image" href="#image" class="field">`image`</a> <span class="type">String</span>
Image URL for the sidecar container (required).

<a id="credentialsParameter" href="#credentialsParameter" class="field">`credentialsParameter`</a> <span class="type">String</span>
ARN of the secret containing the private repository credentials (optional).

<a id="variables" href="#variables" class="field">`variables`</a> <span class="type">Map</span>
Environment variables for the sidecar container (optional)

<a id="secrets" href="#secrets" class="field">`secrets`</a> <span class="type">Map</span>
Secrets to expose to the sidecar container (optional)

<a id="mount-points" href="#mount-points" class="field">`mount_points`</a> <span class="type">Array of Maps</span>
Mount paths for EFS volumes specified at the service level (optional).

<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>
Source volume to mount in this sidecar (required).

<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>
The path inside the sidecar container at which to mount the volume (required).

<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>
Whether to allow the sidecar read-only access to the volume (default true).

<a id="labels" href="#labels" class="field">`labels`</a> <span class="type">Map</span>
Docker labels to apply to this container (optional).

<a id="depends_on" href="#depends_on" class="field">`depends_on`</a> <span class="type">Map</span>
Container dependencies to apply to this container (optional).

<a id="entrypoint" href="#entrypoint" class="field">`entrypoint`</a> <span class="type">String or Array of Strings</span>
Override the default entrypoint in the sidecar.
```yaml
# String version.
entrypoint: "/bin/entrypoint --p1 --p2"
# Alteratively, as an array of strings.
entrypoint: ["/bin/entrypoint", "--p1", "--p2"]
```
<a id="command" href="#command" class="field">`command`</a> <span class="type">String or Array of Strings</span>
Override the default command in the sidecar.

```yaml
# String version.
command: ps au
# Alteratively, as an array of strings.
command: ["ps", "au"]
```
1 change: 1 addition & 0 deletions templates/workloads/partials/cf/sidecars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Name: {{$sidecar.Name}}
Image: {{$sidecar.Image}}{{if $sidecar.Essential}}
Essential: {{$sidecar.Essential}}{{end}}{{if $sidecar.Port}}
{{include "image-overrides" . | indent 2}}
PortMappings:
- ContainerPort: {{$sidecar.Port}}{{if $sidecar.Protocol}}
Protocol: {{$sidecar.Protocol}}{{end}}{{end}}
Expand Down

0 comments on commit abece42

Please sign in to comment.