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

Added feature to pass additional cluster settings from command line. #21

Merged
merged 3 commits into from
Mar 28, 2023

Conversation

rishabh6788
Copy link
Collaborator

Description

Added feature to pass additional cluster settings from command line.

Issues Resolved

List any issues this PR will resolve, e.g. Closes [...].

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

lib/infra/infra-stack.ts Show resolved Hide resolved
lib/infra/infra-stack.ts Show resolved Hide resolved
// @ts-ignore
if (props.additionalConfig.toString() !== 'undefined') {
// @ts-ignore
cfnInitConfig.push(InitCommand.shellCommand(`set -ex; cd opensearch; additionalConfig=$(echo "${props.additionalConfig.toString()}" | tr ',' '\\n');`
Copy link
Collaborator

Choose a reason for hiding this comment

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

As @gaiksaya If we have an array we can remove all this shell logic.
Thank you

const jsonObj = JSON.parse(osConfig);
ymlConfig = dump(jsonObj);
} catch (e) {
throw new Error(`Encountered following error parsing json: ${e}`);
Copy link
Member

Choose a reason for hiding this comment

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

nit: Error(`Encountered following error parsing json from additionalConfig: ${e}`);

Would make it easier for user to troubleshoot instead trying to figure out what json is wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

didn't understand this. This is just catching exception in case the json is not valid. @gaiksaya

Comment on lines 160 to 169
describe('JSON input validation', () => {
test('valid JSON input should parse successfully', () => {
expect(() => JSON.parse(validJson)).not.toThrow();
});

test('invalid JSON input should throw an error', () => {
const invalidJson = '{name: "John", age: 30}';
expect(() => JSON.parse(invalidJson)).toThrow();
});
});
Copy link
Member

Choose a reason for hiding this comment

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

Test the additionalConfig value here. Not the validJson since the validation already happened inside the code. @prudhvigodithi WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Couldn't find a way to access the context variable from stack properties. So adding test at parameter level made more sense.

Copy link
Member

@gaiksaya gaiksaya Mar 28, 2023

Choose a reason for hiding this comment

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

${props.additionalConfig}" is accessible I believe? Since we are using the same here: https://github.com/opensearch-project/opensearch-cluster-cdk/pull/21/files#diff-d7c4924379311512de5d5b043d465129d2b5fb1254d7a08737f2e3f9b1c13f64R474

Point is this test case won't test any code. It is directly calling JSON.parse which does not provide any value here.

Signed-off-by: Rishabh Singh <sngri@amazon.com>
@rishabh6788 rishabh6788 merged commit 5307477 into opensearch-project:main Mar 28, 2023
@opensearch-trigger-bot
Copy link

The backport to 1.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/backport-1.x 1.x
# Navigate to the new working tree
pushd ../.worktrees/backport-1.x
# Create a new branch
git switch --create backport/backport-21-to-1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 5307477e40d3c620aac3a4c7051f60ad59537bb5
# Push it to GitHub
git push --set-upstream origin backport/backport-21-to-1.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/backport-1.x

Then, create a pull request where the base branch is 1.x and the compare/head branch is backport/backport-21-to-1.x.

rishabh6788 added a commit that referenced this pull request Oct 24, 2023
…21)

* make OSD optional and other minor improvements

Signed-off-by: Rishabh Singh <sngri@amazon.com>

* Feature to pass additional cluster settings from command line

Signed-off-by: Rishabh Singh <sngri@amazon.com>

---------

Signed-off-by: Rishabh Singh <sngri@amazon.com>
(cherry picked from commit 5307477)
rishabh6788 added a commit that referenced this pull request Oct 24, 2023
…21)

* make OSD optional and other minor improvements

Signed-off-by: Rishabh Singh <sngri@amazon.com>

* Feature to pass additional cluster settings from command line

Signed-off-by: Rishabh Singh <sngri@amazon.com>

---------

Signed-off-by: Rishabh Singh <sngri@amazon.com>
(cherry picked from commit 5307477)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants