Skip to content
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

[Fleet] Hide Fleet Server policies in standalone agent instructions #98787

Merged
merged 3 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AgentPolicyPackageBadges } from '../agent_policy_package_badges';
type Props = {
agentPolicies?: AgentPolicy[];
onAgentPolicyChange?: (key: string) => void;
excludeFleetServer?: boolean;
} & (
| {
withKeySelection: true;
Expand All @@ -30,7 +31,7 @@ type Props = {

export const EnrollmentStepAgentPolicy: React.FC<Props> = (props) => {
const { notifications } = useStartServices();
const { withKeySelection, agentPolicies, onAgentPolicyChange } = props;
const { withKeySelection, agentPolicies, onAgentPolicyChange, excludeFleetServer } = props;
const onKeyChange = props.withKeySelection && props.onKeyChange;

const [isAuthenticationSettingsOpen, setIsAuthenticationSettingsOpen] = useState(false);
Expand Down Expand Up @@ -182,7 +183,10 @@ export const EnrollmentStepAgentPolicy: React.FC<Props> = (props) => {
/>
<EuiSpacer size="m" />
{selectedState.agentPolicyId && (
<AgentPolicyPackageBadges agentPolicyId={selectedState.agentPolicyId} />
<AgentPolicyPackageBadges
agentPolicyId={selectedState.agentPolicyId}
excludeFleetServer={excludeFleetServer}
/>
)}
{withKeySelection && onKeyChange && (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const StandaloneInstructions = React.memo<Props>(({ agentPolicies }) => {
const yaml = useMemo(() => fullAgentPolicyToYaml(fullAgentPolicy), [fullAgentPolicy]);
const steps: EuiContainedStepProps[] = [
DownloadStep(),
AgentPolicySelectionStep({ agentPolicies, setSelectedPolicyId }),
AgentPolicySelectionStep({ agentPolicies, setSelectedPolicyId, excludeFleetServer: true }),
{
title: i18n.translate('xpack.fleet.agentEnrollment.stepConfigureAgentTitle', {
defaultMessage: 'Configure the agent',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ export const AgentPolicySelectionStep = ({
setSelectedAPIKeyId,
setSelectedPolicyId,
setIsFleetServerPolicySelected,
excludeFleetServer,
}: {
agentPolicies?: AgentPolicy[];
setSelectedAPIKeyId?: (key: string) => void;
setSelectedPolicyId?: (policyId: string) => void;
setIsFleetServerPolicySelected?: (selected: boolean) => void;
excludeFleetServer?: boolean;
}) => {
const regularAgentPolicies = Array.isArray(agentPolicies)
? agentPolicies.filter((policy) => policy && !policy.is_managed)
? agentPolicies.filter(
(policy) =>
policy && !policy.is_managed && (!excludeFleetServer || !policy.is_default_fleet_server)
)
: [];

const onAgentPolicyChange = useCallback(
Expand Down Expand Up @@ -93,6 +98,7 @@ export const AgentPolicySelectionStep = ({
withKeySelection={setSelectedAPIKeyId ? true : false}
onKeyChange={setSelectedAPIKeyId}
onAgentPolicyChange={onAgentPolicyChange}
excludeFleetServer={excludeFleetServer}
/>
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
*/

import React, { useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiSpacer, EuiText, EuiFlexGroup, EuiFlexItem, EuiBadge } from '@elastic/eui';
import { EuiSpacer, EuiText, EuiFlexGroup, EuiFlexItem, EuiBadge, EuiCallOut } from '@elastic/eui';

import { FLEET_SERVER_PACKAGE } from '../../../../../../common/constants';

import type { PackagePolicy, PackagePolicyPackage } from '../../../types';
import { useGetOneAgentPolicy } from '../../../hooks';
Expand All @@ -16,11 +19,13 @@ import { PackageIcon } from '../../../components/package_icon';
interface Props {
agentPolicyId: string;
hideTitle?: boolean;
excludeFleetServer?: boolean;
}

export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
agentPolicyId,
hideTitle,
excludeFleetServer,
}) => {
const agentPolicyRequest = useGetOneAgentPolicy(agentPolicyId);
const agentPolicy = agentPolicyRequest.data ? agentPolicyRequest.data.item : null;
Expand All @@ -45,6 +50,19 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
return [...uniquePackages.values()];
}, [agentPolicy]);

const showFleetServerWarning = useMemo(
() => excludeFleetServer && packages?.some((pkg) => pkg.name === FLEET_SERVER_PACKAGE),
[packages, excludeFleetServer]
);

const collectedIntegrationsCount = useMemo(
() =>
packages
? packages.filter((pkg) => !excludeFleetServer || pkg.name !== FLEET_SERVER_PACKAGE).length
: 0,
[packages, excludeFleetServer]
);

if (!agentPolicy || !packages) {
return null;
}
Expand All @@ -58,8 +76,8 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
id="xpack.fleet.agentReassignPolicy.policyDescription"
defaultMessage="The selected agent policy will collect data for {count, plural, one {{countValue} integration} other {{countValue} integrations}}:"
values={{
count: packages.length,
countValue: <b>{packages.length}</b>,
count: collectedIntegrationsCount,
countValue: <b>{collectedIntegrationsCount}</b>,
}}
/>
</EuiText>
Expand All @@ -68,7 +86,11 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
)}
{packages.map((pkg, idx) => {
return (
<EuiBadge key={idx} color="hollow">
<EuiBadge
key={idx}
color="hollow"
isDisabled={excludeFleetServer && pkg.name === FLEET_SERVER_PACKAGE}
>
<EuiFlexGroup direction="row" gutterSize="xs" alignItems="center">
<EuiFlexItem grow={false}>
<PackageIcon
Expand All @@ -89,6 +111,22 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
</EuiBadge>
);
})}
{showFleetServerWarning && (
<>
<EuiSpacer size="s" />
<EuiCallOut
size="s"
color="warning"
iconType="alert"
title={i18n.translate(
'xpack.fleet.agentReassignPolicy.packageBadgeFleetServerWarning',
{
defaultMessage: 'Fleet Server will not be enabled in standalone mode.',
}
)}
/>
</>
)}
</>
);
};