Skip to content

Commit

Permalink
feat(msk-alpha): new KafkaVersions 3_7_X and 3_7_X_KRAFT (aws#32515)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

None

### Reason for this change

Update the CDK listed Kafka versions to match the current availability, as well as add missing deprecated versions

### Description of changes

Even though there is a Metadata mode input in the web console (see [announcement](https://aws.amazon.com/blogs/big-data/introducing-support-for-apache-kafka-on-raft-mode-kraft-with-amazon-msk-clusters/)), there doesn't seem to be any associated fields, and the metadata mode is only dictated by the selected version according to the [docs](https://docs.aws.amazon.com/msk/latest/developerguide/metadata-management.html#kraft-intro):

> To create a cluster in KRaft mode using the MSK API CreateCluster or CreateClusterV2 operations, you should use 3.7.x.kraft as the version. Use 3.7.x as the version to create a cluster in ZooKeeper mode.

Given this, I don't see a reason to add a field to the `KafkaVersion` class to differentiate between the ZooKeeper and KRaft mode. This may easily be added in the future if needed.

I've also refactored the tiered array to increase maintainability and align it with other version classes, such as the RDS `EngineVersion`s. See [docs](https://docs.aws.amazon.com/msk/latest/developerguide/msk-tiered-storage.html#msk-tiered-storage-requirements) for supported versions:

> The Amazon MSK cluster with tiered storage enabled must use version 3.6.0 or higher, or 2.8.2.tiered.

I don't think it's worth parsing the version to automatically determine the tiered storage support, as we already have non-semver versions and support may be dropped for future versions.


### Description of how you validated changes

I compared the current CDK versions to live SDK data, using the `kafka:ListKafkaVersions` API results, and updated the cluster version integration

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
nmussy authored Dec 19, 2024
1 parent dc1647e commit cbacf4d
Show file tree
Hide file tree
Showing 11 changed files with 437 additions and 519 deletions.
60 changes: 43 additions & 17 deletions packages/@aws-cdk/aws-msk-alpha/lib/cluster-version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/**
* Available features for a given Kafka version
*/
export interface KafkaVersionFeatures {
/**
* Whether the Kafka version supports tiered storage mode.
*
* @see https://docs.aws.amazon.com/msk/latest/developerguide/msk-tiered-storage.html#msk-tiered-storage-requirements
* @default false
*/
readonly tieredStorage?: boolean;
}

/**
* Kafka cluster version
*/
Expand All @@ -22,11 +35,15 @@ export class KafkaVersion {

/**
* Kafka version 2.2.1
*
* @deprecated use the latest runtime instead
*/
public static readonly V2_2_1 = KafkaVersion.of('2.2.1');

/**
* Kafka version 2.3.1
*
* @deprecated use the latest runtime instead
*/
public static readonly V2_3_1 = KafkaVersion.of('2.3.1');

Expand All @@ -40,12 +57,16 @@ export class KafkaVersion {
public static readonly V2_4_1 = KafkaVersion.of('2.4.1');

/**
* Kafka version 2.4.1
* Kafka version 2.4.1.1
*
* @deprecated use the latest runtime instead
*/
public static readonly V2_4_1_1 = KafkaVersion.of('2.4.1.1');

/**
* Kafka version 2.5.1
*
* @deprecated use the latest runtime instead
*/
public static readonly V2_5_1 = KafkaVersion.of('2.5.1');

Expand Down Expand Up @@ -97,7 +118,7 @@ export class KafkaVersion {
/**
* AWS MSK Kafka version 2.8.2.tiered
*/
public static readonly V2_8_2_TIERED = KafkaVersion.of('2.8.2.tiered');
public static readonly V2_8_2_TIERED = KafkaVersion.of('2.8.2.tiered', { tieredStorage: true });

/**
* Kafka version 3.1.1
Expand Down Expand Up @@ -132,36 +153,41 @@ export class KafkaVersion {
/**
* Kafka version 3.6.0
*/
public static readonly V3_6_0 = KafkaVersion.of('3.6.0');
public static readonly V3_6_0 = KafkaVersion.of('3.6.0', { tieredStorage: true });

/**
* Custom cluster version
* @param version custom version number
* Kafka version 3.7.x with ZooKeeper metadata mode support
*
* @see https://docs.aws.amazon.com/msk/latest/developerguide/metadata-management.html#msk-get-connection-string
*/
public static of(version: string) {
return new KafkaVersion(version);
}
public static readonly V3_7_X = KafkaVersion.of('3.7.x', { tieredStorage: true });

/**
* List of Kafka versions that support tiered storage
* Kafka version 3.7.x with KRaft (Apache Kafka Raft) metadata mode support
*
* @see https://docs.aws.amazon.com/msk/latest/developerguide/msk-tiered-storage.html#msk-tiered-storage-requirements
* @see https://docs.aws.amazon.com/msk/latest/developerguide/metadata-management.html#kraft-intro
*/
private static readonly TIERED_STORAGE_COMPATIBLE_VERSIONS = [
KafkaVersion.V2_8_2_TIERED,
KafkaVersion.V3_6_0,
].map(({ version }) => version);
public static readonly V3_7_X_KRAFT = KafkaVersion.of('3.7.x.kraft', { tieredStorage: true });

/**
* Custom cluster version
* @param version custom version number
*/
public static of(version: string, features?: KafkaVersionFeatures) {
return new KafkaVersion(version, features);
}

/**
*
* @param version cluster version number
* @param features features for the cluster version
*/
private constructor(public readonly version: string) {}
private constructor(public readonly version: string, public readonly features?: KafkaVersionFeatures) {}

/**
* Checks if the cluster version supports tiered storage mode.
*/
public isTieredStorageCompatible() {
return KafkaVersion.TIERED_STORAGE_COMPATIBLE_VERSIONS.includes(this.version);
public isTieredStorageCompatible(): boolean {
return this.features?.tieredStorage ?? false;
};
}
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-msk-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ export class Cluster extends ClusterBase {
);
}

let clientAuthentication;
let clientAuthentication: CfnCluster.ClientAuthenticationProperty | undefined;
if (props.clientAuthentication?.saslProps?.iam) {
clientAuthentication = {
sasl: { iam: { enabled: props.clientAuthentication.saslProps.iam } },
Expand Down Expand Up @@ -747,7 +747,7 @@ export class Cluster extends ClusterBase {
openMonitoring: openMonitoring,
storageMode: props.storageMode,
loggingInfo: loggingInfo,
clientAuthentication: clientAuthentication,
clientAuthentication,
});

this.clusterName = this.getResourceNameAttribute(
Expand Down
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-msk-alpha/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ describe('MSK Cluster', () => {
[msk.KafkaVersion.V3_3_2, '3.3.2'],
[msk.KafkaVersion.V3_4_0, '3.4.0'],
[msk.KafkaVersion.V3_5_1, '3.5.1'],
[msk.KafkaVersion.V3_6_0, '3.6.0'],
[msk.KafkaVersion.V3_7_X, '3.7.x'],
[msk.KafkaVersion.V3_7_X_KRAFT, '3.7.x.kraft'],
],
)('created with expected Kafka version %j', (parameter, result) => {
new msk.Cluster(stack, 'Cluster', {
Expand Down Expand Up @@ -794,6 +797,8 @@ describe('MSK Cluster', () => {
expect(msk.KafkaVersion.V2_8_2_TIERED.isTieredStorageCompatible()).toBeTruthy();
expect(msk.KafkaVersion.V3_5_1.isTieredStorageCompatible()).toBeFalsy();
expect(msk.KafkaVersion.V3_6_0.isTieredStorageCompatible()).toBeTruthy();
expect(msk.KafkaVersion.V3_7_X.isTieredStorageCompatible()).toBeTruthy();
expect(msk.KafkaVersion.V3_7_X_KRAFT.isTieredStorageCompatible()).toBeTruthy();
});

test('create a cluster with tiered storage mode', () => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cbacf4d

Please sign in to comment.