Skip to content

Commit a004523

Browse files
committed
Fix review changes
1 parent 64799fb commit a004523

16 files changed

+107
-86
lines changed

.vscode/launch.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@
8888
}
8989
}
9090
]
91-
}
91+
}
92+

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -557,4 +557,5 @@
557557
}
558558
}
559559
}
560-
}
560+
}
561+

src/cli/cli-config.json

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"version": "0.19.0",
3737
"versionRange": "0.19.0",
3838
"versionRangeLabel": "v0.19.0",
39-
"versionLocalBuildRange": "",
4039
"dlFileName": "func",
4140
"cmdFileName": "func",
4241
"filePrefix": "",

src/cli/cli-config.ts

+6-17
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface CliConfig {
4646
location?: string;
4747
}
4848
export interface Config {
49-
cmd?: CliConfig;
49+
func?: CliConfig;
5050
kn?: CliConfig;
5151
kubectl?: CliConfig;
5252
}
@@ -149,11 +149,8 @@ export class CmdCliConfig {
149149
if (toolLocation === undefined) {
150150
const cliFile = `.vs-${cmd}`;
151151
// Look in [HOME]/.vs-[CMD]/ for the [CMD] cli executable
152-
const toolCacheLocation = path.resolve(
153-
Platform.getUserHomePath(),
154-
cliFile,
155-
(CmdCliConfig.tools[cmd] as CliConfig).cmdFileName,
156-
);
152+
const cliFilePath = path.resolve(Platform.getUserHomePath(), cliFile);
153+
const toolCacheLocation = path.resolve(cliFilePath, (CmdCliConfig.tools[cmd] as CliConfig).cmdFileName);
157154
// If [CMD] cli is installed, get it's install location/path
158155
const whichLocation = shell.which(cmd);
159156
// Get a list of locations.
@@ -168,11 +165,7 @@ export class CmdCliConfig {
168165
// If the cli tool is still not found then we will need to install it.
169166
if (foundToolLocation === undefined || foundToolLocation === null) {
170167
// Set the download location for the cli executable.
171-
const toolDlLocation = path.resolve(
172-
Platform.getUserHomePath(),
173-
cliFile,
174-
(CmdCliConfig.tools[cmd] as CliConfig).dlFileName,
175-
);
168+
const toolDlLocation = path.resolve(cliFilePath, (CmdCliConfig.tools[cmd] as CliConfig).dlFileName);
176169
// Message for expected version number
177170
const installRequest = `Download and install v${(CmdCliConfig.tools[cmd] as CliConfig).version}`;
178171
// Create a pop-up that asks to download and install.
@@ -186,7 +179,7 @@ export class CmdCliConfig {
186179
'Cancel',
187180
);
188181
// Ensure that the directory exists. If the directory structure does not exist, then create it.
189-
fsExtra.ensureDirSync(path.resolve(Platform.getUserHomePath(), cliFile));
182+
fsExtra.ensureDirSync(cliFilePath);
190183
// If the user selected to download and install then do this.
191184
if (response === installRequest) {
192185
// Display a Progress notification while downloading
@@ -231,11 +224,7 @@ export class CmdCliConfig {
231224
await CmdCliConfig.detectOrDownload(cmd);
232225
} else if (action !== 'Cancel') {
233226
if (toolDlLocation.endsWith('.zip') || toolDlLocation.endsWith('.tar.gz')) {
234-
await Archive.unzip(
235-
toolDlLocation,
236-
path.resolve(Platform.getUserHomePath(), cliFile),
237-
(CmdCliConfig.tools[cmd] as CliConfig).filePrefix,
238-
);
227+
await Archive.unzip(toolDlLocation, cliFilePath, (CmdCliConfig.tools[cmd] as CliConfig).filePrefix);
239228
await fsExtra.remove(toolDlLocation);
240229
} else if (toolDlLocation.endsWith('.gz')) {
241230
await Archive.unzip(toolDlLocation, toolCacheLocation, (CmdCliConfig.tools[cmd] as CliConfig).filePrefix);

src/cli/cmdCli.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ export class CmdCli implements Cli {
106106
error = err;
107107
});
108108
// eslint-disable-next-line @typescript-eslint/no-misused-promises
109-
command.on('exit', async () => {
109+
command.on('close', async () => {
110110
if (error && stdout === '') {
111111
// "undefinedError: Get \"https://api.devcluster.openshift.com:6443/apis/serving.knative.dev/v1/namespaces/default/services\": dial tcp: lookup api.devcluster.openshift.com on 127.0.0.1:53: no such host\nRun 'kn --help' for usage\n"
112-
if (typeof error === 'string' && error.search('no such host') > 0 && error.search('failed to resolve image') === -1) {
112+
if (
113+
typeof error === 'string' &&
114+
(error.search('no such host') > 0 || error.search('error connecting to the cluster')) &&
115+
error.search('failed to resolve image') === -1
116+
) {
113117
if (CmdCli.clusterErrorNotReported) {
114118
CmdCli.clusterErrorNotReported = false;
115119
await window.showErrorMessage(`The cluster is not up. Please log into a running cluster.`, { modal: true }, 'OK');

src/cli/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const enum Kind {
1414
export enum FunctionContextType {
1515
NONE = 'none',
1616
FUNCTION = 'functions',
17+
FAILNAMESPACENODE = 'failNamespaceNode',
1718
NAMESPACENODE = 'namespaceNode',
1819
LOCAlFUNCTIONS = 'localFunctions',
1920
LOCAlFUNCTIONSENABLEMENT = 'localFunctionsEnablement',

src/cli/kubectl-api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class KubectlAPI {
3131
return kubectlCliCommand(['version', '--short', '--client']);
3232
}
3333

34-
static currentNamesapce(): CliCommand {
34+
static currentNamespace(): CliCommand {
3535
return kubectlCliCommand(['config', 'view', '--minify', '-o', 'json']);
3636
}
3737

src/functions/active-namespace.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ import { KubectlAPI } from '../cli/kubectl-api';
1010
import { getStderrString } from '../util/stderrstring';
1111

1212
export async function activeNamespace(): Promise<string> {
13-
const result = await knExecutor.execute(KubectlAPI.currentNamesapce(), process.cwd(), false);
13+
const result = await knExecutor.execute(KubectlAPI.currentNamespace(), process.cwd(), false);
1414
if (result.error) {
1515
// eslint-disable-next-line @typescript-eslint/no-floating-promises
1616
window.showErrorMessage(`Fail to fetch the Namespace Error: ${getStderrString(result.error)}`);
1717
return null;
1818
}
19-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
20-
const currentNamespace: Namespace = JSON.parse(result.stdout);
21-
return currentNamespace.contexts[0].context.namespace;
19+
try {
20+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
21+
const currentNamespace: Namespace = JSON.parse(result.stdout);
22+
return currentNamespace.contexts[0].context.namespace;
23+
} catch (err) {
24+
return null;
25+
}
2226
}

src/functions/func.ts

+36-24
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { FuncAPI } from '../cli/func-api';
1919

2020
export interface Func {
2121
getFunctionNodes(): Promise<FunctionNode[]>;
22-
getDeployedFunction(func: FunctionNode): Promise<FunctionNode[]>;
22+
getTreeFunction(func: FunctionNode): Promise<FunctionNode[]>;
23+
getDeployedFunction(func: FunctionNode): Promise<Map<string, FunctionNode>>;
2324
getLocalFunction(func: FunctionNode, functionTreeView: Map<string, FunctionNode>): Promise<FunctionNode[]>;
2425
}
2526

@@ -34,35 +35,50 @@ export class FuncImpl implements Func {
3435
public async _getFunctionsNodes(): Promise<FunctionNode[]> {
3536
const functionsTree: FunctionNode[] = [];
3637
const currentNamespace: string = await activeNamespace();
37-
const functionsNode = new FunctionNodeImpl(
38-
FuncImpl.ROOT,
39-
currentNamespace,
40-
FunctionContextType.NAMESPACENODE,
41-
this,
42-
TreeItemCollapsibleState.Collapsed,
43-
);
38+
let functionsNode: FunctionNode;
39+
if (!currentNamespace) {
40+
functionsNode = new FunctionNodeImpl(
41+
FuncImpl.ROOT,
42+
'default',
43+
FunctionContextType.FAILNAMESPACENODE,
44+
this,
45+
TreeItemCollapsibleState.Collapsed,
46+
);
47+
} else {
48+
functionsNode = new FunctionNodeImpl(
49+
FuncImpl.ROOT,
50+
currentNamespace,
51+
FunctionContextType.NAMESPACENODE,
52+
this,
53+
TreeItemCollapsibleState.Collapsed,
54+
);
55+
}
4456
functionsTree.push(functionsNode);
4557
FuncImpl.ROOT.getChildren = () => functionsTree;
4658
return functionsTree;
4759
}
4860

49-
async getDeployedFunction(func: FunctionNode): Promise<FunctionNode[]> {
61+
async getTreeFunction(func: FunctionNode): Promise<FunctionNode[]> {
62+
const deployedFunction: Map<string, FunctionNode> = await this.getDeployedFunction(func);
63+
const deployedLocalFunction: FunctionNode[] = await this.getLocalFunction(func, deployedFunction);
64+
if (deployedLocalFunction.length === 0) {
65+
return [
66+
new FunctionNodeImpl(func, 'No Functions Found', FunctionContextType.NONE, this, TreeItemCollapsibleState.None, null),
67+
];
68+
}
69+
return deployedLocalFunction;
70+
}
71+
72+
async getDeployedFunction(func: FunctionNode): Promise<Map<string, FunctionNode>> {
5073
const functionTreeView = new Map<string, FunctionNode>();
5174
let result: CliExitData;
52-
try {
53-
result = await knExecutor.execute(FuncAPI.funcList(), process.cwd(), false);
54-
} catch (err) {
55-
// ignores
56-
}
5775
let functionList: FunctionList[];
58-
if (result.error) {
59-
// ignores
60-
}
6176
try {
77+
result = await knExecutor.execute(FuncAPI.funcList(), process.cwd(), false);
6278
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
6379
functionList = JSON.parse(result.stdout);
64-
} catch (error) {
65-
// ignore
80+
} catch (err) {
81+
// ignores
6682
}
6783
if (functionList && functionList.length !== 0) {
6884
functionList.forEach((value) => {
@@ -79,8 +95,7 @@ export class FuncImpl implements Func {
7995
functionTreeView.set(value.name, obj);
8096
});
8197
}
82-
// eslint-disable-next-line no-return-await
83-
return await this.getLocalFunction(func, functionTreeView);
98+
return functionTreeView;
8499
}
85100

86101
async getLocalFunction(func: FunctionNode, functionTreeView: Map<string, FunctionNode>): Promise<FunctionNode[]> {
@@ -158,9 +173,6 @@ export class FuncImpl implements Func {
158173
}
159174
}
160175
if (functionTreeView.size === 0) {
161-
functionList.push(
162-
new FunctionNodeImpl(func, 'No Functions Found', FunctionContextType.NONE, this, TreeItemCollapsibleState.None, null),
163-
);
164176
return functionList;
165177
}
166178
functionTreeView.forEach((value) => {

src/functions/function-command/build-and-deploy-function.ts

+29-28
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,25 @@ import { functionExplorer } from '../functionsExplorer';
1717

1818
const imageRegex = RegExp('[^/]+\\.[^/.]+\\/([^/.]+)(?:\\/[\\w\\s._-]*([\\w\\s._-]))*(?::[a-z0-9\\.-]+)?$');
1919

20-
async function functionBuilder(image: string): Promise<ImageAndBuild> {
21-
const builder = await vscode.window.showInputBox({
20+
async function showInputBox(promptMessage: string, inputValidMessage: string): Promise<string> {
21+
// eslint-disable-next-line no-return-await
22+
return await vscode.window.showInputBox({
2223
ignoreFocusOut: true,
23-
prompt: 'Provide Buildpack builder, either an as a an image name or a mapping name.',
24+
prompt: promptMessage,
2425
validateInput: (value: string) => {
2526
if (!imageRegex.test(value)) {
26-
return 'Provide full image name in the form [registry]/[namespace]/[name]:[tag]';
27+
return inputValidMessage;
2728
}
2829
return null;
2930
},
3031
});
32+
}
33+
34+
async function functionBuilder(image: string): Promise<ImageAndBuild> {
35+
const builder = await showInputBox(
36+
'Provide Buildpack builder, either an as a an image name or a mapping name.',
37+
'Provide full image name in the form [registry]/[namespace]/[name]:[tag]',
38+
);
3139
if (!builder) {
3240
return null;
3341
}
@@ -50,24 +58,15 @@ async function functionImage(selectedFolderPick: vscode.Uri, skipBuilder?: boole
5058
const imagePick =
5159
imageList.length === 1
5260
? imageList[0]
53-
: await vscode.window.showInputBox({
54-
ignoreFocusOut: true,
55-
prompt: 'Provide full image name in the form [registry]/[namespace]/[name]:[tag]',
56-
validateInput: (value: string) => {
57-
if (!imageRegex.test(value)) {
58-
return 'Provide full image name in the form [registry]/[namespace]/[name]:[tag]';
59-
}
60-
return null;
61-
},
62-
});
61+
: await showInputBox(
62+
'Provide full image name in the form [registry]/[namespace]/[name]:[tag]',
63+
'Provide full image name in the form [registry]/[namespace]/[name]:[tag]',
64+
);
6365
if (!imagePick) {
6466
return null;
6567
}
6668
if (!funcData?.[0]?.builder.trim() && !skipBuilder) {
6769
const builder = await functionBuilder(imagePick);
68-
if (!builder) {
69-
return null;
70-
}
7170
return builder;
7271
}
7372
return { image: imagePick };
@@ -84,7 +83,7 @@ async function pathFunction(): Promise<FolderPick> {
8483
}
8584
}
8685
if (folderPicks.length === 0) {
87-
const message = 'No project exit which contain func.yaml in it.';
86+
const message = 'No project exist which contain func.yaml in it.';
8887
telemetryLog('func_yaml_not_found', message);
8988
// eslint-disable-next-line @typescript-eslint/no-floating-promises
9089
vscode.window.showInformationMessage(message);
@@ -98,20 +97,25 @@ async function pathFunction(): Promise<FolderPick> {
9897
ignoreFocusOut: true,
9998
placeHolder: 'Select function',
10099
});
101-
if (!selectedFolderPick) {
102-
return null;
103-
}
104100
return selectedFolderPick;
105101
}
106102

107-
export async function buildFunction(context?: FunctionNode): Promise<void> {
103+
async function selectedFolder(context?: FunctionNode): Promise<FolderPick> {
108104
let selectedFolderPick: FolderPick;
109105
if (!context) {
110106
selectedFolderPick = await pathFunction();
111107
if (!selectedFolderPick) {
112108
return null;
113109
}
114110
}
111+
return selectedFolderPick;
112+
}
113+
114+
export async function buildFunction(context?: FunctionNode): Promise<void> {
115+
const selectedFolderPick: FolderPick = await selectedFolder(context);
116+
if (!selectedFolderPick) {
117+
return null;
118+
}
115119
const funcData = await functionImage(context ? context.contextPath : selectedFolderPick.workspaceFolder.uri);
116120
if (!funcData) {
117121
return null;
@@ -129,12 +133,9 @@ export async function buildFunction(context?: FunctionNode): Promise<void> {
129133
}
130134

131135
export async function deployFunction(context?: FunctionNode): Promise<void> {
132-
let selectedFolderPick: FolderPick;
133-
if (!context) {
134-
selectedFolderPick = await pathFunction();
135-
if (!selectedFolderPick) {
136-
return null;
137-
}
136+
const selectedFolderPick: FolderPick = await selectedFolder(context);
137+
if (!selectedFolderPick) {
138+
return null;
138139
}
139140
const funcData = await functionImage(context ? context.contextPath : selectedFolderPick.workspaceFolder.uri, true);
140141
if (!funcData) {

src/functions/function-command/create-function.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function validateInputField(
6464
id: string,
6565
items: ValidatorResponseItem[],
6666
): ValidatorResponse {
67-
if (fs.existsSync(pathValue) && pathValue) {
67+
if (fs.existsSync(pathValue)) {
6868
items.push(createValidationItem(SEVERITY.ERROR, id, message));
6969
folderStatus.set('folder_present', true);
7070
return { items };

src/functions/function-command/run-function.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export async function runFunction(context?: FunctionNode): Promise<void> {
1111
if (!context) {
1212
return null;
1313
}
14+
// TO DO
1415
await knExecutor.executeInTerminal(FuncAPI.runFunc(context.contextPath.fsPath));
1516
}

src/functions/function-tree-view/functionsTreeItem.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ export class FunctionNodeImpl implements FunctionNode {
3535
tooltip: 'NameSpace: {label}',
3636
description: '',
3737
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
38-
getChildren: () => this.func.getDeployedFunction(this),
38+
getChildren: () => this.func.getTreeFunction(this),
39+
},
40+
failNamespaceNode: {
41+
icon: '',
42+
tooltip: '{label}',
43+
description: '',
44+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
45+
getChildren: () => this.func.getTreeFunction(this),
3946
},
4047
localFunctions: {
4148
icon: '',
@@ -95,6 +102,9 @@ export class FunctionNodeImpl implements FunctionNode {
95102
this,
96103
);
97104
}
105+
if (this.contextValue === FunctionContextType.FAILNAMESPACENODE) {
106+
return format(`Cluster is active?`, this);
107+
}
98108
return format(this.CONTEXT_DATA[this.contextValue].tooltip, this);
99109
}
100110

0 commit comments

Comments
 (0)