Skip to content

Commit ef1ea91

Browse files
[8.x] [Spaces] Add defaultSolution to spaces config (elastic#218360) (elastic#218485)
# Backport This will backport the following commits from `main` to `8.x`: - [[Spaces] Add defaultSolution to spaces config (elastic#218360)](elastic#218360) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Krzysztof Kowalczyk","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-16T17:22:10Z","message":"[Spaces] Add defaultSolution to spaces config (elastic#218360)\n\n## Summary\n\nThis PR adds new config option `defaultSolution`\n(`xpack.spaces.defaultSolution`) which lets you specify a default\nsolution, similar to the way cloud plugin does it.\n\nAddresses: elastic#213144","sha":"31f0f211d9d76fc757adaff91e41f94bafbacfb4","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Security","enhancement","Feature:Security/Spaces","backport:version","v9.1.0","v8.19.0"],"title":"[Spaces] Add defaultSolution to spaces config","number":218360,"url":"https://github.com/elastic/kibana/pull/218360","mergeCommit":{"message":"[Spaces] Add defaultSolution to spaces config (elastic#218360)\n\n## Summary\n\nThis PR adds new config option `defaultSolution`\n(`xpack.spaces.defaultSolution`) which lets you specify a default\nsolution, similar to the way cloud plugin does it.\n\nAddresses: elastic#213144","sha":"31f0f211d9d76fc757adaff91e41f94bafbacfb4"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/218360","number":218360,"mergeCommit":{"message":"[Spaces] Add defaultSolution to spaces config (elastic#218360)\n\n## Summary\n\nThis PR adds new config option `defaultSolution`\n(`xpack.spaces.defaultSolution`) which lets you specify a default\nsolution, similar to the way cloud plugin does it.\n\nAddresses: elastic#213144","sha":"31f0f211d9d76fc757adaff91e41f94bafbacfb4"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Krzysztof Kowalczyk <[email protected]>
1 parent 95e63f8 commit ef1ea91

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

x-pack/platform/plugins/shared/spaces/server/config.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,12 @@ describe('config schema', () => {
9696
)
9797
).toThrow();
9898
});
99+
100+
it('should not throw error if defaultSolution uses valid value', () => {
101+
expect(() => ConfigSchema.validate({ defaultSolution: 'es' })).not.toThrow();
102+
});
103+
104+
it('should throw error if defaultSolution uses invalid value', () => {
105+
expect(() => ConfigSchema.validate({ defaultSolution: 'test' })).toThrow();
106+
});
99107
});

x-pack/platform/plugins/shared/spaces/server/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import type { Observable } from 'rxjs';
1010
import type { TypeOf } from '@kbn/config-schema';
1111
import { offeringBasedSchema, schema } from '@kbn/config-schema';
1212
import type { PluginInitializerContext } from '@kbn/core/server';
13+
import type { SolutionId } from '@kbn/core-chrome-browser';
14+
15+
const solutions = ['es', 'oblt', 'security'] as const;
16+
17+
const solutionSchemaLiterals = [...solutions].map((s) => schema.literal(s)) as [
18+
ReturnType<typeof schema.literal<Exclude<SolutionId, 'chat'>>>
19+
];
1320

1421
export const ConfigSchema = schema.object({
1522
enabled: schema.conditional(
@@ -54,6 +61,7 @@ export const ConfigSchema = schema.object({
5461
defaultValue: true,
5562
}),
5663
}),
64+
defaultSolution: schema.maybe(schema.oneOf(solutionSchemaLiterals)),
5765
});
5866

5967
export function createConfig$(context: PluginInitializerContext) {

x-pack/platform/plugins/shared/spaces/server/plugin.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('Spaces plugin', () => {
8282
expect(usageCollection.getCollectorByType('spaces')).toBeDefined();
8383
});
8484

85-
it('can setup space with default solution', async () => {
85+
it('can setup space with default solution for cloud', async () => {
8686
const initializerContext = coreMock.createPluginInitializerContext({ maxSpaces: 1000 });
8787
const core = coreMock.createSetup() as CoreSetup<PluginsStart>;
8888
const features = featuresPluginMock.createSetup();
@@ -100,6 +100,23 @@ describe('Spaces plugin', () => {
100100
expect.objectContaining({ solution: 'security' })
101101
);
102102
});
103+
104+
it('can setup space with default solution for onprem', async () => {
105+
const initializerContext = coreMock.createPluginInitializerContext({
106+
maxSpaces: 1000,
107+
defaultSolution: 'oblt',
108+
});
109+
const core = coreMock.createSetup() as CoreSetup<PluginsStart>;
110+
const features = featuresPluginMock.createSetup();
111+
const licensing = licensingMock.createSetup();
112+
113+
const plugin = new SpacesPlugin(initializerContext);
114+
plugin.setup(core, { features, licensing });
115+
116+
expect(createDefaultSpace).toHaveBeenCalledWith(
117+
expect.objectContaining({ solution: 'oblt' })
118+
);
119+
});
103120
});
104121

105122
describe('#start', () => {

x-pack/platform/plugins/shared/spaces/server/plugin.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import type { Observable } from 'rxjs';
9-
import { map } from 'rxjs';
9+
import { map, take } from 'rxjs';
1010

1111
import type { CloudSetup } from '@kbn/cloud-plugin/server';
1212
import type {
@@ -155,14 +155,20 @@ export class SpacesPlugin
155155

156156
const { license } = this.spacesLicenseService.setup({ license$: plugins.licensing.license$ });
157157

158+
let defaultSolution;
159+
160+
this.config$.pipe(take(1)).subscribe((config) => {
161+
defaultSolution = config.defaultSolution;
162+
});
163+
158164
this.defaultSpaceService = new DefaultSpaceService();
159165
this.defaultSpaceService.setup({
160166
coreStatus: core.status,
161167
getSavedObjects: async () => (await core.getStartServices())[0].savedObjects,
162168
license$: plugins.licensing.license$,
163169
spacesLicense: license,
164170
logger: this.log,
165-
solution: plugins.cloud?.onboarding?.defaultSolution,
171+
solution: plugins.cloud?.onboarding?.defaultSolution || defaultSolution,
166172
});
167173

168174
initSpacesViewsRoutes({

0 commit comments

Comments
 (0)