Skip to content

Commit a6e4f6a

Browse files
piradeepkrix0rrr
authored andcommitted
refactor(ecs): hide clusterName from Services (#2980)
BREAKING CHANGE: * **ecs**: `service.clusterName` has been replaced with `.cluster`.
1 parent c9340a6 commit a6e4f6a

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

packages/@aws-cdk/aws-codepipeline-actions/lib/ecs/deploy-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class EcsDeployAction extends codepipeline.Action {
5252
artifactBounds: deployArtifactBounds(),
5353
inputs: [determineInputArtifact(props)],
5454
configuration: {
55-
ClusterName: props.service.clusterName,
55+
ClusterName: props.service.cluster.clusterName,
5656
ServiceName: props.service.serviceName,
5757
FileName: props.imageFile && props.imageFile.fileName,
5858
},

packages/@aws-cdk/aws-ecs/lib/base/base-service.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,16 @@ export abstract class BaseService extends Resource
114114
public readonly serviceName: string;
115115

116116
/**
117-
* Name of this service's cluster
117+
* Task definition this service is associated with
118118
*/
119-
public readonly clusterName: string;
119+
public readonly taskDefinition: TaskDefinition;
120120

121121
/**
122-
* Task definition this service is associated with
122+
* The cluster this service is scheduled on
123123
*/
124-
public readonly taskDefinition: TaskDefinition;
124+
public readonly cluster: ICluster;
125125

126126
protected cloudmapService?: cloudmap.Service;
127-
protected cluster: ICluster;
128127
protected loadBalancers = new Array<CfnService.LoadBalancerProperty>();
129128
protected networkConfiguration?: CfnService.NetworkConfigurationProperty;
130129
protected serviceRegistries = new Array<CfnService.ServiceRegistryProperty>();
@@ -136,7 +135,6 @@ export abstract class BaseService extends Resource
136135
id: string,
137136
props: BaseServiceProps,
138137
additionalProps: any,
139-
clusterName: string,
140138
taskDefinition: TaskDefinition) {
141139
super(scope, id, {
142140
physicalName: props.serviceName,
@@ -178,7 +176,6 @@ export abstract class BaseService extends Resource
178176
this.serviceArn = resourceIdentifiers.arn;
179177
this.serviceName = resourceIdentifiers.name;
180178

181-
this.clusterName = clusterName;
182179
this.cluster = props.cluster;
183180

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

225222
return this.scalableTaskCount = new ScalableTaskCount(this, 'TaskCount', {
226223
serviceNamespace: appscaling.ServiceNamespace.ECS,
227-
resourceId: `service/${this.clusterName}/${this.serviceName}`,
224+
resourceId: `service/${this.cluster.clusterName}/${this.serviceName}`,
228225
dimension: 'ecs:service:DesiredCount',
229226
role: this.makeAutoScalingRole(),
230227
...props
@@ -238,7 +235,7 @@ export abstract class BaseService extends Resource
238235
return new cloudwatch.Metric({
239236
namespace: 'AWS/ECS',
240237
metricName,
241-
dimensions: { ClusterName: this.clusterName, ServiceName: this.serviceName },
238+
dimensions: { ClusterName: this.cluster.clusterName, ServiceName: this.serviceName },
242239
...props
243240
});
244241
}

packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ export class Ec2Service extends BaseService implements IEc2Service, elb.ILoadBal
8585
return new Import(scope, id);
8686
}
8787

88-
/**
89-
* Name of the cluster
90-
*/
91-
public readonly clusterName: string;
92-
9388
private readonly constraints: CfnService.PlacementConstraintProperty[];
9489
private readonly strategies: CfnService.PlacementStrategyProperty[];
9590
private readonly daemon: boolean;
@@ -125,9 +120,8 @@ export class Ec2Service extends BaseService implements IEc2Service, elb.ILoadBal
125120
placementConstraints: Lazy.anyValue({ produce: () => this.constraints }, { omitEmptyArray: true }),
126121
placementStrategies: Lazy.anyValue({ produce: () => this.strategies }, { omitEmptyArray: true }),
127122
schedulingStrategy: props.daemon ? 'DAEMON' : 'REPLICA',
128-
}, props.cluster.clusterName, props.taskDefinition);
123+
}, props.taskDefinition);
129124

130-
this.clusterName = props.cluster.clusterName;
131125
this.constraints = [];
132126
this.strategies = [];
133127
this.daemon = props.daemon || false;

packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class FargateService extends BaseService implements IFargateService {
7878
taskDefinition: props.taskDefinition.taskDefinitionArn,
7979
launchType: 'FARGATE',
8080
platformVersion: props.platformVersion,
81-
}, props.cluster.clusterName, props.taskDefinition);
81+
}, props.taskDefinition);
8282

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

0 commit comments

Comments
 (0)