Skip to content

Commit

Permalink
Merge pull request #444 from juozasg/reconcile-with-source
Browse files Browse the repository at this point in the history
Reconcile with Source
  • Loading branch information
juozasg authored Jul 19, 2023
2 parents c8da74d + 5384937 commit 2045b67
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@
"title": "Reconcile GitRepository for Path",
"category": "GitOps"
},
{
"command": "gitops.flux.reconcileWorkloadWithSource",
"title": "Reconcile with Source",
"category": "GitOps"
},
{
"command": "gitops.flux.reconcileWorkload",
"title": "Reconcile",
Expand Down Expand Up @@ -402,10 +407,15 @@
"group": "navigation@0"
},
{
"command": "gitops.flux.reconcileWorkload",
"command": "gitops.flux.reconcileWorkloadWithSource",
"when": "view == gitops.views.workloads && viewItem =~ /(Kustomization;|HelmRelease;)/",
"group": "navigation@0"
},
{
"command": "gitops.flux.reconcileWorkload",
"when": "view == gitops.views.workloads && viewItem =~ /(Kustomization;|HelmRelease;)/",
"group": "navigation@1"
},
{
"command": "gitops.suspend",
"when": "view =~ /(gitops.views.sources|gitops.views.workloads)/ && viewItem =~ /(GitRepository;|OCIRepository;|Kustomization;|HelmRelease;|HelmRepository;)/ && viewItem =~ /notSuspend;/",
Expand Down Expand Up @@ -496,6 +506,10 @@
"command": "gitops.flux.reconcileSource",
"when": "never"
},
{
"command": "gitops.flux.reconcileWorkloadWithSource",
"when": "never"
},
{
"command": "gitops.flux.reconcileWorkload",
"when": "never"
Expand Down
5 changes: 3 additions & 2 deletions src/cli/flux/fluxTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ class FluxTools {
* @param name resource name
* @param namespace resource namespace
*/
async reconcile(type: FluxSource | FluxWorkload, name: string, namespace: string) {
const reconcileShellResult = await shell.execWithOutput(`flux reconcile ${type} ${name} -n ${namespace}`);
async reconcile(type: FluxSource | FluxWorkload, name: string, namespace: string, withSource = false) {
const withSourceArg = withSource ? '--with-source' : '';
const reconcileShellResult = await shell.execWithOutput(`flux reconcile ${type} ${name} -n ${namespace} ${withSourceArg}`);
if (reconcileShellResult.code !== 0) {
telemetry.sendError(TelemetryError.FAILED_TO_RUN_FLUX_RECONCILE);
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { fluxCheck } from './fluxCheck';
import { checkFluxPrerequisites } from './fluxCheckPrerequisites';
import { fluxReconcileRepositoryForPath } from './fluxReconcileGitRepositoryForPath';
import { fluxReconcileSourceCommand } from './fluxReconcileSource';
import { fluxReconcileWorkload } from './fluxReconcileWorkload';
import { fluxReconcileWorkload, fluxReconcileWorkloadWithSource } from './fluxReconcileWorkload';
import { installFluxCli } from './installFluxCli';
import { openResource } from './openResource';
import { pullGitRepository } from './pullGitRepository';
Expand Down Expand Up @@ -54,6 +54,7 @@ export function registerCommands(context: ExtensionContext) {
registerCommand(CommandId.FluxCheckPrerequisites, checkFluxPrerequisites);
registerCommand(CommandId.FluxReconcileSource, fluxReconcileSourceCommand);
registerCommand(CommandId.FluxReconcileRepository, fluxReconcileRepositoryForPath);
registerCommand(CommandId.FluxReconcileWorkloadWithSource, fluxReconcileWorkloadWithSource);
registerCommand(CommandId.FluxReconcileWorkload, fluxReconcileWorkload);
registerCommand(CommandId.FluxEnableGitOps, fluxEnableGitOps);
registerCommand(CommandId.FluxDisableGitOps, fluxDisableGitOps);
Expand Down
14 changes: 11 additions & 3 deletions src/commands/fluxReconcileWorkload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { FluxWorkload } from 'types/fluxCliTypes';
import { Kind } from 'types/kubernetes/kubernetesTypes';
import { HelmReleaseNode } from 'ui/treeviews/nodes/helmReleaseNode';
import { KustomizationNode } from 'ui/treeviews/nodes/kustomizationNode';
import { refreshWorkloadsTreeView } from 'ui/treeviews/treeViews';
import { refreshSourcesTreeView, refreshWorkloadsTreeView } from 'ui/treeviews/treeViews';

/**
* Invoke flux reconcile of a specific workload.
* @param workload Target workload tree view item.
*/
export async function fluxReconcileWorkload(workload: KustomizationNode | HelmReleaseNode): Promise<void> {
export async function fluxReconcileWorkload(workload: KustomizationNode | HelmReleaseNode, withSource = false): Promise<void> {
/**
* Accepted workload names in flux: `kustomization`, `helmrelease`.
* Can be checked with: `flux reconcile --help`
Expand All @@ -23,7 +23,15 @@ export async function fluxReconcileWorkload(workload: KustomizationNode | HelmRe
return;
}

await fluxTools.reconcile(workloadType, workload.resource.metadata?.name || '', workload.resource.metadata?.namespace || '');
await fluxTools.reconcile(workloadType, workload.resource.metadata?.name || '', workload.resource.metadata?.namespace || '', withSource);

refreshWorkloadsTreeView();
if(withSource) {
refreshSourcesTreeView();
}
}


export async function fluxReconcileWorkloadWithSource(workload: KustomizationNode | HelmReleaseNode): Promise<void> {
fluxReconcileWorkload(workload, true);
}
1 change: 1 addition & 0 deletions src/types/extensionIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const enum CommandId {
FluxReconcileSource = 'gitops.flux.reconcileSource',
FluxReconcileRepository = 'gitops.flux.reconcileRepository',
FluxReconcileWorkload = 'gitops.flux.reconcileWorkload',
FluxReconcileWorkloadWithSource = 'gitops.flux.reconcileWorkloadWithSource',
FluxTrace = 'gitops.flux.trace',

// tree view
Expand Down

0 comments on commit 2045b67

Please sign in to comment.