Skip to content
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

feat(eks): configure serviceIpv4Cidr on the cluster #16957

Merged
merged 3 commits into from
Oct 17, 2021
Merged
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
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-eks/lib/cluster-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ClusterResourceProps {
readonly resourcesVpcConfig: CfnCluster.ResourcesVpcConfigProperty;
readonly roleArn: string;
readonly encryptionConfig?: Array<CfnCluster.EncryptionConfigProperty>;
readonly kubernetesNetworkConfig?: CfnCluster.KubernetesNetworkConfigProperty;
readonly name: string;
readonly version?: string;
readonly endpointPrivateAccess: boolean;
Expand Down Expand Up @@ -78,6 +79,7 @@ export class ClusterResource extends CoreConstruct {
version: props.version,
roleArn: props.roleArn,
encryptionConfig: props.encryptionConfig,
kubernetesNetworkConfig: props.kubernetesNetworkConfig,
ayush987goyal marked this conversation as resolved.
Show resolved Hide resolved
resourcesVpcConfig: {
subnetIds: (props.resourcesVpcConfig as CfnCluster.ResourcesVpcConfigProperty).subnetIds,
securityGroupIds: (props.resourcesVpcConfig as CfnCluster.ResourcesVpcConfigProperty).securityGroupIds,
Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-eks/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,15 @@ export interface ClusterOptions extends CommonClusterOptions {
* using AWS-Managed encryption keys.
*/
readonly secretsEncryptionKey?: kms.IKey;

/**
* The CIDR block to assign Kubernetes service IP addresses from.
*
* @default - Kubernetes assigns addresses from either the
* 10.100.0.0/16 or 172.20.0.0/16 CIDR blocks
* @see https://docs.aws.amazon.com/eks/latest/APIReference/API_KubernetesNetworkConfigRequest.html#AmazonEKS-Type-KubernetesNetworkConfigRequest-serviceIpv4Cidr
*/
readonly serviceIpv4Cidr?: string;
}

/**
Expand Down Expand Up @@ -1223,6 +1232,9 @@ export class Cluster extends ClusterBase {
resources: ['secrets'],
}],
} : {}),
kubernetesNetworkConfig: props.serviceIpv4Cidr ? {
serviceIpv4Cidr: props.serviceIpv4Cidr,
} : undefined,
endpointPrivateAccess: this.endpointAccess._config.privateAccess,
endpointPublicAccess: this.endpointAccess._config.publicAccess,
publicAccessCidrs: this.endpointAccess._config.publicCidrs,
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-eks/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2888,4 +2888,26 @@ describe('cluster', () => {
expect(providerNestedStackTemplate?.Resources?.Handler886CB40B?.Properties?.MemorySize).toEqual(4096);

});

test('create a cluster using custom kubernetes network config', () => {
// GIVEN
const { stack } = testFixture();
const customCidr = '172.16.0.0/12';

// WHEN
new eks.Cluster(stack, 'Cluster', {
version: CLUSTER_VERSION,
serviceIpv4Cidr: customCidr,
});

// THEN
expect(stack).toHaveResourceLike('Custom::AWSCDK-EKS-Cluster', {
Config: {
kubernetesNetworkConfig: {
serviceIpv4Cidr: customCidr,
},
},
});

});
});