Skip to content

feat(eks): add support for updating remote network configs in EKS Cluster resource #34390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@aws-sdk/client-ec2": "3.632.0",
"@aws-sdk/client-ecr": "3.632.0",
"@aws-sdk/client-ecs": "3.632.0",
"@aws-sdk/client-eks": "3.632.0",
"@aws-sdk/client-eks": "^3.779.0",
"@aws-sdk/client-kinesis": "3.632.0",
"@aws-sdk/client-kms": "3.632.0",
"@aws-sdk/client-lambda": "3.632.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class ClusterResourceHandler extends ResourceHandler {
return this.updateClusterVersion(this.newProps.version);
}

if (updates.updateLogging || updates.updateAccess || updates.updateVpc || updates.updateAuthMode) {
if (updates.updateLogging || updates.updateAccess || updates.updateVpc || updates.updateAuthMode || updates.updateRemoteNetworkConfig) {
const config: EKS.UpdateClusterConfigCommandInput = {
name: this.clusterName,
};
Expand Down Expand Up @@ -262,6 +262,13 @@ export class ClusterResourceHandler extends ResourceHandler {
};
}

if (updates.updateRemoteNetworkConfig) {
config.remoteNetworkConfig = {
remoteNodeNetworks: this.newProps.remoteNetworkConfig?.remoteNodeNetworks,
remotePodNetworks: this.newProps.remoteNetworkConfig?.remotePodNetworks,
};
}

const updateResponse = await this.eks.updateClusterConfig(config);

return { EksUpdateId: updateResponse.update?.id };
Expand Down Expand Up @@ -415,6 +422,7 @@ interface UpdateMap {
updateBootstrapClusterCreatorAdminPermissions: boolean; // accessConfig.bootstrapClusterCreatorAdminPermissions
updateVpc: boolean; // resourcesVpcConfig.subnetIds and securityGroupIds
updateTags: boolean; // tags
updateRemoteNetworkConfig: boolean; // remoteNetworkConfig
}

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

const oldRemoteNetworkConfig = oldProps.remoteNetworkConfig || {};
const newRemoteNetworkConfig = newProps.remoteNetworkConfig || {};

return {
replaceName: newProps.name !== oldProps.name,
updateVpc:
Expand All @@ -448,6 +459,7 @@ function analyzeUpdate(oldProps: Partial<EKS.CreateClusterCommandInput>, newProp
updateBootstrapClusterCreatorAdminPermissions: JSON.stringify(newAccessConfig.bootstrapClusterCreatorAdminPermissions) !==
JSON.stringify(oldAccessConfig.bootstrapClusterCreatorAdminPermissions),
updateTags: JSON.stringify(newProps.tags) !== JSON.stringify(oldProps.tags),
updateRemoteNetworkConfig: !compareRemoteNetworkConfigs(oldRemoteNetworkConfig, newRemoteNetworkConfig),
};
}

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

return missingKeys;
}

function compareRemoteNetworkConfigs(
oldConfig?: EKS.RemoteNetworkConfigRequest | undefined,
newConfig?: EKS.RemoteNetworkConfigRequest | undefined,
): boolean {
if (!oldConfig && !newConfig) {
return true;
}

if (!oldConfig || !newConfig) {
return false;
}

const nodeNetworksEqual = compareNetworkArrays(
oldConfig.remoteNodeNetworks,
newConfig.remoteNodeNetworks,
);

const podNetworksEqual = compareNetworkArrays(
oldConfig.remotePodNetworks,
newConfig.remotePodNetworks,
);

return nodeNetworksEqual && podNetworksEqual;
}

function compareNetworkArrays(
oldNetworks?: (EKS.RemoteNodeNetwork | EKS.RemotePodNetwork)[] | undefined,
newNetworks?: (EKS.RemoteNodeNetwork | EKS.RemotePodNetwork)[] | undefined,
): boolean {
if (!oldNetworks && !newNetworks) {
return true;
}

if (!oldNetworks || !newNetworks) {
return false;
}

if (oldNetworks.length !== newNetworks.length) {
return false;
}

const oldCidrs = oldNetworks.flatMap(network => network.cidrs || []).sort();
const newCidrs = newNetworks.flatMap(network => network.cidrs || []).sort();

if (oldCidrs.length !== newCidrs.length) {
return false;
}

return oldCidrs.every((cidr, index) => cidr === newCidrs[index]);
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/custom-resource-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@aws-sdk/client-route-53": "3.632.0",
"@aws-sdk/client-cloudwatch-logs": "3.632.0",
"@aws-sdk/client-dynamodb": "3.632.0",
"@aws-sdk/client-eks": "3.632.0",
"@aws-sdk/client-eks": "^3.779.0",
"@aws-sdk/client-sts": "3.632.0",
"@smithy/node-http-handler": "3.3.3",
"@smithy/util-stream": "3.3.4",
Expand Down
Loading
Loading