openfaas / faas-cli

Official CLI for OpenFaaS
https://www.openfaas.com/
Other
794 stars 226 forks source link

Regression with path building on Windows #805

Closed alanisaac closed 4 years ago

alanisaac commented 4 years ago

Please note -- there's a lot to my setup, and I have no idea where the actual issue lies. But after hours searching for various issues among faas-cli, faas-netes, k3s, and multipass, I haven't been able to find anything useful, so I thought I'd start at the top of the stack.

Expected Behaviour

I'm trying to deploy a simple hello-world python function through faas-cli, and I'd expect the function to be deployed.

While my setup has a number of layers, I'm trying my best to follow the simple hello-world versions of all of them (how to run k3s on multipass, how to run openfaas on k8s, etc.).

Current Behaviour

I'm running OpenFaaS on k3s through a multipass VM on top of Windows. When I navigate to the OpenFaaS UI at http://<vm-ip>:31112/ui/, the page loads just fine.

However, using the CLI I see the following:

faas-cli deploy -f hello-python.yml --gateway http://<vm-ip>:31112/
Deploying: hello-python.

Unexpected status: 404, message: 404 page not found

I get the same message for most function-based commands pointed at that gateway, such as faas-cli list. However, faas-cli login works just fine:

faas-cli login -g http://<vm-ip>:31112/ -u ***** --password *****
WARNING! Using --password is insecure, consider using: cat ~/faas_pass.txt | faas-cli login -u user --password-stdin
Calling the OpenFaaS server to validate the credentials...
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
credentials saved for admin http://<vm-ip>:31112

Here are the services in the openfaas namespace in k3s:

NAME                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
prometheus          ClusterIP   10.43.82.144    <none>        9090/TCP         28m
gateway             ClusterIP   10.43.190.141   <none>        8080/TCP         28m
nats                ClusterIP   10.43.205.164   <none>        4222/TCP         28m
gateway-external    NodePort    10.43.189.111   <none>        8080:31112/TCP   28m
basic-auth-plugin   ClusterIP   10.43.231.22    <none>        8080/TCP         28m
alertmanager        ClusterIP   10.43.100.208   <none>        9093/TCP         28m

I deployed OpenFaaS through Helm, steps to walk through my setup are below.

Steps to Reproduce (for bugs)

  1. On a Windows environment, install Multipass
  2. Download the powershell and shell scripts in this gist, and run the powershell script.
  3. The final step of the script will open the browser to http://<vm.ip>:31112/. Note that the UI loads fine.
  4. Follow the tutorial here starting from Step 3: Your first serverless function.
  5. Observe that the errors above are seen in the faas-cli

Context

I'm trying to put together a 'quick start' for OpenFaaS that I can run in a local Windows environment through multipass.

Your Environment

Server: Docker Engine - Community Engine: Version: 19.03.8 API version: 1.40 (minimum version 1.12) Go version: go1.12.17 Git commit: afacb8b Built: Wed Mar 11 01:29:16 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: v1.2.13 GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc: Version: 1.0.0-rc10 GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd docker-init: Version: 0.18.0 GitCommit: fec3683

* Are you using Docker Swarm (FaaS-swarm ) or Kubernetes (FaaS-netes)?
Kubernetes / k3s.  Output of `k3s -v`:

k3s version v1.17.4+k3s1 (3eee8ac3)


* Operating System and version (e.g. Linux, Windows, MacOS):
Local system:

OS Name: Microsoft Windows 10 Enterprise OS Version: 10.0.18362 N/A Build 18362

Multipass VM running k3s:

Description: Ubuntu 18.04.4 LTS Release: 18.04 Codename: bionic



* Link to your project or a code example to reproduce issue:
https://gist.github.com/alanisaac/5b3dbcc3c03a5950e0baec5d39680a7a
alexellis commented 4 years ago

Please can you use the official installer https://get-arkade.dev for this installation? Launch it from git bash rather than PowerShell for the deployment.

Can you also spend some time in the OpenFaaS docs? There's a troubleshooting guide and a number of steps you can run to debug this error.

I'm going to close as I can't reproduce the error and I think this is more of a support issue. Feel free to keep the discussion going on Slack.

alexellis commented 4 years ago

/msg: slack

derek[bot] commented 4 years ago

-- Join Slack to connect with the community https://docs.openfaas.com/community

alexellis commented 4 years ago

/set title: Technical support

alanisaac commented 4 years ago

I appreciate the pointers. Before posting, I did go through the troubleshooting guide, the associated workshop, and tried both arkade and helm -- nothing's worked so far.

I'll try slack. Thanks!

alexellis commented 4 years ago

If you went through all of the troubleshooting guide, then you could have pasted the output on the thread.

I'd suggest that you work through this, it should be of help to you with finding your 404 error: https://docs.openfaas.com/deployment/troubleshooting/#troubleshoot-kubernetes

And make sure that you're not executing against port 8080, k3s usually deploys Traefik's dashboard on this port.

alanisaac commented 4 years ago

@alexellis thank you for the replies!

I worked through those guides -- my apologies for any confusion by not initially posting the outputs of that walkthrough. However, I think I now know what's going on.

--

I haven't had an opportunity to use golang yet, but I thought I'd dive in and try to debug this issue. I set up debugging for the deploy command in Visual Studio Code, and found the following:

When a request is created in the following lines: https://github.com/openfaas/faas-cli/blob/f9a4019176bf4ff0c2c3e7e39c8d2c01b3ddb94a/proxy/deploy.go#L147-L148

The resulting request object has the following property:

request.URL.Path="/\system\functions"

That URL did not look correct. As a test, I used Fiddler to make a request with the same body as I saw in code to POST /system/functions, and the function was deployed correctly.

I dove deeper and it looks like the root cause is the following line:

https://github.com/openfaas/faas-cli/blob/f9a4019176bf4ff0c2c3e7e39c8d2c01b3ddb94a/proxy/client.go#L70

If I change that line instead to:

endpoint.Path = endpoint.Path + u.Path

The URL Path is correct, and my function deploys fine. (Note: I realize that's probably not the right go solution here, just my experiment.) Looking back in commit history, I see the following comment from the PR that last changed this line, noting that the path would be different on Windows:

https://github.com/openfaas/faas-cli/commit/f0f57335e6d435f44f36675fb0df43931e2f5969#r38508984

I believe that is the root cause of this issue, and that some functions in the latest version of the CLI could be broken on Windows (unless there's something else environmental on my machine causing this behavior). Running through git bash, as I've seen recommended, does not change this behavior (I wouldn't expect it to, but just wanted to check).

EDIT: since I see this change is relatively recent, I tried going back one version to faas-cli.exe version 0.12.2. In that version, deploy commands work correctly on my environment.

alexellis commented 4 years ago

@LucasRoesler it seems like join() from filepath was used instead of path was used in the following PR and caused unexpected behaviour on Windows (only):

https://github.com/openfaas/faas-cli/commit/f0f57335e6d435f44f36675fb0df43931e2f5969#r38508984

Would you be able to take a look please? If you need a Windows VM, they can be run via Vagrant, on AWS, or via VirtualBox.

If changing to path.Join still works on Linux/Mac, then we could ask @alanisaac to test the patch if you don't have time to create a VM.

alexellis commented 4 years ago

@alanisaac thanks for spending the time to look into this in detail

alexellis commented 4 years ago

/set title: Regression with path building on Windows