Skip to content

Commit

Permalink
[serverless] split serverless config files (#150616)
Browse files Browse the repository at this point in the history
We are currently expecting serverless environments to be broken up into
several different envs, this config structure allows us to customize the
config based on that environment without major modifications to the
config loading system.
  • Loading branch information
Spencer authored Feb 8, 2023
1 parent 375a863 commit 065dbe7
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ disabledPlugins
webpackstats.json
/config/*
!/config/kibana.yml
!/config/kibana.serverless.yml
!/config/README.md
!/config/serverless.yml
!/config/serverless.es.yml
!/config/serverless.oblt.yml
!/config/serverless.security.yml
!/config/node.options
coverage
selenium
Expand Down
13 changes: 13 additions & 0 deletions config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
as work on serverless picks up we will add config values to these files that
define how Kibana will run in "serverless" modes. To start Kibana locally with
this configuration, pass `--serverless={mode}` or run `yarn serverless-{mode}`

valid modes are currently: `es`, `oblt`, and `security`

configuration is applied in the following order, later values override
1. kibana.yml
2. serverless.yml
3. serverless.{mode}.yml
4. kibana.dev.yml
5. serverless.dev.yml
6. serverless.{mode}.dev.yml
9 changes: 0 additions & 9 deletions config/kibana.serverless.yml

This file was deleted.

Empty file added config/serverless.es.yml
Empty file.
Empty file added config/serverless.oblt.yml
Empty file.
Empty file added config/serverless.security.yml
Empty file.
Empty file added config/serverless.yml
Empty file.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
"lint:es": "node scripts/eslint",
"lint:style": "node scripts/stylelint",
"makelogs": "node scripts/makelogs",
"serverless-es": "node scripts/kibana --dev --serverless=es",
"serverless-oblt": "node scripts/kibana --dev --serverless=oblt",
"serverless-security": "node scripts/kibana --dev --serverless=security",
"spec_to_console": "node scripts/spec_to_console",
"start": "node scripts/kibana --dev",
"start-serverless": "node scripts/kibana --dev --serverless",
"storybook": "node scripts/storybook",
"test:ftr": "node scripts/functional_tests",
"test:ftr:runner": "node scripts/functional_test_runner",
Expand Down
35 changes: 30 additions & 5 deletions src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ import { getConfigPath, getConfigDirectory } from '@kbn/utils';
import { isKibanaDistributable } from '@kbn/repo-info';
import { readKeystore } from '../keystore/read_keystore';

/** @typedef {'es' | 'oblt' | 'security'} ServerlessProjectMode */
/** @type {ServerlessProjectMode[]} */
const VALID_SERVERLESS_PROJECT_MODE = ['es', 'oblt', 'security'];

/**
* @param {Record<string, unknown>} opts
* @returns {ServerlessProjectMode | null}
*/
function getServerlessProjectMode(opts) {
if (!opts.serverless) {
return null;
}

if (VALID_SERVERLESS_PROJECT_MODE.includes(opts.serverless)) {
return opts.serverless;
}

throw new Error(
`invalid --serverless value, must be one of ${VALID_SERVERLESS_PROJECT_MODE.join(', ')}`
);
}

function canRequire(path) {
try {
require.resolve(path);
Expand Down Expand Up @@ -212,7 +234,7 @@ export default function (program) {
'--run-examples',
'Adds plugin paths for all the Kibana example plugins and runs with no base path'
)
.option('--serverless', 'Start Kibana with serverless configuration overrides');
.option('--serverless <oblt|security|es>', 'Start Kibana in a serverless project mode');
}

if (DEV_MODE_SUPPORTED) {
Expand All @@ -237,17 +259,20 @@ export default function (program) {
command.action(async function (opts) {
const unknownOptions = this.getUnknownOptions();
const configs = [getConfigPath(), ...getEnvConfigs(), ...(opts.config || [])];
const serverlessMode = getServerlessProjectMode(opts);

// we "unshift" .serverless. config so that it only overrides defaults
if (opts.serverless) {
maybeAddConfig('kibana.serverless.yml', configs, 'unshift');
if (serverlessMode) {
maybeAddConfig(`serverless.yml`, configs, 'push');
maybeAddConfig(`serverless.${serverlessMode}.yml`, configs, 'unshift');
}

// .dev. configs are "pushed" so that they override all other config files
if (opts.dev && opts.devConfig !== false) {
maybeAddConfig('kibana.dev.yml', configs, 'push');
if (opts.serverless) {
maybeAddConfig('kibana.serverless.dev.yml', configs, 'push');
if (serverlessMode) {
maybeAddConfig(`serverless.dev.yml`, configs, 'push');
maybeAddConfig(`serverless.${serverlessMode}.dev.yml`, configs, 'push');
}
}

Expand Down

0 comments on commit 065dbe7

Please sign in to comment.