Skip to content

Commit

Permalink
Merge branch 'master' into ecs-partition-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
makrsmark authored Jan 20, 2022
2 parents 2998ee4 + 7947e07 commit 3184f45
Show file tree
Hide file tree
Showing 240 changed files with 2,943 additions and 8,788 deletions.
24 changes: 3 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -803,35 +803,17 @@ The pattern is simple:
with the name of the context key that **enables** this new feature (for
example, `ENABLE_STACK_NAME_DUPLICATES`). The context key should be in the
form `module.Type:feature` (e.g. `@aws-cdk/core:enableStackNameDuplicates`).
2. Use `node.tryGetContext(cxapi.ENABLE_XXX)` to check if this feature is enabled
2. Use `FeatureFlags.of(construct).isEnabled(cxapi.ENABLE_XXX)` to check if this feature is enabled
in your code. If it is not defined, revert to the legacy behavior.
3. Add your feature flag to the `FUTURE_FLAGS` map in
[cx-api/lib/features.ts](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/cx-api/lib/features.ts).
This map is inserted to generated `cdk.json` files for new projects created
through `cdk init`.
4. In your PR title (which goes into CHANGELOG), add a `(under feature flag)` suffix. e.g:
4. In your tests, use the `testFutureBehavior` and `testLegacyBehavior` [jest helper methods] to test the enabled and disabled behavior.
5. In your PR title (which goes into CHANGELOG), add a `(under feature flag)` suffix. e.g:

`fix(core): impossible to use the same physical stack name for two stacks (under feature flag)`

