Skip to content

Commit

Permalink
kubectl context commands
Browse files Browse the repository at this point in the history
  • Loading branch information
juozasg committed Sep 12, 2023
1 parent 9706ff1 commit 90e0aa5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
39 changes: 35 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,21 @@
"command": "gitops.createKustomization",
"title": "Create Kustomization from Path",
"icon": "$(add)",
"enablement": "!gitops:clusterUnreachable && !gitops:currentClusterGitOpsNotEnabled",
"category": "GitOps"
},
{
"command": "gitops.kubectlApplyPath",
"title": "Apply (kubectl apply -f)",
"category": "GitOps"
},
{
"command": "gitops.kubectlDeletePath",
"title": "Delete (kubectl delete -f)",
"category": "GitOps"
},
{
"command": "gitops.kubectlApplyKustomization",
"title": "Apply Kustomization Directory (kubectl apply -k)",
"category": "GitOps"
},
{
Expand Down Expand Up @@ -479,14 +493,31 @@
],
"gitops.explorer": [
{
"command": "gitops.views.createGitRepository"
"command": "gitops.kubectlApplyPath",
"group": "1"
},
{
"command": "gitops.flux.reconcileRepository",
"command": "gitops.kubectlDeletePath",
"group": "1"
},
{
"command": "gitops.kubectlApplyKustomization",
"group": "1",
"when": "explorerResourceIsFolder"
},
{
"command": "gitops.createKustomization"
"command": "gitops.views.createGitRepository",
"group": "2"
},
{
"command": "gitops.flux.reconcileRepository",
"when": "explorerResourceIsFolder",
"group": "2"
},
{
"command": "gitops.createKustomization",
"group": "2"

}
],
"explorer/context": [
Expand Down
12 changes: 9 additions & 3 deletions src/commands/commands.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { commands, Disposable, ExtensionContext, Uri, window } from 'vscode';

import { showOutputChannel } from 'cli/shell/output';
import { refreshAllTreeViewsCommand, refreshResourcesTreeViewsCommand } from 'commands/refreshTreeViews';
import { telemetry } from 'extension';
import { CommandId } from 'types/extensionIds';
import { TelemetryError } from 'types/telemetryEventNames';
import { refreshAllTreeViewsCommand, refreshResourcesTreeViewsCommand } from 'commands/refreshTreeViews';
import { addKustomization } from './addKustomization';
import { addSource } from './addSource';
import { copyResourceName } from './copyResourceName';
Expand All @@ -14,13 +14,15 @@ import { createKustomizationForPath } from './createKustomizationForPath';
import { deleteSource } from './deleteSource';
import { deleteWorkload } from './deleteWorkload';
import { fluxDisableGitOps, fluxEnableGitOps } from './enableDisableGitOps';
import { expandAllSources, expandAllWorkloads } from './expandAll';
import { fluxCheck } from './fluxCheck';
import { checkFluxPrerequisites } from './fluxCheckPrerequisites';
import { fluxReconcileRepositoryForPath } from './fluxReconcileGitRepositoryForPath';
import { fluxReconcileSourceCommand } from './fluxReconcileSource';
import { fluxReconcileWorkload, fluxReconcileWorkloadWithSource } from './fluxReconcileWorkload';
import { installFluxCli } from './installFluxCli';
import { openResource, openKubeconfig } from './openResource';
import { kubectlApplyKustomization, kubectlApplyPath, kubectlDeletePath } from './kubectlApply';
import { openKubeconfig, openResource } from './openResource';
import { pullGitRepository } from './pullGitRepository';
import { resume } from './resume';
import { setClusterProvider } from './setClusterProvider';
Expand All @@ -32,7 +34,6 @@ import { showNewUserGuide } from './showNewUserGuide';
import { showWorkloadsHelpMessage } from './showWorkloadsHelpMessage';
import { suspend } from './suspend';
import { trace } from './trace';
import { expandAllSources, expandAllWorkloads } from './expandAll';


let _context: ExtensionContext;
Expand Down Expand Up @@ -76,6 +77,11 @@ export function registerCommands(context: ExtensionContext) {
registerCommand(CommandId.CopyResourceName, copyResourceName);
registerCommand(CommandId.AddSource, addSource);
registerCommand(CommandId.AddKustomization, addKustomization);
registerCommand(CommandId.KubectlApplyPath, kubectlApplyPath);
registerCommand(CommandId.KubectlDeletePath, kubectlDeletePath);
registerCommand(CommandId.KubectlApplyKustomization, kubectlApplyKustomization);


registerCommand(CommandId.ExpandAllSources, expandAllSources);
registerCommand(CommandId.ExpandAllWorkloads, expandAllWorkloads);

Expand Down
19 changes: 19 additions & 0 deletions src/commands/kubectlApply.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as shell from 'cli/shell/exec';
import { Uri } from 'vscode';

export async function kubectlApplyPath(uri?: Uri) {
if(uri) {
return await shell.execWithOutput(`kubectl apply -f ${uri.fsPath}`);
}
}
export async function kubectlDeletePath(uri?: Uri) {
if(uri) {
return await shell.execWithOutput(`kubectl delete -f ${uri.fsPath}`);
}
}

export async function kubectlApplyKustomization(uri?: Uri) {
if(uri) {
return await shell.execWithOutput(`kubectl apply -k ${uri.fsPath}`);
}
}
5 changes: 5 additions & 0 deletions src/types/extensionIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export const enum CommandId {
AddSource = 'gitops.addSource',
AddKustomization = 'gitops.addKustomization',

KubectlApplyPath = 'gitops.kubectlApplyPath',
KubectlDeletePath = 'gitops.kubectlDeletePath',
KubectlApplyKustomization = 'gitops.kubectlApplyKustomization',


// editor
EditorOpenResource = 'gitops.editor.openResource',
EditorOpenKubeconfig = 'gitops.editor.openKubeconfig',
Expand Down

0 comments on commit 90e0aa5

Please sign in to comment.