-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In case of kubernetes integration detected return manifest in standalone agent layout instead of policy #114439
Merged
MichaelKatsoulis
merged 16 commits into
elastic:master
from
MichaelKatsoulis:update-fleetui-add-agent-standalone-k8s
Oct 18, 2021
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
be7ffd3
In case of kubernetes integartion detected return manifest in standal…
MichaelKatsoulis 158fce6
Rename manifest file
MichaelKatsoulis 6793345
Update import
MichaelKatsoulis 923d19f
Merge remote-tracking branch 'upstream/master' into update-fleetui-ad…
MichaelKatsoulis d2a5d84
Linting updates
MichaelKatsoulis 84060cd
Merge remote-tracking branch 'upstream/master' into update-fleetui-ad…
MichaelKatsoulis 7258881
Review updates
MichaelKatsoulis 29a6b0f
Get correcy package name
MichaelKatsoulis 340c04c
Merge remote-tracking branch 'upstream/master' into update-fleetui-ad…
MichaelKatsoulis 0fdce64
Review updates
MichaelKatsoulis 2cb0b6b
Update set downloadlink
MichaelKatsoulis b4f55ad
Merge remote-tracking branch 'upstream/master' into update-fleetui-ad…
MichaelKatsoulis ef47868
Update applyMsg and DowloadnMsg
MichaelKatsoulis 1f7a89e
Merge branch 'master' into update-fleetui-add-agent-standalone-k8s
kibanamachine c4c107b
Merge remote-tracking branch 'upstream/master' into update-fleetui-ad…
MichaelKatsoulis 3004261
Merge branch 'update-fleetui-add-agent-standalone-k8s' of github.com:…
MichaelKatsoulis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { safeDump } from 'js-yaml'; | ||
|
||
import type { FullAgentConfigMap } from '../types/models/agent_cm'; | ||
|
||
const CM_KEYS_ORDER = ['apiVersion', 'kind', 'metadata', 'data']; | ||
|
||
export const fullAgentConfigMapToYaml = ( | ||
policy: FullAgentConfigMap, | ||
toYaml: typeof safeDump | ||
): string => { | ||
return toYaml(policy, { | ||
skipInvalid: true, | ||
sortKeys: (keyA: string, keyB: string) => { | ||
const indexA = CM_KEYS_ORDER.indexOf(keyA); | ||
const indexB = CM_KEYS_ORDER.indexOf(keyB); | ||
if (indexA >= 0 && indexB < 0) { | ||
return -1; | ||
} | ||
|
||
if (indexA < 0 && indexB >= 0) { | ||
return 1; | ||
} | ||
|
||
return indexA - indexB; | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { FullAgentPolicy } from './agent_policy'; | ||
|
||
export interface FullAgentConfigMap { | ||
apiVersion: string; | ||
kind: string; | ||
metadata: Metadata; | ||
data: FullAgentPolicy; | ||
} | ||
|
||
interface Metadata { | ||
name: string; | ||
namespace: string; | ||
labels: Labels; | ||
} | ||
|
||
interface Labels { | ||
'k8s-app': string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably do not need the
setYaml
neither the way I would implement thisuseMemo
return a value and compute it only if dependencies changes.So you could do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very tricky. The reason I did it like this is that I didn't want always this usememo to return a value for the yaml. There are unfortunately some race conditions where isk8s === true but fullAgentPolicy hasn't beed updated yet(remains an object instead of string) and also the opposite.
So the way I did it, these cases are skipped (setYaml does not run, so value of yaml remains as it was before).
If I go with the
const yaml = useMemo(() => { return fullAgentPolicyToYaml(fullAgentPolicy); }
approach then I always have to return a value which in those cases I shouldn't.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case you should probably use
useEffect
instead ofuseMemo