Skip to content

Commit 2efb16e

Browse files
authored
chore(manifest): add data structures for efs fields (#1890)
<!-- Provide summary of changes --> Adds new structs for Volume and Mount Point task definition fields and custom unmarshaling logic for `efs` key. <!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" --> Adds the following specification to the manifest. ```yaml storage: volumes: myVolume: path: '/path/inside/container' read_only: false efs: id: fs-12345 root_dir: '/' auth: iam: true access_point_id: ap-5678 sidecars: nginx: mount_points: - source_volume: myVolume path: '/var/www' read_only: true ``` If a customer does not need detailed efs configuration and wishes to use sane defaults, they can specify: ```yaml volumes: myVolume: path: '/path/inside/container' read_only: false efs: id: fs-12345 ``` Which will render to the following defaults for the `efs` struct: ```yaml efs: filesystem_id: fs-12345 root_directory: '/' transit_encryption: true authorization_config: iam: false access_point_id: "" ``` 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 d5a3021 commit 2efb16e

File tree

7 files changed

+142
-6
lines changed

7 files changed

+142
-6
lines changed

internal/pkg/manifest/backend_svc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type BackendServiceConfig struct {
3939
TaskConfig `yaml:",inline"`
4040
*Logging `yaml:"logging,flow"`
4141
Sidecar `yaml:",inline"`
42+
Storage `yaml:"storage"`
4243
}
4344

4445
// LogConfigOpts converts the service's Firelens configuration into a format parsable by the templates pkg.

internal/pkg/manifest/job.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type ScheduledJobConfig struct {
4040
TaskConfig `yaml:",inline"`
4141
*Logging `yaml:"logging,flow"`
4242
Sidecar `yaml:",inline"`
43+
Storage `yaml:"storage"`
4344
On JobTriggerConfig `yaml:"on,flow"`
4445
JobFailureHandlerConfig `yaml:",inline"`
4546
}

internal/pkg/manifest/lb_web_svc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type LoadBalancedWebServiceConfig struct {
4747
TaskConfig `yaml:",inline"`
4848
*Logging `yaml:"logging,flow"`
4949
Sidecar `yaml:",inline"`
50+
Storage `yaml:"storage"`
5051
}
5152

5253
// LogConfigOpts converts the service's Firelens configuration into a format parsable by the templates pkg.

internal/pkg/manifest/lb_web_svc_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,19 @@ func TestLoadBalancedWebService_ApplyEnv(t *testing.T) {
267267
Value: aws.Int(1),
268268
},
269269
},
270+
Storage: Storage{
271+
Volumes: map[string]Volume{
272+
"myEFSVolume": {
273+
MountPointOpts: MountPointOpts{
274+
ContainerPath: aws.String("/path/to/files"),
275+
ReadOnly: aws.Bool(false),
276+
},
277+
EFS: EFSVolumeConfiguration{
278+
FileSystemID: aws.String("fs-1234"),
279+
},
280+
},
281+
},
282+
},
270283
},
271284
},
272285
envToApply: "prod-iad",
@@ -300,6 +313,19 @@ func TestLoadBalancedWebService_ApplyEnv(t *testing.T) {
300313
Value: aws.Int(1),
301314
},
302315
},
316+
Storage: Storage{
317+
Volumes: map[string]Volume{
318+
"myEFSVolume": {
319+
MountPointOpts: MountPointOpts{
320+
ContainerPath: aws.String("/path/to/files"),
321+
ReadOnly: aws.Bool(false),
322+
},
323+
EFS: EFSVolumeConfiguration{
324+
FileSystemID: aws.String("fs-1234"),
325+
},
326+
},
327+
},
328+
},
303329
},
304330
},
305331
},
@@ -341,6 +367,23 @@ func TestLoadBalancedWebService_ApplyEnv(t *testing.T) {
341367
"TWILIO_TOKEN": "1111",
342368
},
343369
},
370+
Storage: Storage{
371+
Volumes: map[string]Volume{
372+
"myEFSVolume": {
373+
MountPointOpts: MountPointOpts{
374+
ContainerPath: aws.String("/path/to/files"),
375+
ReadOnly: aws.Bool(false),
376+
},
377+
EFS: EFSVolumeConfiguration{
378+
FileSystemID: aws.String("fs-1234"),
379+
AuthConfig: AuthorizationConfig{
380+
IAM: aws.Bool(true),
381+
AccessPointID: aws.String("ap-1234"),
382+
},
383+
},
384+
},
385+
},
386+
},
344387
Sidecar: Sidecar{
345388
Sidecars: map[string]*SidecarConfig{
346389
"xray": {
@@ -378,10 +421,31 @@ func TestLoadBalancedWebService_ApplyEnv(t *testing.T) {
378421
"DDB_TABLE_NAME": "awards-prod",
379422
},
380423
},
424+
Storage: Storage{
425+
Volumes: map[string]Volume{
426+
"myEFSVolume": {
427+
EFS: EFSVolumeConfiguration{
428+
FileSystemID: aws.String("fs-5678"),
429+
AuthConfig: AuthorizationConfig{
430+
AccessPointID: aws.String("ap-5678"),
431+
},
432+
},
433+
},
434+
},
435+
},
381436
Sidecar: Sidecar{
382437
Sidecars: map[string]*SidecarConfig{
383438
"xray": {
384439
Port: aws.String("2000/udp"),
440+
MountPoints: []SidecarMountPoint{
441+
{
442+
SourceVolume: aws.String("myEFSVolume"),
443+
MountPointOpts: MountPointOpts{
444+
ReadOnly: aws.Bool(true),
445+
ContainerPath: aws.String("/var/www"),
446+
},
447+
},
448+
},
385449
},
386450
},
387451
},
@@ -433,12 +497,38 @@ func TestLoadBalancedWebService_ApplyEnv(t *testing.T) {
433497
"TWILIO_TOKEN": "1111",
434498
},
435499
},
500+
Storage: Storage{
501+
Volumes: map[string]Volume{
502+
"myEFSVolume": {
503+
MountPointOpts: MountPointOpts{
504+
ContainerPath: aws.String("/path/to/files"),
505+
ReadOnly: aws.Bool(false),
506+
},
507+
EFS: EFSVolumeConfiguration{
508+
FileSystemID: aws.String("fs-5678"),
509+
AuthConfig: AuthorizationConfig{
510+
IAM: aws.Bool(true),
511+
AccessPointID: aws.String("ap-5678"),
512+
},
513+
},
514+
},
515+
},
516+
},
436517
Sidecar: Sidecar{
437518
Sidecars: map[string]*SidecarConfig{
438519
"xray": {
439520
Port: aws.String("2000/udp"),
440521
Image: aws.String("123456789012.dkr.ecr.us-east-2.amazonaws.com/xray-daemon"),
441522
CredsParam: aws.String("some arn"),
523+
MountPoints: []SidecarMountPoint{
524+
{
525+
SourceVolume: aws.String("myEFSVolume"),
526+
MountPointOpts: MountPointOpts{
527+
ReadOnly: aws.Bool(true),
528+
ContainerPath: aws.String("/var/www"),
529+
},
530+
},
531+
},
442532
},
443533
},
444534
},

internal/pkg/manifest/storage.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package manifest
4+
5+
// Storage represents the options for external and native storage.
6+
type Storage struct {
7+
Volumes map[string]Volume `yaml:"volumes"`
8+
}
9+
10+
// Volume is an abstraction which merges the MountPoint and Volumes concepts from the ECS Task Definition
11+
type Volume struct {
12+
EFS EFSVolumeConfiguration `yaml:"efs"`
13+
MountPointOpts `yaml:",inline"`
14+
}
15+
16+
// MountPointOpts is shared between Volumes for the main container and MountPoints for sidecars.
17+
type MountPointOpts struct {
18+
ContainerPath *string `yaml:"path"`
19+
ReadOnly *bool `yaml:"read_only"`
20+
}
21+
22+
// SidecarMountPoint is used to let sidecars mount volumes defined in `storage`
23+
type SidecarMountPoint struct {
24+
SourceVolume *string `yaml:"source_volume"`
25+
MountPointOpts `yaml:",inline"`
26+
}
27+
28+
// EFSVolumeConfiguration holds options which tell ECS how to reach out to the EFS filesystem.
29+
type EFSVolumeConfiguration struct {
30+
FileSystemID *string `yaml:"id"` // Required.
31+
RootDirectory *string `yaml:"root_dir"` // Default "/"
32+
AuthConfig AuthorizationConfig `yaml:"auth"`
33+
}
34+
35+
// AuthorizationConfig holds options relating to access points and IAM authorization.
36+
type AuthorizationConfig struct {
37+
IAM *bool `yaml:"iam"` // Default true
38+
AccessPointID *string `yaml:"access_point_id"` // Default ""
39+
}

internal/pkg/manifest/storage_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package manifest

internal/pkg/manifest/workload.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424

2525
var (
2626
errUnmarshalBuildOpts = errors.New("can't unmarshal build field into string or compose-style map")
27-
errUnmarshalCountOpts = errors.New(`unmarshal "count" field to an integer or autoscaling configuration`)
27+
errUnmarshalCountOpts = errors.New(`can't unmarshal "count" field to an integer or autoscaling configuration`)
2828
)
2929

3030
var dockerfileDefaultName = "Dockerfile"
@@ -243,11 +243,12 @@ func (s *Sidecar) Options() ([]*template.SidecarOpts, error) {
243243

244244
// SidecarConfig represents the configurable options for setting up a sidecar container.
245245
type SidecarConfig struct {
246-
Port *string `yaml:"port"`
247-
Image *string `yaml:"image"`
248-
CredsParam *string `yaml:"credentialsParameter"`
249-
Variables map[string]string `yaml:"variables"`
250-
Secrets map[string]string `yaml:"secrets"`
246+
Port *string `yaml:"port"`
247+
Image *string `yaml:"image"`
248+
CredsParam *string `yaml:"credentialsParameter"`
249+
Variables map[string]string `yaml:"variables"`
250+
Secrets map[string]string `yaml:"secrets"`
251+
MountPoints []SidecarMountPoint `yaml:"mount_points"`
251252
}
252253

253254
// Valid sidecar portMapping example: 2000/udp, or 2000 (default to be tcp).

0 commit comments

Comments
 (0)