Skip to content

Commit

Permalink
refactor(ecs): hide clusterName from Services (#2980)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

* **ecs**: `service.clusterName` has been replaced with `.cluster`.
  • Loading branch information
piradeepk authored and rix0rrr committed Jun 21, 2019
1 parent c9340a6 commit a6e4f6a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
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

0 comments on commit a6e4f6a

Please sign in to comment.