Skip to content

Commit

Permalink
[kbn/es serverless] Fix teardown for CLI. Update help command (#166317)
Browse files Browse the repository at this point in the history
## Summary

- Fixes `--teardown` to work with events for CLI and FTR
- Adds missing flags to `--help`

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
Ikuni17 and kibanamachine authored Sep 13, 2023
1 parent 512b92e commit bc69490
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/kbn-es/src/cli_commands/serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ export const serverless: Command = {
--tag Image tag of ESS to run from ${SERVERLESS_REPO} [default: ${SERVERLESS_TAG}]
--image Full path of ESS image to run, has precedence over tag. [default: ${SERVERLESS_IMG}]
--background Start ESS without attaching to the first node's logs
--basePath Path to the directory where the ES cluster will store data
--clean Remove existing file system object store before running
--kill Kill running ESS nodes if detected on startup
--port The port to bind to on 127.0.0.1 [default: ${DEFAULT_PORT}]
--ssl Enable HTTP SSL on Elasticsearch
--kill Kill running ESS nodes if detected
--background Start ESS without attaching to the first node's logs
--teardown If this process exits, teardown the ES cluster as well
--waitForReady Wait for the ES cluster to be ready to serve requests
-E Additional key=value settings to pass to Elasticsearch
-F Absolute paths for files to mount into containers
Expand All @@ -60,8 +65,8 @@ export const serverless: Command = {
files: 'F',
},

string: ['tag', 'image'],
boolean: ['clean', 'ssl', 'kill', 'background'],
string: ['tag', 'image', 'basePath'],
boolean: ['clean', 'ssl', 'kill', 'background', 'teardown', 'waitForReady'],

default: defaults,
}) as unknown as ServerlessOptions;
Expand Down
13 changes: 13 additions & 0 deletions packages/kbn-es/src/utils/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,24 @@ export async function runServerlessCluster(log: ToolingLog, options: ServerlessO
log.success('ES is ready');
}

if (options.teardown) {
// SIGINT will not trigger in FTR (see cluster.runServerless for FTR signal)
process.on('SIGINT', () => teardownServerlessClusterSync(log, options));
}

if (!options.background) {
// The ESS cluster has to be started detached, so we attach a logger afterwards for output
await execa('docker', ['logs', '-f', SERVERLESS_NODES[0].name], {
// inherit is required to show Docker output and Java console output for pw, enrollment token, etc
stdio: ['ignore', 'inherit', 'inherit'],
}).catch((error) => {
/**
* 255 is a generic exit code which is triggered from docker logs command
* if we teardown the cluster since the entrypoint doesn't exit normally
*/
if (error.exitCode !== 255) {
log.error(error.message);
}
});
}

Expand Down

0 comments on commit bc69490

Please sign in to comment.