Skip to content

Commit

Permalink
[Fleet] Fix namespaces property of created agent policies
Browse files Browse the repository at this point in the history
  • Loading branch information
jillguyonnet committed Jul 25, 2024
1 parent ed74543 commit 771fd30
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ export interface FleetServerPolicy {
* The coordinator index of the policy
*/
coordinator_idx: number;
/**
* The namespaces of the policy
*/
namespaces?: string[];
/**
* The opaque payload.
*/
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/fleet/server/services/agent_policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ describe('Agent policy', () => {

describe('removeOutputFromAll', () => {
let mockedAgentPolicyServiceUpdate: jest.SpyInstance<
ReturnType<(typeof agentPolicyService)['update']>
ReturnType<typeof agentPolicyService['update']>
>;
beforeEach(() => {
mockedAgentPolicyServiceUpdate = jest
Expand Down Expand Up @@ -864,7 +864,7 @@ describe('Agent policy', () => {

describe('removeDefaultSourceFromAll', () => {
let mockedAgentPolicyServiceUpdate: jest.SpyInstance<
ReturnType<(typeof agentPolicyService)['update']>
ReturnType<typeof agentPolicyService['update']>
>;
beforeEach(() => {
mockedAgentPolicyServiceUpdate = jest
Expand Down Expand Up @@ -1269,6 +1269,7 @@ describe('Agent policy', () => {
soClient.bulkGet.mockResolvedValue({
saved_objects: [mockSo],
});
soClient.getCurrentNamespace.mockReturnValue('mySpace');
await agentPolicyService.deployPolicy(soClient, 'policy123');

expect(esClient.bulk).toBeCalledWith(
Expand All @@ -1286,6 +1287,7 @@ describe('Agent policy', () => {
default_fleet_server: false,
policy_id: 'policy123',
revision_idx: 1,
namespaces: ['mySpace'],
}),
],
refresh: 'wait_for',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ class AgentPolicyService {
'@timestamp': new Date().toISOString(),
revision_idx: fullPolicy.revision,
coordinator_idx: 0,
namespaces: fullPolicy.namespaces,
data: fullPolicy as unknown as FleetServerPolicy['data'],
policy_id: fullPolicy.id,
default_fleet_server: policy.is_default_fleet_server === true,
Expand Down

0 comments on commit 771fd30

Please sign in to comment.