[serverless] split serverless config files (#150616)

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.
This commit is contained in:
Spencer 2023-02-08 13:28:47 -07:00 committed by GitHub
parent 375a863349
commit 065dbe759c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 51 additions and 16 deletions

6
.gitignore vendored
View file

@ -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

13
config/README.md Normal file
View file

@ -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

View file

@ -1,9 +0,0 @@
# as work on serverless picks up we will add config values to this file that
# define how Kibana will run in "serverless" mode. To start Kibana locally with
# this configuration, pass `--serverless` or run `yarn start-serverless`
# configuration is applied in the following order, later values override
# 1. kibana.yml
# 2. kibana.serverless.yml (when --serverless is passed)
# 3. kibana.dev.yml
# 4. kibana.serverless.dev.yml (when --serverless is passed)

0
config/serverless.es.yml Normal file
View file

View file

View file

0
config/serverless.yml Normal file
View file

View file

@ -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",

View file

@ -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);
@ -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) {
@ -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');
}
}