Skip to content

Commit d99047d

Browse files
authored
fix: sidecar should not set port mapping if unspecified (#2565)
<!-- Provide summary of changes --> fixes https://twitter.com/tajima_taso/status/1411631066994024449 <!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" --> 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 558e882 commit d99047d

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ const (
2828
defaultWritePermission = false
2929
)
3030

31-
// Default value for Sidecar port.
32-
const (
33-
defaultSidecarPort = "80"
34-
)
35-
3631
// Min and Max values for task ephemeral storage in GiB.
3732
const (
3833
ephemeralMinValueGiB = 21
@@ -130,8 +125,7 @@ func convertImageDependsOn(s convertSidecarOpts) (map[string]string, error) {
130125
// Valid sidecar portMapping example: 2000/udp, or 2000 (default to be tcp).
131126
func parsePortMapping(s *string) (port *string, protocol *string, err error) {
132127
if s == nil {
133-
// default port for sidecar container to be 80.
134-
return aws.String(defaultSidecarPort), nil, nil
128+
return nil, nil, nil
135129
}
136130
portProtocol := strings.Split(*s, "/")
137131
switch len(portProtocol) {

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Test_convertSidecar(t *testing.T) {
2121
mockCredsParam := aws.String("mockCredsParam")
2222
circularDependencyErr := fmt.Errorf("circular container dependency chain includes the following containers: ")
2323
testCases := map[string]struct {
24-
inPort string
24+
inPort *string
2525
inEssential bool
2626
inLabels map[string]string
2727
inDependsOn map[string]string
@@ -32,12 +32,12 @@ func Test_convertSidecar(t *testing.T) {
3232
wantedErr error
3333
}{
3434
"invalid port": {
35-
inPort: "b/a/d/P/o/r/t",
35+
inPort: aws.String("b/a/d/P/o/r/t"),
3636

3737
wantedErr: fmt.Errorf("cannot parse port mapping from b/a/d/P/o/r/t"),
3838
},
3939
"good port without protocol": {
40-
inPort: "2000",
40+
inPort: aws.String("2000"),
4141
inEssential: true,
4242

4343
wanted: &template.SidecarOpts{
@@ -51,7 +51,7 @@ func Test_convertSidecar(t *testing.T) {
5151
},
5252
},
5353
"good port with protocol": {
54-
inPort: "2000/udp",
54+
inPort: aws.String("2000/udp"),
5555
inEssential: true,
5656

5757
wanted: &template.SidecarOpts{
@@ -66,7 +66,7 @@ func Test_convertSidecar(t *testing.T) {
6666
},
6767
},
6868
"invalid container dependency due to circularly depending on itself": {
69-
inPort: "2000",
69+
inPort: aws.String("2000"),
7070
inEssential: true,
7171
inDependsOn: map[string]string{
7272
"foo": "start",
@@ -75,7 +75,7 @@ func Test_convertSidecar(t *testing.T) {
7575
wantedErr: fmt.Errorf("container foo cannot depend on itself"),
7676
},
7777
"invalid container dependency due to circularly depending on another container": {
78-
inPort: "2000",
78+
inPort: aws.String("2000"),
7979
inEssential: true,
8080
inDependsOn: map[string]string{
8181
"frontend": "start",
@@ -89,23 +89,23 @@ func Test_convertSidecar(t *testing.T) {
8989
circDepContainers: []string{"frontend", "foo"},
9090
},
9191
"invalid container dependency status": {
92-
inPort: "2000",
92+
inPort: aws.String("2000"),
9393
inEssential: true,
9494
inDependsOn: map[string]string{
9595
"frontend": "never",
9696
},
9797
wantedErr: errInvalidDependsOnStatus,
9898
},
9999
"invalid essential container dependency status": {
100-
inPort: "2000",
100+
inPort: aws.String("2000"),
101101
inEssential: true,
102102
inDependsOn: map[string]string{
103103
"frontend": "complete",
104104
},
105105
wantedErr: errEssentialContainerStatus,
106106
},
107107
"good essential container dependencies": {
108-
inPort: "2000",
108+
inPort: aws.String("2000"),
109109
inEssential: true,
110110
inDependsOn: map[string]string{
111111
"frontend": "start",
@@ -125,15 +125,13 @@ func Test_convertSidecar(t *testing.T) {
125125
},
126126
},
127127
"good nonessential container dependencies": {
128-
inPort: "2000",
129128
inEssential: false,
130129
inDependsOn: map[string]string{
131130
"frontend": "start",
132131
},
133132

134133
wanted: &template.SidecarOpts{
135134
Name: aws.String("foo"),
136-
Port: aws.String("2000"),
137135
CredsParam: mockCredsParam,
138136
Image: mockImage,
139137
Secrets: mockMap,
@@ -145,7 +143,7 @@ func Test_convertSidecar(t *testing.T) {
145143
},
146144
},
147145
"specify essential as false": {
148-
inPort: "2000",
146+
inPort: aws.String("2000"),
149147
inEssential: false,
150148
inLabels: map[string]string{
151149
"com.amazonaws.ecs.copilot.sidecar.description": "wow",
@@ -174,7 +172,7 @@ func Test_convertSidecar(t *testing.T) {
174172
Secrets: mockMap,
175173
Variables: mockMap,
176174
Essential: aws.Bool(tc.inEssential),
177-
Port: aws.String(tc.inPort),
175+
Port: tc.inPort,
178176
DockerLabels: tc.inLabels,
179177
DependsOn: tc.inDependsOn,
180178
},

0 commit comments

Comments
 (0)