From d3208678110282ce3b429d7385d47f5957cee7da Mon Sep 17 00:00:00 2001 From: Kingdon Barrett Date: Thu, 27 Jun 2024 13:23:46 -0400 Subject: [PATCH 1/3] probably shouldn't update this file Signed-off-by: Kingdon Barrett --- webview-ui/configureGitOps/src/lib/utils/debug.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webview-ui/configureGitOps/src/lib/utils/debug.ts b/webview-ui/configureGitOps/src/lib/utils/debug.ts index 0788d817..d9bcad28 100644 --- a/webview-ui/configureGitOps/src/lib/utils/debug.ts +++ b/webview-ui/configureGitOps/src/lib/utils/debug.ts @@ -1,4 +1,6 @@ +import { workspace } from 'vscode'; import { setParams } from '../params'; +const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace'); export function debug(str: string) { const e = document.getElementById('debug'); @@ -23,11 +25,11 @@ export function debugStandalone() { 'url': 'ssh://git@github.com/juozasg/pooodinfo.git', 'branch': 'master', }, - 'namespaces': [ 'default', 'flux-system', 'foobar'], + 'namespaces': [ 'default', fluxSystemNamespace', 'foobar'], 'sources': [ {'kind': 'GitRepository', metadata: {'name': 'podinfo', 'namespace': 'default'}}, {'kind': 'OCIRepository', metadata: {'name': 'podinfo', 'namespace': 'default'}}, - {'kind': 'OCIRepository', metadata: {'name': 'podinfo', 'namespace': 'flux-system'}}, + {'kind': 'OCIRepository', metadata: {'name': 'podinfo', 'namespace': fluxSystemNamespace}}, {'kind': 'GitRepository', metadata: {'name': 'podinfo2', 'namespace': 'default'}}, {'kind': 'OCIRepository', metadata: {'name': 'podinfo11', 'namespace': 'default'}}], 'selectSourceTab': false, From 918f9b7d1ac6322af68a18bd80abc1c3e7c1ff10 Mon Sep 17 00:00:00 2001 From: Kingdon Barrett Date: Thu, 27 Jun 2024 13:23:53 -0400 Subject: [PATCH 2/3] flux-system as configurable string Signed-off-by: Kingdon Barrett --- package.json | 5 +++++ src/cli/kubernetes/kubectlGet.ts | 6 ++++-- src/commands/trace.ts | 6 ++++-- src/data/contextData.ts | 8 +++++--- webview-ui/configureGitOps/src/lib/model.ts | 9 +++++---- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 6d9204ac..53ed1aad 100644 --- a/package.json +++ b/package.json @@ -347,6 +347,11 @@ "type": "boolean", "default": false, "description": "Stop recommending changes to editor or extension settings." + }, + "gitops.fluxSystemNamespace": { + "type": "string", + "default": "flux-system", + "description": "The namespace where Flux manifests are installed (usually flux-system)" } } }, diff --git a/src/cli/kubernetes/kubectlGet.ts b/src/cli/kubernetes/kubectlGet.ts index f352fa1d..d420eb04 100644 --- a/src/cli/kubernetes/kubectlGet.ts +++ b/src/cli/kubernetes/kubectlGet.ts @@ -15,7 +15,7 @@ import { Pipeline } from 'types/flux/pipeline'; import { Deployment, Kind, KubernetesObject, Pod, qualifyToolkitKind } from 'types/kubernetes/kubernetesTypes'; import { TelemetryError } from 'types/telemetryEventNames'; import { parseJson, parseJsonItems } from 'utils/jsonUtils'; -import { window } from 'vscode'; +import { window, workspace } from 'vscode'; import { getAvailableResourcePlurals } from './apiResources'; import { invokeKubectlCommand } from './kubernetesToolsKubectl'; /** @@ -118,7 +118,9 @@ export async function getGitOpsSet(): Promise { export async function getFluxControllers(context?: string): Promise { const contextArg = context ? safesh`--context ${context}` : ''; - const fluxDeploymentShellResult = await invokeKubectlCommand(`get deployment --namespace=flux-system ${contextArg} -o json`); + const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace'); + + const fluxDeploymentShellResult = await invokeKubectlCommand(`get deployment --namespace=${fluxSystemNamespace} ${contextArg} -o json`); if (fluxDeploymentShellResult?.code !== 0) { console.warn(`Failed to get flux controllers: ${fluxDeploymentShellResult?.stderr}`); diff --git a/src/commands/trace.ts b/src/commands/trace.ts index f0e3ce9c..11b60e2b 100644 --- a/src/commands/trace.ts +++ b/src/commands/trace.ts @@ -1,4 +1,4 @@ -import { window } from 'vscode'; +import { window, workspace } from 'vscode'; import { fluxTools } from 'cli/flux/fluxTools'; import { getResource } from 'cli/kubernetes/kubectlGet'; @@ -11,8 +11,10 @@ import { WorkloadNode } from 'ui/treeviews/nodes/workload/workloadNode'; * Run flux trace for the Workloads tree view node. */ export async function trace(node: AnyResourceNode | WorkloadNode) { + const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace'); + const resourceName = node.resource.metadata.name; - const resourceNamespace = node.resource.metadata.namespace || 'flux-system'; + const resourceNamespace = node.resource.metadata.namespace || fluxSystemNamespace; const resourceKind = node.resource.kind; let resourceApiVersion = node.resource.apiVersion; diff --git a/src/data/contextData.ts b/src/data/contextData.ts index d6ad7563..3213931d 100644 --- a/src/data/contextData.ts +++ b/src/data/contextData.ts @@ -5,7 +5,7 @@ import { ConfigMap, Kind } from 'types/kubernetes/kubernetesTypes'; import { NamespaceNode } from 'ui/treeviews/nodes/namespaceNode'; import { TreeNode } from 'ui/treeviews/nodes/treeNode'; import { WgeContainerNode } from 'ui/treeviews/nodes/wge/wgeNodes'; -import { TreeItemCollapsibleState } from 'vscode'; +import { TreeItemCollapsibleState, workspace } from 'vscode'; import { ApiState, KindApiParams } from '../cli/kubernetes/apiResources'; // a data store for each context defined in kubeconfig. @@ -86,8 +86,9 @@ export class ViewData { } export async function loadContextData() { + const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace'); const context = currentContextData(); - const config = await getResource('weave-gitops-interop', 'flux-system', Kind.ConfigMap) as ConfigMap; + const config = await getResource('weave-gitops-interop', fluxSystemNamespace, Kind.ConfigMap) as ConfigMap; if(config) { context.portalUrl = config.data.portalUrl; @@ -99,7 +100,8 @@ export async function loadContextData() { } async function wgeHelmReleasePortalUrl() { - const wgeHelmRelease = await getResource('weave-gitops-enterprise', 'flux-system', Kind.HelmRelease); + const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace'); + const wgeHelmRelease = await getResource('weave-gitops-enterprise', fluxSystemNamespace, Kind.HelmRelease); if(!wgeHelmRelease) { return; } diff --git a/webview-ui/configureGitOps/src/lib/model.ts b/webview-ui/configureGitOps/src/lib/model.ts index b081752e..e22b67f2 100644 --- a/webview-ui/configureGitOps/src/lib/model.ts +++ b/webview-ui/configureGitOps/src/lib/model.ts @@ -1,17 +1,18 @@ -import { createEffect, createSignal, untrack } from 'solid-js'; +import { createEffect, createSignal } from 'solid-js'; import { createStore, unwrap } from 'solid-js/store'; +import { workspace } from 'vscode'; import { params } from './params'; -import { debug } from './utils/debug'; import { capitalize, namespacedSource } from './utils/helpers'; /* SOURCE */ export const [createSource, setCreateSource] = createSignal(true); +const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace'); export const [source, setSource] = createStore({ kind: 'GitRepository', name: 'podinfo', - namespace: 'flux-system', + namespace: fluxSystemNamespace, interval: '1m0s', @@ -84,7 +85,7 @@ export const [createWorkload, setCreateWorkload] = createSignal(false); export const [kustomization, setKustomization] = createStore({ name: 'podinfo', - namespace: 'flux-system', + namespace: fluxSystemNamespace, source: '', // Ex: GitRepository/podinfo.flux-system path: '/kustomize', targetNamespace: 'default', From c9d59a1df7a53c0fc56ec8e9da3f9d34d4464aa6 Mon Sep 17 00:00:00 2001 From: Kingdon Barrett Date: Thu, 27 Jun 2024 13:42:54 -0400 Subject: [PATCH 3/3] add fluxSystemNamespace in some other places Signed-off-by: Kingdon Barrett --- src/cli/flux/fluxTools.ts | 5 +++-- src/commands/fluxCheck.ts | 5 ++++- src/commands/trace.ts | 4 ++-- src/data/contextData.ts | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/cli/flux/fluxTools.ts b/src/cli/flux/fluxTools.ts index 94860a1b..ec76f4ba 100644 --- a/src/cli/flux/fluxTools.ts +++ b/src/cli/flux/fluxTools.ts @@ -1,5 +1,5 @@ import safesh from 'shell-escape-tag'; -import { window } from 'vscode'; +import { window, workspace } from 'vscode'; import * as shell from 'cli/shell/exec'; import { enabledFluxChecks, telemetry } from 'extension'; @@ -67,7 +67,8 @@ class FluxTools { if (!enabledFluxChecks()) { return undefined; } - const result = await shell.execWithOutput(safesh`flux check --context ${context}`, { revealOutputView: false }); + const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace'); + const result = await shell.execWithOutput(safesh`flux check -n ${fluxSystemNamespace} --context ${context}`, { revealOutputView: false }); if (result.code !== 0) { telemetry.sendError(TelemetryError.FAILED_TO_RUN_FLUX_CHECK); diff --git a/src/commands/fluxCheck.ts b/src/commands/fluxCheck.ts index 55c2ec20..06f05848 100644 --- a/src/commands/fluxCheck.ts +++ b/src/commands/fluxCheck.ts @@ -2,11 +2,14 @@ import safesh from 'shell-escape-tag'; import * as shell from 'cli/shell/exec'; import { ClusterNode } from 'ui/treeviews/nodes/cluster/clusterNode'; +import { workspace } from 'vscode'; + +const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace'); /** * Runs `flux check` command for selected cluster in the output view. * @param clusterNode target cluster node (from tree node context menu) */ export async function fluxCheck(clusterNode: ClusterNode) { - shell.execWithOutput(safesh`flux check --context ${clusterNode.context.name}`); + shell.execWithOutput(safesh`flux check -n ${fluxSystemNamespace} --context ${clusterNode.context.name}`); } diff --git a/src/commands/trace.ts b/src/commands/trace.ts index 11b60e2b..5a09b8f7 100644 --- a/src/commands/trace.ts +++ b/src/commands/trace.ts @@ -31,7 +31,7 @@ export async function trace(node: AnyResourceNode | WorkloadNode) { // flux tree fetched items don't have the "apiVersion" property if (!resourceApiVersion) { - const resource = await getResource(resourceName, resourceNamespace, resourceKind as Kind); + const resource = await getResource(resourceName, resourceNamespace as string, resourceKind as Kind); const apiVersion = resource?.apiVersion; if (!apiVersion && !apiVersion) { window.showErrorMessage('"apiVersion" is required to run `flux trace`'); @@ -41,5 +41,5 @@ export async function trace(node: AnyResourceNode | WorkloadNode) { resourceApiVersion = apiVersion; } - await fluxTools.trace(resourceName, resourceKind, resourceApiVersion, resourceNamespace); + await fluxTools.trace(resourceName, resourceKind, resourceApiVersion, resourceNamespace as string); } diff --git a/src/data/contextData.ts b/src/data/contextData.ts index 3213931d..83ab2579 100644 --- a/src/data/contextData.ts +++ b/src/data/contextData.ts @@ -88,7 +88,7 @@ export class ViewData { export async function loadContextData() { const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace'); const context = currentContextData(); - const config = await getResource('weave-gitops-interop', fluxSystemNamespace, Kind.ConfigMap) as ConfigMap; + const config = await getResource('weave-gitops-interop', fluxSystemNamespace as string, Kind.ConfigMap) as ConfigMap; if(config) { context.portalUrl = config.data.portalUrl; @@ -101,7 +101,7 @@ export async function loadContextData() { async function wgeHelmReleasePortalUrl() { const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace'); - const wgeHelmRelease = await getResource('weave-gitops-enterprise', fluxSystemNamespace, Kind.HelmRelease); + const wgeHelmRelease = await getResource('weave-gitops-enterprise', fluxSystemNamespace as string, Kind.HelmRelease); if(!wgeHelmRelease) { return; }