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

Extend yarn es: plugin support + adding secure files to es keystore #126938

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions packages/kbn-es/src/cli_commands/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ exports.help = (defaults = {}) => {
--use-cached Skips cache verification and use cached ES snapshot.
--skip-ready-check Disable the ready check,
--ready-timeout Customize the ready check timeout, in seconds or "Xm" format, defaults to 1m
--plugins Comma seperated list of Elasticsearch plugins to install
jbudz marked this conversation as resolved.
Show resolved Hide resolved
--secure-files Comma seperated list of secure_setting_name=/path pairs

Example:

Expand All @@ -58,6 +60,7 @@ exports.run = async (defaults = {}) => {
useCached: 'use-cached',
skipReadyCheck: 'skip-ready-check',
readyTimeout: 'ready-timeout',
secureFiles: 'secure-files',
},

string: ['version', 'ready-timeout'],
Expand All @@ -76,6 +79,14 @@ exports.run = async (defaults = {}) => {
if (options.dataArchive) {
await cluster.extractDataDirectory(installPath, options.dataArchive);
}
if (options.plugins) {
await cluster.installPlugins(installPath, options.plugins, options);
}
if (options.secureFiles) {
const pairs = options.secureFiles.split(',').map(kv=> kv.split('=').map(v=>v.trim()));
console.log(pairs);
spalger marked this conversation as resolved.
Show resolved Hide resolved
await cluster.configureKeystoreWithSecureSettingsFiles(installPath, pairs);
}

reportTime(installStartTime, 'installed', {
success: true,
Expand Down
11 changes: 11 additions & 0 deletions packages/kbn-es/src/cli_commands/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ exports.help = (defaults = {}) => {
--password Sets password for elastic user [default: ${password}]
--password.[user] Sets password for native realm user [default: ${password}]
--ssl Sets up SSL on Elasticsearch
--plugins Comma seperated list of Elasticsearch plugins to install
--secure-files Comma seperated list of secure_setting_name=/path pairs
-E Additional key=value settings to pass to Elasticsearch
--skip-ready-check Disable the ready check,
--ready-timeout Customize the ready check timeout, in seconds or "Xm" format, defaults to 1m
Expand All @@ -47,6 +49,7 @@ exports.run = async (defaults = {}) => {
dataArchive: 'data-archive',
skipReadyCheck: 'skip-ready-check',
readyTimeout: 'ready-timeout',
secureFiles: 'secure-files',
esArgs: 'E',
},

Expand All @@ -62,6 +65,14 @@ exports.run = async (defaults = {}) => {
if (options.dataArchive) {
await cluster.extractDataDirectory(installPath, options.dataArchive);
}
if (options.plugins) {
await cluster.installPlugins(installPath, options.plugins, options);
}
if (options.secureFiles) {
const pairs = options.secureFiles.split(',').map(kv=> kv.split('=').map(v=>v.trim()));
console.log(pairs);
Mpdreamz marked this conversation as resolved.
Show resolved Hide resolved
await cluster.configureKeystoreWithSecureSettingsFiles(installPath, pairs);
}

await cluster.run(installPath, {
...options,
Expand Down
68 changes: 56 additions & 12 deletions packages/kbn-es/src/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const chalk = require('chalk');
const path = require('path');
const { Client } = require('@elastic/elasticsearch');
const { downloadSnapshot, installSnapshot, installSource, installArchive } = require('./install');
const { ES_BIN } = require('./paths');
const { ES_BIN, ES_KEYSTORE_BIN } = require('./paths');
const {
log: defaultLog,
parseEsLog,
Expand Down Expand Up @@ -150,6 +150,46 @@ exports.Cluster = class Cluster {
});
}

/**
* Starts ES and returns resolved promise once started
*
* @param {String} installPath
* @param {String} plugins - comma separated list of plugins to install
* @param {Object} options
* @returns {Promise}
*/
async installPlugins(installPath, plugins, options) {
let esJavaOpts = this.javaOptions(options);
for (const plugin in plugins.split(',')) {
await execa(ES_PLUGIN_BIN, ['install', plugins.trim()], {
Mpdreamz marked this conversation as resolved.
Show resolved Hide resolved
cwd: installPath,
env: {
...process.env,
spalger marked this conversation as resolved.
Show resolved Hide resolved
JAVA_HOME: '', // By default, we want to always unset JAVA_HOME so that the bundled JDK will be used
ES_JAVA_OPTS: esJavaOpts.trim(),
Mpdreamz marked this conversation as resolved.
Show resolved Hide resolved
}
});
}
}

async configureKeystoreWithSecureSettingsFiles(
installPath,
secureSettingsFiles
) {
const env = { JAVA_HOME: '' };
for (const [secureSettingName, secureSettingFile] of secureSettingsFiles) {
this._log.info(
`setting secure setting %s to %s`,
chalk.bold(secureSettingName),
chalk.bold(secureSettingFile)
);
await execa(ES_KEYSTORE_BIN, ['add-file', secureSettingName, secureSettingFile], {
cwd: installPath,
env,
});
}
}

/**
* Starts ES and returns resolved promise once started
*
Expand Down Expand Up @@ -280,17 +320,7 @@ exports.Cluster = class Cluster {
);

this._log.info('%s %s', ES_BIN, args.join(' '));

let esJavaOpts = `${options.esJavaOpts || ''} ${process.env.ES_JAVA_OPTS || ''}`;

// ES now automatically sets heap size to 50% of the machine's available memory
// so we need to set it to a smaller size for local dev and CI
// especially because we currently run many instances of ES on the same machine during CI
// inital and max must be the same, so we only need to check the max
if (!esJavaOpts.includes('Xmx')) {
// 1536m === 1.5g
esJavaOpts += ' -Xms1536m -Xmx1536m';
}
let esJavaOpts = this.javaOptions(options);

this._log.info('ES_JAVA_OPTS: %s', esJavaOpts.trim());

Expand Down Expand Up @@ -429,4 +459,18 @@ exports.Cluster = class Cluster {
}
}
}

javaOptions(options) {
let esJavaOpts = `${options.esJavaOpts || ''} ${process.env.ES_JAVA_OPTS || ''}`;

// ES now automatically sets heap size to 50% of the machine's available memory
// so we need to set it to a smaller size for local dev and CI
// especially because we currently run many instances of ES on the same machine during CI
// inital and max must be the same, so we only need to check the max
if (!esJavaOpts.includes('Xmx')) {
// 1536m === 1.5g
esJavaOpts += ' -Xms1536m -Xmx1536m';
}
return esJavaOpts;
spalger marked this conversation as resolved.
Show resolved Hide resolved
}
};
1 change: 1 addition & 0 deletions packages/kbn-es/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const BASE_PATH = Path.resolve(tempDir, 'kbn-es');

export const GRADLE_BIN = maybeUseBat('./gradlew');
export const ES_BIN = maybeUseBat('bin/elasticsearch');
export const ES_PLUGIN_BIN = maybeUseBat('bin/elasticsearch-plugin');
export const ES_CONFIG = 'config/elasticsearch.yml';

export const ES_KEYSTORE_BIN = maybeUseBat('./bin/elasticsearch-keystore');