Skip to content
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
31 changes: 31 additions & 0 deletions src/components/Agents/Add/AddAgentForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useAgentQuery } from "@flanksource-ui/api/query-hooks/useAgentsQuery";
import FormikSwitchField from "@flanksource-ui/components/Forms/Formik/FormikSwitchField";
import { AuthorizationAccessCheck } from "@flanksource-ui/components/Permissions/AuthorizationAccessCheck";
import { useUser } from "@flanksource-ui/context";
import { tables } from "@flanksource-ui/context/UserAccessContext/permissions";
import FormSkeletonLoader from "@flanksource-ui/ui/SkeletonLoader/FormSkeletonLoader";
import clsx from "clsx";
Expand All @@ -23,6 +24,10 @@ import DeleteAgentButton from "../DeleteAgentButton";

export type AgentFormValues = GenerateAgent & {
kubernetes?: Record<string, any>;
pushTelemetry?: {
enabled?: boolean;
topologyName?: string;
};
};

type Props = {
Expand All @@ -40,6 +45,7 @@ export default function AgentForm({
onSuccess = () => {},
onUpdated = () => {}
}: Props) {
const { backendUrl } = useUser();
const [formValues, setFormValues] = useState<AgentFormValues>();

const { data, isLoading: isLoadingAgent } = useAgentQuery(id!, {
Expand Down Expand Up @@ -103,6 +109,10 @@ export default function AgentForm({
kubernetes: {
interval: "30m",
enabled: false
},
pushTelemetry: {
enabled: false,
topologyName: backendUrl ?? ""
}
}}
onSubmit={handleSubmit}
Expand Down Expand Up @@ -169,6 +179,27 @@ export default function AgentForm({
hint="How often to perform a full reconciliation of changes (in addition to real-time changes from Kubernetes events), set higher for larger clusters."
/>
)}

<FormikSwitchField
options={[
{ label: "Enabled", key: true },
{ label: "Disabled", key: false }
]}
name="pushTelemetry.enabled"
label={
<div className="flex w-full flex-col">
<span>Telemetry</span>
</div>
}
/>
{Boolean(values.pushTelemetry?.enabled) === true && (
<FormikTextInput
name="pushTelemetry.topologyName"
label="Label"
hintPosition="top"
hint='A unique name describing the company and cluster in which the agent is running, e.g. "acme-prod"'
/>
)}
</div>
</div>
</div>
Expand Down
22 changes: 19 additions & 3 deletions src/components/Agents/InstalAgentInstruction/CLIInstallAgent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GeneratedAgent } from "@flanksource-ui/api/services/agents";
import { useUser } from "@flanksource-ui/context";
import CodeBlock from "@flanksource-ui/ui/Code/CodeBlock";
import Handlebars from "handlebars";
import { useMemo } from "react";
Expand All @@ -15,6 +16,10 @@ helm install mc-agent flanksource/mission-control-agent -n "mission-control-agen
--set upstream.username=token \\
--set upstream.password={{generatedAgent.access_token}} \\
--set upstream.agentName={{agentFormValues.name}} \\
{{#if pushTelemetry}}
--set pushTelemetry.enabled=true \\
--set pushTelemetry.topologyName={{pushTelemetry.topologyName}}
{{/if}}
--create-namespace

{{#if kubeOptions}}
Expand All @@ -35,16 +40,27 @@ export default function CLIInstallAgent({
generatedAgent,
agentFormValues
}: Props) {
const kubeOptions = agentFormValues?.kubernetes;

const baseUrl = useAgentsBaseURL();
const { backendUrl, orgSlug } = useUser();

const helmCommandTemplate = useMemo(() => {
const kubeOptions = agentFormValues?.kubernetes;
const pushTelemetry = agentFormValues?.pushTelemetry;

return template(
{
generatedAgent,
baseUrl,
agentFormValues,
pushTelemetry: pushTelemetry?.enabled
? {
...pushTelemetry,
topologyName: orgSlug
? `${orgSlug}-${pushTelemetry.topologyName}`
: pushTelemetry.topologyName
}
: undefined,
backendUrl,
kubeOptions: kubeOptions
? {
interval: kubeOptions?.interval,
Expand All @@ -54,7 +70,7 @@ export default function CLIInstallAgent({
},
{}
);
}, [agentFormValues, baseUrl, generatedAgent, kubeOptions]);
}, [agentFormValues, backendUrl, baseUrl, generatedAgent, orgSlug]);

return (
<div className="flex flex-1 flex-col gap-4 overflow-y-auto p-2">
Expand Down
23 changes: 20 additions & 3 deletions src/components/Agents/InstalAgentInstruction/FluxInstallAgent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GeneratedAgent } from "@flanksource-ui/api/services/agents";
import { useUser } from "@flanksource-ui/context";
import { JSONViewer } from "@flanksource-ui/ui/Code/JSONViewer";
import Handlebars from "handlebars";
import { useMemo } from "react";
Expand Down Expand Up @@ -40,6 +41,11 @@ spec:
username: token
agentName: {{agentFormValues.name}}
password: {{generatedAgent.access_token}}
{{#if pushTelemetry}}
pushTelemetry:
enabled: true
topologyName: {{pushTelemetry.topologyName}}
{{/if}}
{{#if kubeOptions}}
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
Expand Down Expand Up @@ -72,16 +78,27 @@ export default function FluxInstallAgent({
generatedAgent,
agentFormValues
}: Props) {
const kubeOptions = agentFormValues?.kubernetes;

const baseUrl = useAgentsBaseURL();
const { backendUrl, orgSlug } = useUser();

const yaml = useMemo(() => {
const kubeOptions = agentFormValues?.kubernetes;
const pushTelemetry = agentFormValues?.pushTelemetry ?? undefined;

return template(
{
generatedAgent,
baseUrl,
agentFormValues,
pushTelemetry: pushTelemetry?.enabled
? {
...pushTelemetry,
topologyName: orgSlug
? `${orgSlug}-${pushTelemetry.topologyName}`
: pushTelemetry.topologyName
}
: undefined,
backendUrl,
kubeOptions: kubeOptions
? {
interval: kubeOptions?.interval,
Expand All @@ -91,7 +108,7 @@ export default function FluxInstallAgent({
},
{}
);
}, [agentFormValues, baseUrl, generatedAgent, kubeOptions]);
}, [agentFormValues, backendUrl, baseUrl, generatedAgent, orgSlug]);

return (
<div className="flex max-h-[30rem] flex-1 flex-col gap-4 overflow-y-auto rounded-md border border-gray-200 p-2 px-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export default function ClerkAuthContextProvider({
<AuthContext.Provider
value={{
user: payload.user ?? (payload as any),
backendUrl: backendURL as string
backendUrl: backendURL as string,
orgSlug: organization?.slug ?? undefined
}}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions src/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { User } from "../api/types/users";
interface IAuthContext {
user?: User;
backendUrl?: string;
orgSlug?: string;
}

export const AuthContext = createContext<IAuthContext>({});
Expand Down