Skip to content

Commit 6ba2be4

Browse files
committed
refactor: extract helm installation snippet from agent installation instructions
1 parent fd099f5 commit 6ba2be4

14 files changed

+579
-371
lines changed

src/components/Agents/InstalAgentInstruction/CLIInstallAgent.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/components/Agents/InstalAgentInstruction/InstallAgentModal.tsx

Lines changed: 67 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1-
import { useMemo, useState } from "react";
1+
import HelmInstallationSnippets, {
2+
ChartData
3+
} from "@flanksource-ui/ui/HelmSnippet/HelmInstallationSnippets";
4+
import { useMemo } from "react";
25
import { GeneratedAgent } from "../../../api/services/agents";
36
import { Button } from "../../../ui/Buttons/Button";
47
import { Modal } from "../../../ui/Modal";
5-
import { Tab, Tabs } from "../../../ui/Tabs/Tabs";
68
import { AgentFormValues } from "../Add/AddAgentForm";
7-
import CLIInstallAgent from "./CLIInstallAgent";
8-
import FluxInstallAgent from "./FluxInstallAgent";
99
import { useAgentsBaseURL } from "./useAgentsBaseURL";
1010

11-
export function WarningBox() {
12-
return (
13-
<div
14-
className="relative rounded border border-yellow-200 bg-yellow-100 px-4 py-3 text-yellow-700"
15-
role="alert"
16-
>
17-
<span className="block sm:inline">
18-
Access token will be shown only once. Please copy it and store it
19-
securely.
20-
</span>
21-
</div>
22-
);
23-
}
24-
2511
export function MoreInfoBox() {
2612
return (
2713
<div className="flex flex-col gap-2 px-2">
@@ -84,14 +70,6 @@ export function MoreInfoBox() {
8470
);
8571
}
8672

87-
export type TemplateContextData = {
88-
namespace?: string;
89-
chart?: string;
90-
repoName?: string;
91-
values?: string[];
92-
kubeValues?: string[];
93-
};
94-
9573
type Props = {
9674
isOpen: boolean;
9775
onClose: () => void;
@@ -105,47 +83,78 @@ export default function InstallAgentModal({
10583
generatedAgent,
10684
agentFormValues
10785
}: Props) {
108-
const [activeTab, setActiveTab] = useState<"cli" | "flux">("cli");
10986
const baseUrl = useAgentsBaseURL();
11087

11188
const data = useMemo(() => {
11289
const kubeOptions = agentFormValues?.kubernetes;
11390
const pushTelemetry = agentFormValues?.pushTelemetry ?? undefined;
11491

115-
return {
116-
chart: "mission-control-agent",
117-
namespace: "mission-control-agent",
118-
repoName: "flanksource",
119-
// You can add more values here to be passed to the template for the
120-
// values section of the HelmRelease
121-
values: [
122-
`upstream.createSecret=true`,
123-
`upstream.host=${baseUrl}`,
124-
`upstream.username=token`,
125-
`upstream.password=${generatedAgent?.access_token}`,
126-
`upstream.agentName=${agentFormValues?.name}`,
127-
...(pushTelemetry?.enabled
128-
? [
129-
`pushTelemetry.enabled=true`,
130-
`pushTelemetry.topologyName=${
131-
pushTelemetry.topologyName
132-
}-${agentFormValues?.name}`
133-
]
134-
: [])
135-
],
136-
// You can add more values here to be passed to the template for the
137-
// kubeValues section of the HelmRelease
138-
kubeValues: kubeOptions
92+
return [
93+
{
94+
chart: "mission-control-agent",
95+
namespace: "mission-control-agent",
96+
repoName: "flanksource",
97+
createNamespace: true,
98+
createRepo: true,
99+
// You can add more values here to be passed to the template for the
100+
// values section of the HelmRelease
101+
values: [
102+
{
103+
key: "upstream.createSecret",
104+
value: "true"
105+
},
106+
{
107+
key: "upstream.host",
108+
value: baseUrl
109+
},
110+
{
111+
key: "upstream.username",
112+
value: "token"
113+
},
114+
{
115+
key: "upstream.password",
116+
value: generatedAgent?.access_token
117+
},
118+
{
119+
key: "upstream.agentName",
120+
value: agentFormValues?.name
121+
},
122+
...(pushTelemetry?.enabled
123+
? [
124+
{
125+
key: "pushTelemetry.enabled",
126+
value: "true"
127+
},
128+
{
129+
key: "pushTelemetry.topologyName",
130+
value: `${pushTelemetry.topologyName}`
131+
}
132+
]
133+
: [])
134+
]
135+
},
136+
...(kubeOptions?.enabled
139137
? [
140-
`clusterName: "${agentFormValues?.name}"`,
141-
`scraper.schedule: "${kubeOptions.schedule}"`
138+
{
139+
chart: "mc-agent-kubernetes",
140+
namespace: "mission-control-agent",
141+
repoName: "flanksource",
142+
values: [
143+
{
144+
key: "clusterName",
145+
value: agentFormValues?.name
146+
},
147+
{
148+
key: "scraper.schedule",
149+
value: kubeOptions.schedule
150+
}
151+
]
152+
}
142153
]
143-
: []
144-
} satisfies TemplateContextData;
154+
: [])
155+
] satisfies ChartData[];
145156
}, [agentFormValues, baseUrl, generatedAgent]);
146157

147-
console.log(JSON.stringify(data, null, 2));
148-
149158
return (
150159
<Modal
151160
title={"Installation Instructions"}
@@ -159,23 +168,7 @@ export default function InstallAgentModal({
159168
Install the Mission Control agent using instructions below
160169
</h3>
161170
<div className="flex flex-col">
162-
<Tabs
163-
activeTab={activeTab}
164-
onSelectTab={(v) => setActiveTab(v as any)}
165-
>
166-
<Tab className="flex flex-col gap-4 p-4" label="Flux" value="flux">
167-
<FluxInstallAgent data={data} />
168-
<WarningBox />
169-
</Tab>
170-
<Tab
171-
className="flex flex-col gap-4 p-4"
172-
label="Helm CLI"
173-
value="cli"
174-
>
175-
<CLIInstallAgent data={data} />
176-
<WarningBox />
177-
</Tab>
178-
</Tabs>
171+
<HelmInstallationSnippets charts={data} isWarningDisplayed />
179172
</div>
180173
<MoreInfoBox />
181174
</div>

src/components/Agents/InstalAgentInstruction/__tests__/CLIInstallAgent.unit.test.tsx

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/components/Agents/InstalAgentInstruction/__tests__/FluxInstallAgent.unit.test.tsx

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)