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

Configurable flux-system namespace #508

Draft
wants to merge 3 commits into
base: release-0.26
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions src/cli/flux/fluxTools.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/cli/kubernetes/kubectlGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
/**
Expand Down Expand Up @@ -118,7 +118,9 @@ export async function getGitOpsSet(): Promise<GitOpsSet[]> {
export async function getFluxControllers(context?: string): Promise<Deployment[]> {
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}`);
Expand Down
5 changes: 4 additions & 1 deletion src/commands/fluxCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
10 changes: 6 additions & 4 deletions src/commands/trace.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;

Expand All @@ -29,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`');
Expand All @@ -39,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);
}
8 changes: 5 additions & 3 deletions src/data/contextData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 as string, Kind.ConfigMap) as ConfigMap;

if(config) {
context.portalUrl = config.data.portalUrl;
Expand All @@ -99,7 +100,8 @@ export async function loadContextData() {
}

async function wgeHelmReleasePortalUrl() {
const wgeHelmRelease = await getResource<HelmRelease>('weave-gitops-enterprise', 'flux-system', Kind.HelmRelease);
const fluxSystemNamespace = workspace.getConfiguration('gitops').get('fluxSystemNamespace');
const wgeHelmRelease = await getResource<HelmRelease>('weave-gitops-enterprise', fluxSystemNamespace as string, Kind.HelmRelease);
if(!wgeHelmRelease) {
return;
}
Expand Down
9 changes: 5 additions & 4 deletions webview-ui/configureGitOps/src/lib/model.ts
Original file line number Diff line number Diff line change
@@ -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',

Expand Down Expand Up @@ -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',
Expand Down
6 changes: 4 additions & 2 deletions webview-ui/configureGitOps/src/lib/utils/debug.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -23,11 +25,11 @@ export function debugStandalone() {
'url': 'ssh://[email protected]/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,
Expand Down