Skip to content

Commit 7f83288

Browse files
committed
Add support for updating remote network configs in EKS Cluster resource
1 parent 9684d50 commit 7f83288

File tree

6 files changed

+4361
-2436
lines changed

6 files changed

+4361
-2436
lines changed

packages/@aws-cdk/aws-custom-resource-sdk-adapter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@aws-sdk/client-ec2": "3.632.0",
3838
"@aws-sdk/client-ecr": "3.632.0",
3939
"@aws-sdk/client-ecs": "3.632.0",
40-
"@aws-sdk/client-eks": "3.632.0",
40+
"@aws-sdk/client-eks": "^3.779.0",
4141
"@aws-sdk/client-kinesis": "3.632.0",
4242
"@aws-sdk/client-kms": "3.632.0",
4343
"@aws-sdk/client-lambda": "3.632.0",

packages/@aws-cdk/custom-resource-handlers/lib/aws-eks/cluster-resource-handler/cluster.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export class ClusterResourceHandler extends ResourceHandler {
195195
return this.updateClusterVersion(this.newProps.version);
196196
}
197197

198-
if (updates.updateLogging || updates.updateAccess || updates.updateVpc || updates.updateAuthMode) {
198+
if (updates.updateLogging || updates.updateAccess || updates.updateVpc || updates.updateAuthMode || updates.updateRemoteNetworkConfig) {
199199
const config: EKS.UpdateClusterConfigCommandInput = {
200200
name: this.clusterName,
201201
};
@@ -262,6 +262,13 @@ export class ClusterResourceHandler extends ResourceHandler {
262262
};
263263
}
264264

265+
if (updates.updateRemoteNetworkConfig) {
266+
config.remoteNetworkConfig = {
267+
remoteNodeNetworks: this.newProps.remoteNetworkConfig?.remoteNodeNetworks,
268+
remotePodNetworks: this.newProps.remoteNetworkConfig?.remotePodNetworks,
269+
};
270+
}
271+
265272
const updateResponse = await this.eks.updateClusterConfig(config);
266273

267274
return { EksUpdateId: updateResponse.update?.id };
@@ -415,6 +422,7 @@ interface UpdateMap {
415422
updateBootstrapClusterCreatorAdminPermissions: boolean; // accessConfig.bootstrapClusterCreatorAdminPermissions
416423
updateVpc: boolean; // resourcesVpcConfig.subnetIds and securityGroupIds
417424
updateTags: boolean; // tags
425+
updateRemoteNetworkConfig: boolean; // remoteNetworkConfig
418426
}
419427

420428
function analyzeUpdate(oldProps: Partial<EKS.CreateClusterCommandInput>, newProps: EKS.CreateClusterCommandInput): UpdateMap {
@@ -431,6 +439,9 @@ function analyzeUpdate(oldProps: Partial<EKS.CreateClusterCommandInput>, newProp
431439
const newAccessConfig = newProps.accessConfig || {};
432440
const oldAccessConfig = oldProps.accessConfig || {};
433441

442+
const oldRemoteNetworkConfig = oldProps.remoteNetworkConfig || {};
443+
const newRemoteNetworkConfig = newProps.remoteNetworkConfig || {};
444+
434445
return {
435446
replaceName: newProps.name !== oldProps.name,
436447
updateVpc:
@@ -448,6 +459,7 @@ function analyzeUpdate(oldProps: Partial<EKS.CreateClusterCommandInput>, newProp
448459
updateBootstrapClusterCreatorAdminPermissions: JSON.stringify(newAccessConfig.bootstrapClusterCreatorAdminPermissions) !==
449460
JSON.stringify(oldAccessConfig.bootstrapClusterCreatorAdminPermissions),
450461
updateTags: JSON.stringify(newProps.tags) !== JSON.stringify(oldProps.tags),
462+
updateRemoteNetworkConfig: !compareRemoteNetworkConfigs(oldRemoteNetworkConfig, newRemoteNetworkConfig),
451463
};
452464
}
453465

@@ -482,3 +494,54 @@ function getTagsToRemove<T extends Record<string, string>>(oldTags: T, newTags:
482494

483495
return missingKeys;
484496
}
497+
498+
function compareRemoteNetworkConfigs(
499+
oldConfig?: EKS.RemoteNetworkConfigRequest | undefined,
500+
newConfig?: EKS.RemoteNetworkConfigRequest | undefined,
501+
): boolean {
502+
if (!oldConfig && !newConfig) {
503+
return true;
504+
}
505+
506+
if (!oldConfig || !newConfig) {
507+
return false;
508+
}
509+
510+
const nodeNetworksEqual = compareNetworkArrays(
511+
oldConfig.remoteNodeNetworks,
512+
newConfig.remoteNodeNetworks,
513+
);
514+
515+
const podNetworksEqual = compareNetworkArrays(
516+
oldConfig.remotePodNetworks,
517+
newConfig.remotePodNetworks,
518+
);
519+
520+
return nodeNetworksEqual && podNetworksEqual;
521+
}
522+
523+
function compareNetworkArrays(
524+
oldNetworks?: (EKS.RemoteNodeNetwork | EKS.RemotePodNetwork)[] | undefined,
525+
newNetworks?: (EKS.RemoteNodeNetwork | EKS.RemotePodNetwork)[] | undefined,
526+
): boolean {
527+
if (!oldNetworks && !newNetworks) {
528+
return true;
529+
}
530+
531+
if (!oldNetworks || !newNetworks) {
532+
return false;
533+
}
534+
535+
if (oldNetworks.length !== newNetworks.length) {
536+
return false;
537+
}
538+
539+
const oldCidrs = oldNetworks.flatMap(network => network.cidrs || []).sort();
540+
const newCidrs = newNetworks.flatMap(network => network.cidrs || []).sort();
541+
542+
if (oldCidrs.length !== newCidrs.length) {
543+
return false;
544+
}
545+
546+
return oldCidrs.every((cidr, index) => cidr === newCidrs[index]);
547+
}

packages/@aws-cdk/custom-resource-handlers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@aws-sdk/client-route-53": "3.632.0",
4242
"@aws-sdk/client-cloudwatch-logs": "3.632.0",
4343
"@aws-sdk/client-dynamodb": "3.632.0",
44-
"@aws-sdk/client-eks": "3.632.0",
44+
"@aws-sdk/client-eks": "^3.779.0",
4545
"@aws-sdk/client-sts": "3.632.0",
4646
"@smithy/node-http-handler": "3.3.3",
4747
"@smithy/util-stream": "3.3.4",

0 commit comments

Comments
 (0)