Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding support for function #156

Merged
merged 45 commits into from
Jan 19, 2022
Merged

Conversation

sudhirverma
Copy link
Contributor

@sudhirverma sudhirverma commented Jul 13, 2021

Fix: #155
Fix: #165
Fix: #166
Fix: #159

@sudhirverma sudhirverma marked this pull request as draft July 13, 2021 11:20
@sudhirverma sudhirverma force-pushed the 155 branch 2 times, most recently from 51cc60c to d702a7d Compare July 19, 2021 12:11
@@ -59,4 +89,4 @@
}
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a new line here.

@joshuawilson
Copy link
Member

Please do not merge without adding tests.

@@ -3,10 +3,23 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { WorkspaceFolder } from 'vscode';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why import all and a specific thing?

@sudhirverma sudhirverma force-pushed the 155 branch 2 times, most recently from a2e1b24 to 3e14a77 Compare July 22, 2021 10:11
Copy link

@evidolob evidolob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I provide wrong docker image name(with not valid docker registry path), build pass successfully but when I run deploy I got Deploying Function... notification which load never replace with error notification.

Another feedback, I think we need to stream logs on function build command, as that process can take a while, and I as user want to track build progress.

package.json Outdated
@@ -382,4 +420,4 @@
}
}
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add new line.

