Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-ecs): make cluster name private in all services #2980

Merged
merged 2 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class EcsDeployAction extends codepipeline.Action {
artifactBounds: deployArtifactBounds(),
inputs: [determineInputArtifact(props)],
configuration: {
ClusterName: props.service.clusterName,
ClusterName: props.service.cluster.clusterName,
ServiceName: props.service.serviceName,
FileName: props.imageFile && props.imageFile.fileName,
},
Expand Down
15 changes: 6 additions & 9 deletions packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,16 @@ export abstract class BaseService extends Resource
public readonly serviceName: string;

/**
* Name of this service's cluster
* Task definition this service is associated with
*/
public readonly clusterName: string;
public readonly taskDefinition: TaskDefinition;

/**
* Task definition this service is associated with
* The cluster this service is scheduled on
*/
public readonly taskDefinition: TaskDefinition;
public readonly cluster: ICluster;

protected cloudmapService?: cloudmap.Service;
protected cluster: ICluster;
protected loadBalancers = new Array<CfnService.LoadBalancerProperty>();
protected networkConfiguration?: CfnService.NetworkConfigurationProperty;
protected serviceRegistries = new Array<CfnService.ServiceRegistryProperty>();
Expand All @@ -136,7 +135,6 @@ export abstract class BaseService extends Resource
id: string,
props: BaseServiceProps,
additionalProps: any,
clusterName: string,
taskDefinition: TaskDefinition) {
super(scope, id, {
physicalName: props.serviceName,
Expand Down Expand Up @@ -178,7 +176,6 @@ export abstract class BaseService extends Resource
this.serviceArn = resourceIdentifiers.arn;
this.serviceName = resourceIdentifiers.name;

this.clusterName = clusterName;
this.cluster = props.cluster;

if (props.serviceDiscoveryOptions) {
Expand Down Expand Up @@ -224,7 +221,7 @@ export abstract class BaseService extends Resource

return this.scalableTaskCount = new ScalableTaskCount(this, 'TaskCount', {
serviceNamespace: appscaling.ServiceNamespace.ECS,
resourceId: `service/${this.clusterName}/${this.serviceName}`,
resourceId: `service/${this.cluster.clusterName}/${this.serviceName}`,
dimension: 'ecs:service:DesiredCount',
role: this.makeAutoScalingRole(),
...props
Expand All @@ -238,7 +235,7 @@ export abstract class BaseService extends Resource
return new cloudwatch.Metric({
namespace: 'AWS/ECS',
metricName,
dimensions: { ClusterName: this.clusterName, ServiceName: this.serviceName },
dimensions: { ClusterName: this.cluster.clusterName, ServiceName: this.serviceName },
...props
});
}
Expand Down
8 changes: 1 addition & 7 deletions packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ export class Ec2Service extends BaseService implements IEc2Service, elb.ILoadBal
return new Import(scope, id);
}

/**
* Name of the cluster
*/
public readonly clusterName: string;

private readonly constraints: CfnService.PlacementConstraintProperty[];
private readonly strategies: CfnService.PlacementStrategyProperty[];
private readonly daemon: boolean;
Expand Down Expand Up @@ -125,9 +120,8 @@ export class Ec2Service extends BaseService implements IEc2Service, elb.ILoadBal
placementConstraints: Lazy.anyValue({ produce: () => this.constraints }, { omitEmptyArray: true }),
placementStrategies: Lazy.anyValue({ produce: () => this.strategies }, { omitEmptyArray: true }),
schedulingStrategy: props.daemon ? 'DAEMON' : 'REPLICA',
}, props.cluster.clusterName, props.taskDefinition);
}, props.taskDefinition);

this.clusterName = props.cluster.clusterName;
this.constraints = [];
this.strategies = [];
this.daemon = props.daemon || false;
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class FargateService extends BaseService implements IFargateService {
taskDefinition: props.taskDefinition.taskDefinitionArn,
launchType: 'FARGATE',
platformVersion: props.platformVersion,
}, props.cluster.clusterName, props.taskDefinition);
}, props.taskDefinition);

this.configureAwsVpcNetworking(props.cluster.vpc, props.assignPublicIp, props.vpcSubnets, props.securityGroup);

Expand Down