Skip to content

Commit b6764f5

Browse files
author
Kingdon Barrett
authored
Merge pull request #399 from juozasg/azure-fixes
Azure fixes
2 parents 71960eb + 7d3b0f5 commit b6764f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5001
-365
lines changed

media/createSource.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
<h2>Create Source on the <code id="cluster-name">""</code> cluster</h2>
1+
<h2>Create Source on the <code id="cluster-name">""</code>cluster</h2>
22
<h3 id="cluster-provider"></h3>
33
<hr>
44

55

6+
7+
8+
69
<div id="generic-form" hidden>
710
<div>
811
<label class="header-label" for="git-source-name">Source Name</label><input type="text" id="git-source-name">
@@ -67,7 +70,6 @@ <h3 id="cluster-provider"></h3>
6770

6871

6972
<div id="azure-form" hidden>
70-
7173
<div>
7274
<label class="header-label" for="az-scope-cluster">Specify scope of the operator to be 'namespace' or 'cluster' <code class="cli-argument">--scope</code></label>
7375
<input type="radio" id="az-scope-cluster" name="az-scope" value="cluster" checked> <label for="az-scope-cluster">cluster</label>

package.json

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@
6767
"onCommand:gitops.copyResourceName",
6868
"onCommand:gitops.editor.openResource",
6969
"onCommand:gitops.editor.showLogs",
70-
"onCommand:gitops.editor.createSource",
7170
"onCommand:gitops.output.show",
7271
"onCommand:gitops.installFluxCli",
73-
"onWebviewPanel:createSource",
7472
"onView:gitops.views.clusters",
7573
"onView:gitops.views.sources",
7674
"onView:gitops.views.workloads",
@@ -179,7 +177,7 @@
179177
},
180178
{
181179
"command": "gitops.views.createGitRepository",
182-
"title": "Create Git Repository Source",
180+
"title": "Create GitRepository Source",
183181
"category": "GitOps"
184182
},
185183
{
@@ -189,6 +187,20 @@
189187
"enablement": "!gitops:noClusterSelected && !gitops:currentClusterGitOpsNotEnabled",
190188
"category": "GitOps"
191189
},
190+
{
191+
"command": "gitops.addSource",
192+
"title": "Add Source",
193+
"category": "GitOps",
194+
"icon": "$(add)",
195+
"enablement": "!gitops:noClusterSelected && !gitops:currentClusterGitOpsNotEnabled"
196+
},
197+
{
198+
"command": "gitops.addKustomization",
199+
"title": "Add Kustomization",
200+
"category": "GitOps",
201+
"icon": "$(add)",
202+
"enablement": "!gitops:noClusterSelected && !gitops:currentClusterGitOpsNotEnabled"
203+
},
192204
{
193205
"command": "gitops.views.deleteWorkload",
194206
"title": "Delete",
@@ -215,13 +227,6 @@
215227
"title": "View Config",
216228
"category": "GitOps"
217229
},
218-
{
219-
"command": "gitops.editor.createSource",
220-
"title": "Create Source",
221-
"category": "GitOps",
222-
"enablement": "!gitops:noClusterSelected && !gitops:currentClusterGitOpsNotEnabled",
223-
"icon": "$(add)"
224-
},
225230
{
226231
"command": "gitops.output.show",
227232
"title": "Show Output",
@@ -341,12 +346,12 @@
341346
"when": "view == gitops.views.clusters"
342347
},
343348
{
344-
"command": "gitops.editor.createSource",
349+
"command": "gitops.addSource",
345350
"group": "navigation@0",
346351
"when": "view == gitops.views.sources"
347352
},
348353
{
349-
"command": "gitops.createKustomization",
354+
"command": "gitops.addKustomization",
350355
"group": "navigation@0",
351356
"when": "view == gitops.views.workloads"
352357
},
@@ -427,6 +432,11 @@
427432
"when": "view == gitops.views.sources && viewItem =~ /GitRepository;/",
428433
"group": "navigation@3"
429434
},
435+
{
436+
"command": "gitops.addKustomization",
437+
"when": "view == gitops.views.sources && viewItem =~ /GitRepository;/",
438+
"group": "navigation@3"
439+
},
430440
{
431441
"command": "gitops.editor.showLogs",
432442
"when": "view =~ /^(gitops.views.clusters)$/ && viewItem =~ /(Deployment;)/"
@@ -520,10 +530,6 @@
520530
"command": "gitops.views.showWorkloadsHelpMessage",
521531
"when": "never"
522532
},
523-
{
524-
"command": "gitops.editor.createSource",
525-
"when": "never"
526-
},
527533
{
528534
"command": "gitops.flux.trace",
529535
"when": "never"
@@ -552,7 +558,9 @@
552558
"watch-tests": "tsc -p . -w --outDir out",
553559
"pretest": "npm run compile-tests && npm run compile && npm run lint",
554560
"lint": "eslint src --ext ts",
555-
"test": "node ./out/test/runTest.js"
561+
"test": "node ./out/test/runTest.js",
562+
"start:webview": "npm --prefix ./webview-ui run start",
563+
"build:webview": "npm --prefix ./webview-ui run build"
556564
},
557565
"extensionDependencies": [
558566
"ms-kubernetes-tools.vscode-kubernetes-tools"

src/azure/azureTools.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export const enum AzureConstants {
2727
FluxExtensionName = 'flux',
2828
}
2929

30+
31+
export type CreateSourceGitAzureArgs = Parameters<typeof azureTools['createSourceGit']>[0];
32+
33+
3034
class AzureTools {
3135

3236
private async buildAzCommand(
@@ -180,7 +184,7 @@ class AzureTools {
180184
* @param contextName target context name
181185
* @param clusterProvider target cluster provider
182186
*/
183-
private async listFluxConfigurations(
187+
public async listFluxConfigurations(
184188
contextName: string,
185189
clusterProvider: AzureClusterProvider,
186190
): Promise<undefined | any[]> {
@@ -212,9 +216,12 @@ class AzureTools {
212216
kustomizationPath: string,
213217
contextName: string,
214218
clusterProvider: AzureClusterProvider,
219+
kustomizationDependsOn?: string,
215220
) {
221+
const dependsOnArg = kustomizationDependsOn ? ` --depends-on "${kustomizationDependsOn}"` : '';
222+
216223
const createKustomizationShellResult = await this.invokeAzCommand(
217-
`az k8s-configuration flux kustomization create --kustomization-name ${kustomizationName} --name ${gitRepositoryName} --path "${kustomizationPath}" --prune true`,
224+
`az k8s-configuration flux kustomization create --kustomization-name ${kustomizationName} --name ${gitRepositoryName} --path "${kustomizationPath}"${dependsOnArg} --prune true`,
218225
contextName,
219226
clusterProvider,
220227
);
@@ -232,8 +239,8 @@ class AzureTools {
232239
*/
233240
async createSourceGit(args: {
234241
sourceName: string;
235-
sourceScope?: string;
236-
sourceNamespace?: string;
242+
azureScope?: string;
243+
namespace?: string;
237244
contextName: string;
238245
clusterProvider: AzureClusterProvider;
239246
url: string;
@@ -262,8 +269,8 @@ class AzureTools {
262269
kustomizationForce?: boolean;
263270
}) {
264271
const urlArg = ` --url "${args.url}"`;
265-
const scopeArg = args.sourceScope ? ` --scope "${args.sourceScope}"` : '';
266-
const namespaceArg = args.sourceNamespace ? ` --namespace "${args.sourceNamespace}"` : '';
272+
const scopeArg = args.azureScope ? ` --scope "${args.azureScope}"` : '';
273+
const namespaceArg = args.namespace ? ` --namespace "${args.namespace}"` : '';
267274
const branchArg = args.branch ? ` --branch "${args.branch}"` : '';
268275
const tagArg = args.tag ? ` --tag "${args.tag}"` : '';
269276
const semverArg = args.semver ? ` --semver "${args.semver}"` : '';
@@ -399,12 +406,13 @@ class AzureTools {
399406

400407

401408
async deleteKustomization(
409+
configName: string,
402410
kustomizationName: string,
403411
contextName: string,
404412
clusterProvider: AzureClusterProvider,
405413
) {
406414
const deleteSourceShellResult = await this.invokeAzCommand(
407-
`az k8s-configuration flux kustomization delete -n ${kustomizationName} --yes`,
415+
`az k8s-configuration flux kustomization delete -n ${configName} -k ${kustomizationName} --yes`,
408416
contextName,
409417
clusterProvider,
410418
);
@@ -460,6 +468,11 @@ class AzureTools {
460468
}
461469

462470

471+
getAzName(fluxConfigName: string, resourceName: string) {
472+
return resourceName.replace(RegExp(`^${fluxConfigName}-`), '');
473+
}
474+
475+
463476
}
464477

465478
/**

src/commands.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { commands, Disposable, ExtensionContext, Uri, window } from 'vscode';
22
import { copyResourceName } from './commands/copyResourceName';
33
import { createGitRepository } from './commands/createGitRepository';
44
import { createKustomization } from './commands/createKustomization';
5+
import { addSource } from './commands/addSource';
6+
import { addKustomization } from './commands/addKustomization';
57
import { deleteWorkload } from './commands/deleteWorkload';
68
import { deleteSource } from './commands/deleteSource';
79
import { fluxDisableGitOps, fluxEnableGitOps } from './commands/enableDisableGitOps';
@@ -11,7 +13,6 @@ import { fluxReconcileRepository } from './commands/fluxReconcileRepository';
1113
import { fluxReconcileSourceCommand } from './commands/fluxReconcileSource';
1214
import { fluxReconcileWorkload } from './commands/fluxReconcileWorkload';
1315
import { installFluxCli } from './commands/installFluxCli';
14-
import { openCreateSourceWebview } from './commands/openCreateSourceWebview';
1516
import { openResource } from './commands/openResource';
1617
import { pullGitRepository } from './commands/pullGitRepository';
1718
import { resume } from './commands/resume';
@@ -73,13 +74,14 @@ export const enum CommandId {
7374
DeleteWorkload = 'gitops.views.deleteWorkload',
7475
DeleteSource = 'gitops.views.deleteSource',
7576
CopyResourceName = 'gitops.copyResourceName',
77+
AddSource = 'gitops.addSource',
78+
AddKustomization = 'gitops.addKustomization',
7679

7780
// editor
7881
EditorOpenResource = 'gitops.editor.openResource',
7982

8083
// webview
8184
ShowLogs = 'gitops.editor.showLogs',
82-
OpenCreateSourceWebview = 'gitops.editor.createSource',
8385
ShowNewUserGuide = 'gitops.views.showNewUserGuide',
8486

8587
// output commands
@@ -130,13 +132,15 @@ export function registerCommands(context: ExtensionContext) {
130132
registerCommand(CommandId.DeleteWorkload, deleteWorkload);
131133
registerCommand(CommandId.DeleteSource, deleteSource);
132134
registerCommand(CommandId.CopyResourceName, copyResourceName);
135+
registerCommand(CommandId.AddSource, addSource);
136+
registerCommand(CommandId.AddKustomization, addKustomization);
137+
133138

134139
// editor
135140
registerCommand(CommandId.EditorOpenResource, openResource);
136141

137142
// webview
138143
registerCommand(CommandId.ShowLogs, showLogs);
139-
registerCommand(CommandId.OpenCreateSourceWebview, openCreateSourceWebview);
140144
registerCommand(CommandId.ShowNewUserGuide, showNewUserGuide);
141145

142146
// output

src/commands/addKustomization.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { openConfigureGitOpsPanel } from '../panels/configureGitOps';
2+
import { GitRepositoryNode } from '../views/nodes/gitRepositoryNode';
3+
4+
/**
5+
* Open ConfigureGitops webview with a source preselected (if user right-clicked a source node)
6+
* @param sourceNode user right-clicked this in the Sources treeview
7+
*/
8+
export async function addKustomization(sourceNode?: GitRepositoryNode) {
9+
const selectedSource = sourceNode?.resource?.metadata.name;
10+
11+
openConfigureGitOpsPanel(true, selectedSource);
12+
}

src/commands/addSource.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { openConfigureGitOpsPanel } from '../panels/configureGitOps';
2+
3+
/**
4+
* Open ConfigureGitops webview with 'New Source' tab open
5+
*/
6+
export async function addSource() {
7+
openConfigureGitOpsPanel(false);
8+
}

src/commands/createSource.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import gitUrlParse from 'git-url-parse';
22
import { commands, env, Uri, window } from 'vscode';
3-
import { azureTools } from '../azure/azureTools';
3+
import { azureTools, CreateSourceGitAzureArgs } from '../azure/azureTools';
44
import { CommandId } from '../commands';
55
import { telemetry } from '../extension';
6-
import { fluxTools } from '../flux/fluxTools';
6+
import { CreateSourceGitGenericArgs, fluxTools } from '../flux/fluxTools';
77
import { KubernetesObjectKinds } from '../kubernetes/kubernetesTypes';
88
import { TelemetryEventNames } from '../telemetry';
99
import { refreshSourcesTreeView, refreshWorkloadsTreeView } from '../views/treeViews';
1010

11-
export async function createGitRepositoryGenericCluster(args: Parameters<typeof fluxTools['createSourceGit']>[0]) {
12-
11+
export async function createGitRepositoryGenericCluster(args: CreateSourceGitGenericArgs) {
1312
const parsedGitUrl = gitUrlParse(args.url);
1413
if (isUrlSourceAzureDevops(parsedGitUrl.source)) {
1514
// Azure devops git repo doesn't work with git implementation `go-git` and
@@ -23,6 +22,7 @@ export async function createGitRepositoryGenericCluster(args: Parameters<typeof
2322
});
2423

2524
const deployKey = await fluxTools.createSourceGit(args);
25+
refreshSourcesTreeView();
2626

2727
setTimeout(() => {
2828
// Wait a bit for the repository to have a failed state in case of SSH url
@@ -31,7 +31,7 @@ export async function createGitRepositoryGenericCluster(args: Parameters<typeof
3131
showDeployKeyNotificationIfNeeded(args.url, deployKey?.deployKey);
3232
}
3333

34-
export async function createGitRepositoryAzureCluster(args: Parameters<typeof azureTools['createSourceGit']>[0]) {
34+
export async function createGitRepositoryAzureCluster(args: CreateSourceGitAzureArgs) {
3535

3636
telemetry.send(TelemetryEventNames.CreateSource, {
3737
kind: KubernetesObjectKinds.GitRepository,

src/commands/deleteWorkload.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ export async function deleteWorkload(workloadNode: KustomizationNode | HelmRelea
6464

6565

6666
if (currentClusterInfo.result.isAzure && workloadType === 'kustomization') {
67-
await azureTools.deleteKustomization(workloadName, currentClusterInfo.result.contextName, currentClusterInfo.result.clusterProvider as AzureClusterProvider);
67+
const fluxConfigName = (workloadNode.resource.spec as any).sourceRef?.name;
68+
const azResourceName = azureTools.getAzName(fluxConfigName, workloadName);
69+
await azureTools.deleteKustomization(fluxConfigName, azResourceName, currentClusterInfo.result.contextName, currentClusterInfo.result.clusterProvider as AzureClusterProvider);
6870
} else {
6971
await fluxTools.delete(workloadType, workloadName, workloadNamespace);
7072
}

src/commands/openCreateSourceWebview.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/extension.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { statusBar } from './statusBar';
1212
import { Telemetry, TelemetryEventNames } from './telemetry';
1313
import { createTreeViews, clusterTreeViewProvider, sourceTreeViewProvider, workloadTreeViewProvider } from './views/treeViews';
1414
import { shell } from './shell';
15+
import { openConfigureGitOpsPanel } from './panels/configureGitOps';
1516

1617
/** Disable interactive modal dialogs, useful for testing */
1718
export let disableConfirmations = false;
@@ -24,7 +25,7 @@ export const enum GitOpsExtensionConstants {
2425
/** State that is saved even between editor reloads */
2526
export let globalState: GlobalState;
2627
/** Methods to report telemetry over Application Insights (Exceptions or Custom Events). */
27-
export let telemetry: Telemetry;
28+
export let telemetry: Telemetry | any;
2829

2930
/**
3031
* Called when GitOps extension is activated.
@@ -49,6 +50,8 @@ export async function activate(context: ExtensionContext) {
4950
// to the cluster
5051
checkIfOpenedFolderGitRepositorySourceExists();
5152

53+
// openConfigureGitOpsPanel(true);
54+
5255
telemetry.send(TelemetryEventNames.Startup);
5356

5457
if (globalState.get(GlobalStateKey.FirstEverActivationStorageKey) === undefined) {

0 commit comments

Comments
 (0)