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

Add option to create internal NLB #25

Merged
merged 1 commit into from
May 5, 2023
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ In order to deploy both the stacks the user needs to provide a set of required a
| account (Optional) | string | User provided aws account |
| dataNodeStorage (Optional) | string | User provided ebs block storage size, defaults to 100Gb |
| mlNodeStorage (Optional) | string | User provided ebs block storage size, defaults to 100Gb |
| use50PercentHeap (Optional) | boolean | Boolean flag to use 50% of physical memory as heap. Default is 1GB. e.g., `--context use50PercentHeap=true` |
| use50PercentHeap (Optional) | boolean | Boolean flag to use 50% of physical memory as heap. Default is 1GB. e.g., `--context use50PercentHeap=true` |
| isInternal (Optional) | boolean | Boolean flag to make network load balancer internal. Default is internet-facing e.g., `--context isInternal=true` |



Expand Down
13 changes: 7 additions & 6 deletions lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
readonly jvmSysPropsString?: string,
readonly additionalConfig?: string,
readonly use50PercentHeap: boolean,
readonly isInternal: boolean,
}

export class InfraStack extends Stack {
Expand Down Expand Up @@ -86,33 +87,33 @@
const ec2InstanceType = (props.cpuType === AmazonLinuxCpuType.X86_64)
? InstanceType.of(InstanceClass.C5, InstanceSize.XLARGE) : InstanceType.of(InstanceClass.C6G, InstanceSize.XLARGE);

const alb = new NetworkLoadBalancer(this, 'publicNlb', {
const nlb = new NetworkLoadBalancer(this, 'clusterNlb', {
vpc: props.vpc,
internetFacing: true,
internetFacing: (!props.isInternal),
crossZoneEnabled: true,
});

if (!props.securityDisabled && !props.minDistribution) {
opensearchListener = alb.addListener('opensearch', {
opensearchListener = nlb.addListener('opensearch', {
port: 443,
protocol: Protocol.TCP,
});
} else {
opensearchListener = alb.addListener('opensearch', {
opensearchListener = nlb.addListener('opensearch', {
port: 80,
protocol: Protocol.TCP,
});
}

if (props.dashboardsUrl !== 'undefined') {
dashboardsListener = alb.addListener('dashboards', {
dashboardsListener = nlb.addListener('dashboards', {
port: 8443,
protocol: Protocol.TCP,
});
}

if (props.singleNodeCluster) {
console.log('Single node value is true, creating single node configurations');

Check warning on line 116 in lib/infra/infra-stack.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
singleNodeInstance = new Instance(this, 'single-node-instance', {
vpc: props.vpc,
instanceType: ec2InstanceType,
Expand Down Expand Up @@ -325,7 +326,7 @@
}

new CfnOutput(this, 'loadbalancer-url', {
value: alb.loadBalancerDnsName,
value: nlb.loadBalancerDnsName,
});
}

Expand Down Expand Up @@ -408,7 +409,7 @@

fileContent['cluster.name'] = `${scope.stackName}-${scope.account}-${scope.region}`;

console.log(dump(fileContent).toString());

Check warning on line 412 in lib/infra/infra-stack.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
opensearchConfig = dump(fileContent).toString();
cfnInitConfig.push(InitCommand.shellCommand(`set -ex;cd opensearch; echo "${opensearchConfig}" > config/opensearch.yml`,
{
Expand Down
4 changes: 4 additions & 0 deletions lib/os-cluster-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ export class OsClusterEntrypoint {
const use50heap = `${scope.node.tryGetContext('use50PercentHeap')}`;
const use50PercentHeap = use50heap === 'true';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rishabh6788 , where are we using this use50PercentHeap value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is optional parameter, processed here. @prudhvigodithi

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was included due to formatting fix.


const nlbScheme = `${scope.node.tryGetContext('isInternal')}`;
const isInternal = nlbScheme === 'true';

const network = new NetworkStack(scope, 'opensearch-network-stack', {
cidrBlock: cidrRange,
maxAzs: 3,
Expand Down Expand Up @@ -196,6 +199,7 @@ export class OsClusterEntrypoint {
jvmSysPropsString: jvmSysProps,
additionalConfig: ymlConfig,
use50PercentHeap,
isInternal,
...props,
});

Expand Down
7 changes: 7 additions & 0 deletions test/os-cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ test('Test Resources with security enabled multi-node with existing Vpc', () =>
},
],
});
infraTemplate.hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
Scheme: 'internet-facing',
});
});

test('Test Resources with security enabled single-node cluster', () => {
Expand All @@ -121,6 +124,7 @@ test('Test Resources with security enabled single-node cluster', () => {
serverAccessType: 'prefixList',
restrictServerAccessTo: 'pl-12345',
dataNodeStorage: 200,
isInternal: true,
},
});

Expand Down Expand Up @@ -153,4 +157,7 @@ test('Test Resources with security enabled single-node cluster', () => {
},
],
});
infraTemplate.hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
Scheme: 'internal',
});
});
Loading