Skip to content

Commit

Permalink
Merge pull request #892 from vineetjp/feature/custom-cni-sgid
Browse files Browse the repository at this point in the history
Provision add custom security group to secondary eni in vpc cni addon custom networking
  • Loading branch information
shapirov103 authored Dec 18, 2023
2 parents 3667d52 + 8d7530d commit 0e27d32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/addons/vpc-cni/eniConfig.ytpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ metadata:
name: "{{availabilityZone}}"
spec:
securityGroups:
- "{{clusterSecurityGroupId}}"
- "{{securityGroupId}}"
subnet: "{{subnetId}}"
14 changes: 11 additions & 3 deletions lib/addons/vpc-cni/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ISubnet } from "aws-cdk-lib/aws-ec2";
import { ISecurityGroup, ISubnet } from "aws-cdk-lib/aws-ec2";
import * as eks from "aws-cdk-lib/aws-eks";
import * as iam from "aws-cdk-lib/aws-iam";
import { Construct } from 'constructs';
Expand Down Expand Up @@ -295,6 +295,10 @@ export interface CustomNetworkingConfig {
* Secondary subnets of your VPC
*/
readonly subnets?: ISubnet[];
/**
* Security group of secondary ENI
*/
readonly securityGroup?: ISecurityGroup;
}

const defaultProps: CoreAddOnProps = {
Expand Down Expand Up @@ -323,15 +327,19 @@ export class VpcCniAddOn extends CoreAddOn {

deploy(clusterInfo: ClusterInfo): Promise<Construct> {
const cluster = clusterInfo.cluster;
let clusterSecurityGroupId = cluster.clusterSecurityGroupId;
let securityGroupId = cluster.clusterSecurityGroupId;

if (this.vpcCniAddOnProps.customNetworkingConfig?.securityGroup) {
securityGroupId = this.vpcCniAddOnProps.customNetworkingConfig.securityGroup.securityGroupId;
}

if ((this.vpcCniAddOnProps.customNetworkingConfig?.subnets)) {
for (let subnet of this.vpcCniAddOnProps.customNetworkingConfig.subnets) {
const doc = readYamlDocument(__dirname + '/eniConfig.ytpl');
const manifest = doc.split("---").map(e => loadYaml(e));
const values: Values = {
availabilityZone: subnet.availabilityZone,
clusterSecurityGroupId: clusterSecurityGroupId,
securityGroupId: securityGroupId,
subnetId: subnet.subnetId
};
const manifestDeployment: ManifestDeployment = {
Expand Down

0 comments on commit 0e27d32

Please sign in to comment.