Skip to content

Commit

Permalink
added annotation warnings for unused properties
Browse files Browse the repository at this point in the history
  • Loading branch information
lpizzinidev committed Aug 18, 2023
1 parent 744eab6 commit 37f7454
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Construct } from 'constructs';
import { FargatePlatformVersion, FargateTaskDefinition } from '../../../aws-ecs';
import { FargateTaskDefinition } from '../../../aws-ecs';
import { EcsTask } from '../../../aws-events-targets';
import { FargateServiceBaseProps } from '../base/fargate-service-base';
import { ScheduledTaskBase, ScheduledTaskBaseProps, ScheduledTaskImageProps } from '../base/scheduled-task-base';
import { Annotations } from '../../../core';

/**
* The properties for the ScheduledFargateTask task.
*/
export interface ScheduledFargateTaskProps extends ScheduledTaskBaseProps {
export interface ScheduledFargateTaskProps extends ScheduledTaskBaseProps, FargateServiceBaseProps {
/**
* The properties to define if using an existing TaskDefinition in this construct.
* ScheduledFargateTaskDefinitionOptions or ScheduledFargateTaskImageOptions must be defined, but not both.
Expand All @@ -23,17 +24,6 @@ export interface ScheduledFargateTaskProps extends ScheduledTaskBaseProps {
* @default none
*/
readonly scheduledFargateTaskImageOptions?: ScheduledFargateTaskImageOptions;

/**
* The platform version on which to run your service.
*
* If one is not specified, the LATEST platform version is used by default. For more information, see
* [AWS Fargate Platform Versions](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/platform_versions.html)
* in the Amazon Elastic Container Service Developer Guide.
*
* @default Latest
*/
readonly platformVersion?: FargatePlatformVersion;
}

/**
Expand Down Expand Up @@ -98,8 +88,21 @@ export class ScheduledFargateTask extends ScheduledTaskBase {
throw new Error('You must specify one of: taskDefinition or image');
}

if (props.taskDefinition) {
Annotations.of(this).addWarning('Property \'taskDefinition\' is ignored, use \'scheduledFargateTaskDefinitionOptions\' or \'scheduledFargateTaskImageOptions\' instead.');
}
if (props.cpu) {
Annotations.of(this).addWarning('Property \'cpu\' is ignored, use \'scheduledFargateTaskImageOptions.cpu\' instead.');
}
if (props.memoryLimitMiB) {
Annotations.of(this).addWarning('Property \'memoryLimitMiB\' is ignored, use \'scheduledFargateTaskImageOptions.memoryLimitMiB\' instead.');
}
if (props.runtimePlatform) {
Annotations.of(this).addWarning('Property \'runtimePlatform\' is ignored.');
}

// Use the EcsTask as the target of the EventRule
this.task = new EcsTask({
this.task = new EcsTask( {
cluster: this.cluster,
taskDefinition: this.taskDefinition,
taskCount: this.desiredTaskCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,35 @@ test('Scheduled Fargate Task - with list of tags', () => {
],
});
});

test('Scheduled Fargate Task - with unused properties', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 1 });
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });

new ScheduledFargateTask(stack, 'ScheduledFargateTask', {
cluster,
scheduledFargateTaskImageOptions: {
image: ecs.ContainerImage.fromRegistry('henk'),
memoryLimitMiB: 512,
},
schedule: events.Schedule.expression('rate(1 minute)'),
taskDefinition: new ecs.FargateTaskDefinition(stack, 'ScheduledFargateTaskDefinition'),
cpu: 256,
memoryLimitMiB: 512,
runtimePlatform: {
cpuArchitecture: ecs.CpuArchitecture.X86_64,
},
});

// THEN
Annotations.fromStack(stack).hasWarning(
'/Default/ScheduledFargateTask',
Match.stringLikeRegexp('Property \'taskDefinition\' is ignored, use \'scheduledFargateTaskDefinitionOptions\' or \'scheduledFargateTaskImageOptions\' instead.'),
);
Annotations.fromStack(stack).hasWarning('/Default/ScheduledFargateTask', Match.stringLikeRegexp('Property \'cpu\' is ignored, use \'scheduledFargateTaskImageOptions.cpu\' instead.'));
Annotations.fromStack(stack).hasWarning('/Default/ScheduledFargateTask', Match.stringLikeRegexp('Property \'memoryLimitMiB\' is ignored, use \'scheduledFargateTaskImageOptions.memoryLimitMiB\' instead.'));
Annotations.fromStack(stack).hasWarning('/Default/ScheduledFargateTask', Match.stringLikeRegexp('Property \'runtimePlatform\' is ignored.'));
});

0 comments on commit 37f7454

Please sign in to comment.