In the [next major version of the
CDK](https://github.com/aws/aws-cdk/issues/3398) we will either remove the
legacy behavior or flip the logic for all these features and then
reset the `FEATURE_FLAGS` map for the next cycle.

### Feature Flags - CDKv2

We have started working on the next version of the CDK, specifically CDKv2. This is currently being maintained
on a separate branch `v2-main` whereas `master` continues to track versions `1.x`.

Feature flags introduced in the CDK 1.x and removed in 2.x, must be added to the `FUTURE_FLAGS_EXPIRED` list in
[cx-api/lib/features.ts](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/cx-api/lib/features.ts)
on the `v2-main` branch.
This will make the default behaviour in CDKv2 as if the flag is enabled and also prevents users from disabling
the feature flag.

A couple of [jest helper methods] are available for use with unit tests. These help run unit tests that test
behaviour when flags are enabled or disabled in the two major versions.

[jest helper methods]: https://github.com/aws/aws-cdk/blob/master/tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts

## Versioning and Release
Expand Down
5 changes: 5 additions & 0 deletions allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,8 @@ base-types:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps
changed-type:@aws-cdk/aws-elasticloadbalancingv2.ApplicationLoadBalancer.vpc
changed-type:@aws-cdk/aws-elasticloadbalancingv2.BaseLoadBalancer.vpc
changed-type:@aws-cdk/aws-elasticloadbalancingv2.NetworkLoadBalancer.vpc

# removed methods and properties related to event bridge notifications for S3 buckets as they are not yet supported (19 Jan 2022)
removed:@aws-cdk/aws-s3.Bucket.enableEventBridgeNotification
removed:@aws-cdk/aws-s3.BucketBase.enableEventBridgeNotification
removed:@aws-cdk/aws-s3.BucketProps.eventBridgeEnabled
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"@yarnpkg/lockfile": "^1.1.0",
"cdk-generate-synthetic-examples": "^0.1.2",
"cdk-generate-synthetic-examples": "^0.1.3",
"conventional-changelog-cli": "^2.2.2",
"fs-extra": "^9.1.0",
"graceful-fs": "^4.2.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assert-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^27.4.0",
"jest": "^27.4.7",
"ts-jest": "^27.1.2"
"ts-jest": "^27.1.3"
},
"dependencies": {
"@aws-cdk/cloud-assembly-schema": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"aws-cdk-migration": "0.0.0",
"constructs": "^3.3.69",
"jest": "^27.3.1",
"ts-jest": "^27.1.2"
"ts-jest": "^27.1.3"
},
"dependencies": {
"@aws-cdk/cloudformation-diff": "0.0.0",
Expand Down
16 changes: 14 additions & 2 deletions packages/@aws-cdk/assertions/lib/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class LiteralMatch extends Matcher {

public test(actual: any): MatchResult {
if (Array.isArray(this.pattern)) {
return new ArrayMatch(this.name, this.pattern, { subsequence: false }).test(actual);
return new ArrayMatch(this.name, this.pattern, { subsequence: false, partialObjects: this.partialObjects }).test(actual);
}

if (typeof this.pattern === 'object') {
Expand Down Expand Up @@ -155,13 +155,21 @@ interface ArrayMatchOptions {
* @default true
*/
readonly subsequence?: boolean;

/**
* Whether to continue matching objects inside the array partially
*
* @default false
*/
readonly partialObjects?: boolean;
}

/**
* Match class that matches arrays.
*/
class ArrayMatch extends Matcher {
private readonly subsequence: boolean;
private readonly partialObjects: boolean;

constructor(
public readonly name: string,
Expand All @@ -170,6 +178,7 @@ class ArrayMatch extends Matcher {

super();
this.subsequence = options.subsequence ?? true;
this.partialObjects = options.partialObjects ?? false;
}

public test(actual: any): MatchResult {
Expand All @@ -195,7 +204,10 @@ class ArrayMatch extends Matcher {
while (patternIdx < this.pattern.length && actualIdx < actual.length) {
const patternElement = this.pattern[patternIdx];

const matcher = Matcher.isMatcher(patternElement) ? patternElement : new LiteralMatch(this.name, patternElement);
const matcher = Matcher.isMatcher(patternElement)
? patternElement
: new LiteralMatch(this.name, patternElement, { partialObjects: this.partialObjects });

const matcherName = matcher.name;
if (this.subsequence && (matcherName == 'absent' || matcherName == 'anyValue')) {
// array subsequence matcher is not compatible with anyValue() or absent() matcher. They don't make sense to be used together.
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assertions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@types/jest": "^27.4.0",
"constructs": "^3.3.69",
"jest": "^27.4.7",
"ts-jest": "^27.1.2"
"ts-jest": "^27.1.3"
},
"dependencies": {
"@aws-cdk/cloud-assembly-schema": "0.0.0",
Expand Down
21 changes: 19 additions & 2 deletions packages/@aws-cdk/assertions/test/match.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,31 @@ describe('Matchers', () => {
expectPass(matcher, { foo: 'bar', baz: { fred: 'waldo', wobble: 'flob' } });
});

test('nested with ArrayMatch', () => {
test('ArrayMatch nested inside ObjectMatch', () => {
matcher = Match.objectLike({
foo: Match.arrayWith(['bar']),
});
expectPass(matcher, { foo: ['bar', 'baz'], fred: 'waldo' });
expectFailure(matcher, { foo: ['baz'], fred: 'waldo' }, [/Missing element \[bar\] at pattern index 0 at \/foo/]);
});

test('Partiality is maintained throughout arrays', () => {
// Before this fix:
//
// - objectLike({ x: { LITERAL }) ==> LITERAL would be matched partially as well
// - objectLike({ xs: [ { LITERAL } ] }) ==> but here LITERAL would be matched fully
//
// That passing through an array resets the partial matching to full is a
// surprising inconsistency.
//
matcher = Match.objectLike({
foo: [{ bar: 'bar' }],
});
expectPass(matcher, { foo: [{ bar: 'bar' }] }); // Trivially true
expectPass(matcher, { boo: 'boo', foo: [{ bar: 'bar' }] }); // Additional members at top level okay
expectPass(matcher, { foo: [{ bar: 'bar', boo: 'boo' }] }); // Additional members at inner level okay
});

test('absent', () => {
matcher = Match.objectLike({ foo: Match.absent() });
expectPass(matcher, { bar: 'baz' });
Expand Down Expand Up @@ -389,7 +406,7 @@ describe('Matchers', () => {
function expectPass(matcher: Matcher, target: any): void {
const result = matcher.test(target);
if (result.hasFailed()) {
fail(result.toHumanStrings()); // eslint-disable-line jest/no-jasmine-globals
throw new Error(result.toHumanStrings().join('\n')); // eslint-disable-line jest/no-jasmine-globals
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert-internal": "0.0.0",
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cdk-integ-tools": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/assets/test/compat.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SymlinkFollowMode } from '@aws-cdk/core';
import '@aws-cdk/assert-internal/jest';
import { FollowMode } from '../lib';
import { toSymlinkFollow } from '../lib/compat';

Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/assets/test/staging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as path from 'path';
import { describeDeprecated } from '@aws-cdk/cdk-build-tools';
import { App, Stack } from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import '@aws-cdk/assert-internal/jest';
import { Staging } from '../lib';

describeDeprecated('staging', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-acmpca/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert-internal": "0.0.0",
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/aws-acmpca/test/acmpca.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@aws-cdk/assert-internal/jest';
import {} from '../lib';

test('No tests are specified for this package', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cdk-integ-tools": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@types/aws-lambda": "^8.10.89",
"@types/aws-lambda": "^8.10.90",
"@types/jest": "^27.4.0"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-applicationautoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert-internal": "0.0.0",
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@aws-cdk/assert-internal/jest';
import { Match, Template } from '@aws-cdk/assertions';
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
Expand All @@ -20,7 +20,7 @@ describe('scalable target', () => {
});

// THEN
expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', {
Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', {
ServiceNamespace: 'dynamodb',
ScalableDimension: 'test:TestCount',
ResourceId: 'test:this/test',
Expand All @@ -43,7 +43,7 @@ describe('scalable target', () => {
});

// THEN: no exception
expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', {
Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', {
ServiceNamespace: 'dynamodb',
ScalableDimension: 'test:TestCount',
ResourceId: 'test:this/test',
Expand All @@ -65,7 +65,7 @@ describe('scalable target', () => {
});

// THEN
expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', {
Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', {
ScheduledActions: [
{
ScalableTargetAction: {
Expand Down Expand Up @@ -104,11 +104,11 @@ describe('scalable target', () => {
});

// THEN
expect(stack).not.toHaveResource('AWS::CloudWatch::Alarm', {
Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', Match.not({
Period: 60,
});
}));

expect(stack).toHaveResource('AWS::CloudWatch::Alarm', {
Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', {
ComparisonOperator: 'LessThanOrEqualToThreshold',
EvaluationPeriods: 1,
Metrics: [
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('scalable target', () => {
});

// THEN
expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', {
Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', {
ServiceNamespace: 'dynamodb',
ScalableDimension: 'test:TestCount',
ResourceId: 'test:this/test',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '@aws-cdk/assert-internal/jest';
import { SynthUtils } from '@aws-cdk/assert-internal';
import { Template } from '@aws-cdk/assertions';
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import * as cdk from '@aws-cdk/core';
import * as fc from 'fast-check';
Expand Down Expand Up @@ -132,7 +131,7 @@ describe('step scaling policy', () => {
});

// THEN
expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', {
Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', {
PolicyType: 'StepScaling',
ScalingTargetId: {
Ref: 'Target3191CF44',
Expand Down Expand Up @@ -169,14 +168,14 @@ describe('step scaling policy', () => {
});

// THEN
expect(stack).toHaveResourceLike('AWS::ApplicationAutoScaling::ScalingPolicy', {
Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', {
PolicyType: 'StepScaling',
StepScalingPolicyConfiguration: {
AdjustmentType: 'ChangeInCapacity',
MetricAggregationType: 'Average',
},
});
expect(stack).toHaveResource('AWS::CloudWatch::Alarm', {
Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', {
ComparisonOperator: 'GreaterThanOrEqualToThreshold',
EvaluationPeriods: 1,
AlarmActions: [
Expand Down Expand Up @@ -209,14 +208,14 @@ describe('step scaling policy', () => {
});

// THEN
expect(stack).toHaveResourceLike('AWS::ApplicationAutoScaling::ScalingPolicy', {
Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', {
PolicyType: 'StepScaling',
StepScalingPolicyConfiguration: {
AdjustmentType: 'ChangeInCapacity',
MetricAggregationType: 'Maximum',
},
});
expect(stack).toHaveResource('AWS::CloudWatch::Alarm', {
Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', {
ComparisonOperator: 'GreaterThanOrEqualToThreshold',
EvaluationPeriods: 10,
ExtendedStatistic: 'p99',
Expand Down Expand Up @@ -247,14 +246,14 @@ describe('step scaling policy', () => {
});

// THEN
expect(stack).toHaveResourceLike('AWS::ApplicationAutoScaling::ScalingPolicy', {
Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', {
PolicyType: 'StepScaling',
StepScalingPolicyConfiguration: {
AdjustmentType: 'ChangeInCapacity',
MetricAggregationType: 'Maximum',
},
});
expect(stack).toHaveResource('AWS::CloudWatch::Alarm', {
Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', {
ComparisonOperator: 'GreaterThanOrEqualToThreshold',
EvaluationPeriods: 10,
DatapointsToAlarm: 6,
Expand Down Expand Up @@ -297,7 +296,7 @@ function setupStepScaling(intervals: appscaling.ScalingInterval[]) {
scalingSteps: intervals,
});

return new ScalingStackTemplate(SynthUtils.synthesize(stack).template);
return new ScalingStackTemplate(Template.fromStack(stack).toJSON());
}

class ScalingStackTemplate {
Expand Down
Loading

0 comments on commit 3184f45

Please sign in to comment.