if (functionCheck.test(result.stdout)) {
return [new FunctionNodeImpl(null, 'No Function Found', FunctionContextType.NONE, TreeItemCollapsibleState.None, null)];
}
window.showErrorMessage(`Fail to parse Json Error: ${getStderrString(error)}`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got this error when my cluster doesn't contains any functions. The func CLI ignore -o json and provide output:

No functions found
null

for func list -o json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the func cli version they have done changes in the output.

apple@Apples-MacBook-Pro vscode-knative % func list -o json
No functions found in knative-serving namespace
apple@Apples-MacBook-Pro vscode-knative % ~/.vs-func/func list -o json
No functions found
null

@sudhirverma sudhirverma requested a review from evidolob August 11, 2021 12:17
@sudhirverma
Copy link
Contributor Author

sudhirverma commented Aug 11, 2021

Another feedback, I think we need to stream logs on function build command, as that process can take a while, and I as user want to track build progress.

I think we can run the build and deploy command on the terminal so that we can see the stream logs

@mohitsuman
Copy link
Collaborator

@sudhirverma can you please have a look at the failed GH builds, if we can fix them.

@odockal
Copy link
Collaborator

odockal commented Sep 17, 2021

@mohitsuman @sudhirverma Fixes for failing builds could be solved in #148.

@odockal
Copy link
Collaborator

odockal commented Sep 17, 2021

Rebase this PR please.

@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2021

Codecov Report

Merging #156 (02b2567) into main (6b4949e) will decrease coverage by 2.81%.
The diff coverage is 82.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #156      +/-   ##
==========================================
- Coverage   96.55%   93.73%   -2.82%     
==========================================
  Files          51       70      +19     
  Lines        2233     2841     +608     
  Branches      336      452     +116     
==========================================
+ Hits         2156     2663     +507     
- Misses         77      178     +101     
Impacted Files Coverage Δ
src/util/constants.ts 0.00% <0.00%> (ø)
src/cli/cmdCli.ts 53.62% <20.00%> (+2.10%) ⬆️
src/util/existing-workspace-folder-pick.ts 33.33% <33.33%> (ø)
.../functions/function-tree-view/functionsTreeItem.ts 36.95% <36.95%> (ø)
src/cli/cli-config.ts 76.34% <50.00%> (-4.38%) ⬇️
src/extension.ts 83.67% <52.94%> (-16.33%) ⬇️
src/cli/func-api.ts 65.90% <65.90%> (ø)
src/functions/active-namespace.ts 76.92% <76.92%> (ø)
src/functions/function-command/create-function.ts 79.31% <79.31%> (ø)
src/util/stderrstring.ts 80.00% <80.00%> (ø)
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b4949e...02b2567. Read the comment docs.

@sudhirverma sudhirverma marked this pull request as ready for review December 17, 2021 11:00
@sudhirverma sudhirverma requested a review from lstocchi December 17, 2021 11:05
Copy link
Contributor

@lstocchi lstocchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i started playing with it. The major problem i faced is that it asks me to download clis (kubectl and func) multiple times.

E.g I have a function opened in workspace, it is displayed fine on the tree.
I create a new function using the wizard and open it in same workspace, the tree is not refreshed correctly and i notice it asks me to download the cli again... but i already downloaded it before otherwise it would not have worked.

// Change the file permissions if on Linux or Mac
if (Platform.OS !== 'win32') {
fs.chmodSync(toolCacheLocation, 0o755);
} else {
fs.chmodSync(toolCacheLocation, '+x');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure about it... is it executing chmod necessary in windows? isn't .exe already executable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it only read and write -rw-r--r--@ 1 apple staff 66777600 Dec 20 18:18 func_windows_amd64.exe

import { CliCommand, CmdCli, createCliCommand } from './cmdCli';

function funcCliCommand(cmdArguments: string[]): CliCommand {
return createCliCommand('func', ...cmdArguments);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be func.exe in windows?

if (toolDlLocation.endsWith('.zip') || toolDlLocation.endsWith('.tar.gz')) {
await Archive.unzip(
toolDlLocation,
path.resolve(Platform.getUserHomePath(), cliFile),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you use toolCacheLocation as the other else if branch and merge both?

@@ -67,41 +64,10 @@ async function getVersion(location: string): Promise<string> {
if (cmd === 'kubectl') {
version = KubectlAPI.getKubectlVersion(location);
}
if (cmd === 'func') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting this here as i can't comment above but it's about line ~48.
The interface Config is

export interface Config {
  cmd?: CliConfig;
  kn?: CliConfig;
  kubectl?: CliConfig;
}

Why cmd?? What does that represent?
Shouldn't you add func?: CliConfig there as well?

// eslint-disable-next-line @typescript-eslint/no-floating-promises
startTelemetry(extensionContext);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
setCommandContext(CommandContext.funcDisableRun, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add it? I cannot find any way to change it to true, missing something?

Copy link
Contributor Author

@sudhirverma sudhirverma Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for localFunctionsEnablement context or node it will be disabled and always false.

id: string,
items: ValidatorResponseItem[],
): ValidatorResponse {
if (fs.existsSync(pathValue) && pathValue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not this be the opposite order? So if pathValue is null you don't execute existsSync?

}
if (context.functionStatus === FunctionStatus.CLUSTERLOCALBOTH || context.functionStatus === FunctionStatus.LOCALONLY) {
const funcYaml = path.join(context.contextPath.fsPath, 'func.yaml');
await fsExtra.remove(funcYaml);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you deleting the function locally? Maybe users want to delete it on the current namespace only.
I would completely remove the delete action for local functions. What are we going to delete? Only the func.yaml? All the code? How can we decide? If users wants to delete something locally they can do it manually or we need to be extra clear about what we are going to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will wait till we get confirmation on what should we do with the local function whether we should delete the function or not.

if (!context) {
return null;
}
await knExecutor.executeInTerminal(FuncAPI.runFunc(context.contextPath.fsPath));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a guard for contextPath or it contains a valid value in all cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it will contain the valid value I will test it on windows.

}

export interface Namespace {
Kind?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need Kind?

async reveal(item: FunctionNode): Promise<void> {
await this.refresh(item.getParent());
await this.treeView.reveal(item);
await this.treeView.reveal(item);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this row is a duplicate?

Copy link
Contributor

@lstocchi lstocchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried again a full example like create new function -> build -> run -> deploy and delete. Everything worked fine. There is just an annoying dialog which pops up telling me i'm not connected to a cluster. In the video below you can see i have access to a cluster.

cluster_not_logged

@lstocchi
Copy link
Contributor

lstocchi commented Jan 3, 2022

I think there is an issue with the regex that verifies the image name.
If i start writing sio/s it correctly fails telling me Provide full image name in the form registry/namespace/name:tag
image

but then if i add a dot -> s.io/s it is accepted as correct name and then it fails during execution.
image

In IJ, Jeff made me add an example in the validation message and a default image name as placeholder so user can just click next if they don't want to change anything.
So the vlidation message looks like -> Provide full image name in the form [registry]/[namespace]/[name]:[tag] (e.g quay.io/boson/image:latest)
and the default image name as placeholder is "quay.io/" + defaultUsername + "/" + name + ":latest" where defaultUsername is the username env variable and name is the function name in func.yaml

@sudhirverma sudhirverma requested a review from lstocchi January 4, 2022 11:52
Copy link
Contributor

@lstocchi lstocchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine for me. There are some improvements to add (suggested by Jeff) #169 and #168 but it's better to stop adding stuff here. It is becoming huge and difficult to review.

@sudhirverma sudhirverma merged commit b5cb711 into redhat-developer:main Jan 19, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
7 participants