Skip to content

Commit 9a799c3

Browse files
committed
Added ECS Params schema for Service Discovery
1 parent 922ca35 commit 9a799c3

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

ecs-cli/modules/utils/compose/ecs_params_reader.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ type TaskSize struct {
101101
type RunParams struct {
102102
NetworkConfiguration NetworkConfiguration `yaml:"network_configuration"`
103103
TaskPlacement TaskPlacement `yaml:"task_placement"`
104+
ServiceDiscovery ServiceDiscovery `yaml:"service_discovery"`
104105
}
105106

106107
// NetworkConfiguration specifies the network config for the task definition.
@@ -117,9 +118,52 @@ type AwsVpcConfiguration struct {
117118
AssignPublicIp AssignPublicIp `yaml:"assign_public_ip"` // Needed to run FARGATE tasks
118119
}
119120

121+
// TODO: Remove; use enum in aws-sdk-go instead (AssignPublicIpEnabled, AssignPublicIpDisabled)
120122
type AssignPublicIp string
121123

122-
// TODO: Remove; use enum in aws-sdk-go instead (AssignPublicIpEnabled, AssignPublicIpDisabled)
124+
// ServiceDiscovery holds information related to ECS/Route53 Service Discovery
125+
type ServiceDiscovery struct {
126+
ContainerName string `yaml:"container_name"`
127+
ContainerPort *int64 `yaml:"container_port"`
128+
PrivateDNSNamespace PrivateDNSNamespace `yaml:"private_dns_namespace"`
129+
PublicDNSNamespace PublicDNSNamespace `yaml:"public_dns_namespace"`
130+
ServiceDiscoveryService ServiceDiscoveryService `yaml:"service_discovery_service"`
131+
}
132+
133+
// PrivateDNSNamespace holds information related to Route53 private DNS namespaces
134+
type PrivateDNSNamespace struct {
135+
VPC string `yaml:"vpc"`
136+
ID string `yaml:"id"`
137+
Name string `yaml:"name"`
138+
Description string `yaml:"description"`
139+
}
140+
141+
// PublicDNSNamespace holds information related to Route53 public DNS namespaces
142+
type PublicDNSNamespace struct {
143+
ID string `yaml:"id"`
144+
Name string `yaml:"name"`
145+
}
146+
147+
// ServiceDiscoveryService holds information related to Route53 Service Discovery Services
148+
type ServiceDiscoveryService struct {
149+
Name string `yaml:"name"`
150+
Description string `yaml:"description"`
151+
DNSConfig DNSConfig `yaml:"dns_config"`
152+
RoutingPolicy string `yaml:"routing_policy"`
153+
HealthCheckCustomConfig HealthCheckCustomConfig `yaml:"healthcheck_custom_config"`
154+
}
155+
156+
// DNSConfig holds the dns configuration for Service Discovery Services
157+
type DNSConfig struct {
158+
Type string `yaml:"type"`
159+
TTL *int64 `yaml:"ttl"`
160+
}
161+
162+
// HealthCheckCustomConfig
163+
type HealthCheckCustomConfig struct {
164+
FailureThreshold *int64 `yaml:"failure_threshold"`
165+
}
166+
123167
const (
124168
Enabled AssignPublicIp = "ENABLED"
125169
Disabled AssignPublicIp = "DISABLED"

ecs-cli/modules/utils/compose/ecs_params_reader_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,66 @@ task_definition:
713713
}
714714
}
715715

716+
func TestReadECSParams_WithServiceDiscoveryAllFields(t *testing.T) {
717+
ecsParamsString := `version: 1
718+
run_params:
719+
service_discovery:
720+
container_name: nginx
721+
container_port: 80
722+
private_dns_namespace:
723+
vpc: vpc-8BAADF00D
724+
id: ns-CA15CA15CA15CA15
725+
name: corp
726+
description: This is a private namespace
727+
public_dns_namespace:
728+
id: ns-C0VF3F3
729+
name: amazon.com
730+
service_discovery_service:
731+
name: mysds
732+
description: This is an SDS
733+
dns_config:
734+
type: A
735+
ttl: 60
736+
routing_policy: MULTIVALUE
737+
healthcheck_custom_config:
738+
failure_threshold: 1`
739+
740+
content := []byte(ecsParamsString)
741+
742+
tmpfile, err := ioutil.TempFile("", "ecs-params")
743+
assert.NoError(t, err, "Could not create ecs-params tempfile")
744+
745+
ecsParamsFileName := tmpfile.Name()
746+
defer os.Remove(ecsParamsFileName)
747+
748+
_, err = tmpfile.Write(content)
749+
assert.NoError(t, err, "Could not write data to ecs-params tempfile")
750+
751+
err = tmpfile.Close()
752+
assert.NoError(t, err, "Could not close tempfile")
753+
754+
ecsParams, err := ReadECSParams(ecsParamsFileName)
755+
756+
if assert.NoError(t, err) {
757+
serviceDiscovery := ecsParams.RunParams.ServiceDiscovery
758+
assert.Equal(t, "nginx", serviceDiscovery.ContainerName, "Expected ContainerName to match")
759+
assert.Equal(t, aws.Int64(80), serviceDiscovery.ContainerPort, "Expected ContainerPort to match")
760+
assert.Equal(t, "vpc-8BAADF00D", serviceDiscovery.PrivateDNSNamespace.VPC, "Expected VPC to match")
761+
assert.Equal(t, "ns-CA15CA15CA15CA15", serviceDiscovery.PrivateDNSNamespace.ID, "Expected private namespace ID to match")
762+
assert.Equal(t, "corp", serviceDiscovery.PrivateDNSNamespace.Name, "Expected private namespace Name to match")
763+
assert.Equal(t, "This is a private namespace", serviceDiscovery.PrivateDNSNamespace.Description, "Expected private namespace description to match")
764+
assert.Equal(t, "ns-C0VF3F3", serviceDiscovery.PublicDNSNamespace.ID, "Expected public namespace ID to match")
765+
assert.Equal(t, "amazon.com", serviceDiscovery.PublicDNSNamespace.Name, "Expected public namespace name to match")
766+
sds := serviceDiscovery.ServiceDiscoveryService
767+
assert.Equal(t, "mysds", sds.Name, "Expected SDS Name to match")
768+
assert.Equal(t, "This is an SDS", sds.Description, "Expected SDS Description to match")
769+
assert.Equal(t, "A", sds.DNSConfig.Type, "Expected SDS DNSConfig Type to match")
770+
assert.Equal(t, aws.Int64(60), sds.DNSConfig.TTL, "Expected SDS DNSConfig TTL to match")
771+
assert.Equal(t, "MULTIVALUE", sds.RoutingPolicy, "Expected SDS RoutingPolicy to match")
772+
assert.Equal(t, aws.Int64(1), sds.HealthCheckCustomConfig.FailureThreshold, "Expected SDS HealthCheckCustomConfig FailureThreshold to match")
773+
}
774+
}
775+
716776
func TestConvertToECSHealthCheck(t *testing.T) {
717777
testHealthCheck := &HealthCheck{
718778
Test: []string{"CMD-SHELL", "curl -f http://localhost"},

0 commit comments

Comments
 (0)