Skip to content

Commit

Permalink
Merge pull request #458 from weaveworks/disable-flux-check
Browse files Browse the repository at this point in the history
(Prerelease) Allow users to disable running `flux check`
  • Loading branch information
Kingdon Barrett authored Jul 31, 2023
2 parents 56e84ea + e5b77ea commit d008edd
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 33 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@
"configuration": {
"title": "GitOps Tools",
"properties": {
"gitops.doFluxCheck": {
"type": "boolean",
"default": true,
"description": "Enable Flux Check (uncheck to skip flux check)"
},
"gitops.weaveGitopsEnterprise": {
"type": "boolean",
"default": false,
Expand Down
19 changes: 11 additions & 8 deletions src/cli/checkVersions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { commands, Uri, window } from 'vscode';

import { enabledWGE, telemetry } from 'extension';
import { enabledWGE, telemetry, enabledFluxChecks } from 'extension';
import { Errorable, failed } from 'types/errorable';
import { CommandId } from 'types/extensionIds';
import { TelemetryError } from 'types/telemetryEventNames';
Expand Down Expand Up @@ -104,14 +104,17 @@ export async function getFluxVersion(): Promise<Errorable<string>> {
* @see https://fluxcd.io/docs/cmd/flux_check/
*/
export async function checkFluxPrerequisites() {
const prerequisiteShellResult = await shell.execWithOutput('flux check --pre', { revealOutputView: false });

if (prerequisiteShellResult.code !== 0) {
const showOutput = 'Show Output';
const showOutputConfirm = await window.showWarningMessage('Flux prerequisites check failed.', showOutput);
if (showOutput === showOutputConfirm) {
commands.executeCommand(CommandId.ShowOutputChannel);
if(enabledFluxChecks()) {
const prerequisiteShellResult = await shell.execWithOutput('flux check --pre', { revealOutputView: false });
if (prerequisiteShellResult.code !== 0) {
const showOutput = 'Show Output';
const showOutputConfirm = await window.showWarningMessage('Flux prerequisites check failed.', showOutput);
if (showOutput === showOutputConfirm) {
commands.executeCommand(CommandId.ShowOutputChannel);
}
}
} else {
window.showInformationMessage('DEBUG: not running `flux check`');
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/cli/flux/fluxTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class FluxTools {
* https://github.com/fluxcd/flux2/blob/main/cmd/flux/check.go
*/
async check(context: string): Promise<{ prerequisites: FluxPrerequisite[]; controllers: FluxController[]; } | undefined> {
// cannot observe extension.enabledFluxChecks here, return type is specific;

const result = await shell.execWithOutput(safesh`flux check --context ${context}`, { revealOutputView: false });

if (result.code !== 0) {
Expand Down
9 changes: 8 additions & 1 deletion src/commands/fluxCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ import safesh from 'shell-escape-tag';

import { shell } from 'cli/shell/exec';
import { ClusterNode } from 'ui/treeviews/nodes/cluster/clusterNode';
import { enabledFluxChecks } from 'extension';
import { window } from 'vscode';

/**
* 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}`);
if(enabledFluxChecks()) {
shell.execWithOutput(safesh`flux check --context ${clusterNode.context.name}`);
} else {
// user called for health checking, notify them it isn't being performed
window.showInformationMessage('DEBUG: not running `flux check`');
}
}
7 changes: 6 additions & 1 deletion src/commands/fluxCheckPrerequisites.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { shell } from 'cli/shell/exec';
import { enabledFluxChecks } from 'extension';

/**
* Runs `flux check --pre` command in the output view.
*/
export async function checkFluxPrerequisites() {
return await shell.execWithOutput('flux check --pre');
if(enabledFluxChecks()) {
return await shell.execWithOutput('flux check --pre');
} else {
return true;
}
}
9 changes: 9 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ export function enabledWGE(): boolean {
return workspace.getConfiguration('gitops').get('weaveGitopsEnterprise') || false;
}

export function enabledFluxChecks(): boolean {
let ret = workspace.getConfiguration('gitops').get('doFluxCheck');
if(ret === false) {
return false;
} else {
return true;
}
}


/**
* Called when extension is deactivated.
Expand Down
47 changes: 24 additions & 23 deletions src/ui/treeviews/dataProviders/clusterDataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { fluxTools } from 'cli/flux/fluxTools';
import { getFluxControllers } from 'cli/kubernetes/kubectlGet';
import { kubeConfig } from 'cli/kubernetes/kubernetesConfig';
import { setVSCodeContext } from 'extension';
import { enabledFluxChecks, setVSCodeContext } from 'extension';
import { ContextId } from 'types/extensionIds';
import { statusBar } from 'ui/statusBar';
import { TreeItem } from 'vscode';
import { TreeItem, window } from 'vscode';
import { ClusterDeploymentNode } from '../nodes/cluster/clusterDeploymentNode';
import { ClusterNode } from '../nodes/cluster/clusterNode';
import { TreeNode } from '../nodes/treeNode';
Expand Down Expand Up @@ -114,30 +114,31 @@ export class ClusterDataProvider extends DataProvider {
if (!clusterNode || clusterNode.children.length === 0) {
return;
}
const fluxCheckResult = await fluxTools.check(clusterNode.context.name);
if (!fluxCheckResult) {
return;
}

// Match controllers fetched with flux with controllers
// fetched with kubectl and update tree nodes.
for (const clusterController of (clusterNode.children as ClusterDeploymentNode[])) {
for (const controller of fluxCheckResult.controllers) {
const clusterControllerName = clusterController.resource.metadata.name?.trim();
const deploymentName = controller.name.trim();

if (clusterControllerName === deploymentName) {
clusterController.description = controller.status;
if (controller.success) {
clusterController.setStatus('success');
} else {
clusterController.setStatus('failure');
if(enabledFluxChecks()){ // disable nixes health checking on the cluster
const fluxCheckResult = await fluxTools.check(clusterNode.context.name);
if (!fluxCheckResult) {
return;
}
// Match controllers fetched with flux with controllers
// fetched with kubectl and update tree nodes.
for (const clusterController of (clusterNode.children as ClusterDeploymentNode[])) {
for (const controller of fluxCheckResult.controllers) {
const clusterControllerName = clusterController.resource.metadata.name?.trim();
const deploymentName = controller.name.trim();

if (clusterControllerName === deploymentName) {
clusterController.description = controller.status;
if (controller.success) {
clusterController.setStatus('success');
} else {
clusterController.setStatus('failure');
}
}
}
refreshClustersTreeView(clusterController);
}
refreshClustersTreeView(clusterController);
} else {
window.showInformationMessage('DEBUG: not running `flux check`');
}
}


}

0 comments on commit d008edd

Please sign in to comment.