omrikiei / ktunnel

A cli that exposes your local resources to kubernetes
GNU General Public License v3.0
928 stars 71 forks source link

URL Parse Error #8

Closed DrDonk closed 4 years ago

DrDonk commented 4 years ago

Trying to use ktunnel with Rancher deployed pod (the example pod ffrom this repo). The following error is displayed: INFO[0001] Injecting tunnel sidecar to dparsons/pyremotedebug INFO[0002] Waiting for deployment to be ready INFO[0007] Waiting for port forward to finish ERRO[0007] error upgrading connection: error creating request: parse https://rancher.plaidcloud.io%2Fk8s%2Fclusters%2Fc-wfdqx/api/v1/namespaces/dparsons/pods/pyremotedebug-9ff9fc4c-trbcg/portforward: invalid URL escape "%2F"

omrikiei commented 4 years ago

@DrDonk thanks for reporting! Is port-forward to the pod via kubectl working for you?

DrDonk commented 4 years ago

The port forward via 8000 works. The port 4321 does not work when using http://localhost:8000/ debug.

omrikiei commented 4 years ago

@DrDonk I pre-released an alpha that should fix this, could you try to inject with this version and let me know? https://github.com/omrikiei/ktunnel/releases/tag/v1.1.5-alpha

If it's resolved I'll release it

DrDonk commented 4 years ago

I still had a problem but later in the process. Maybe another piece of code with same issue. I'm sorry can't really help with Rancher as I just use it as setup by devops folks.

INFO[0000] Injecting tunnel sidecar to dparsons/pyremotedebug INFO[0000] Waiting for deployment to be ready INFO[0008] All pods located for port-forwarding INFO[0008] Waiting for port forward to finish ERRO[0008] error upgrading connection: error creating request: parse https://rancher.plaidcloud.io%2Fk8s%2Fclusters%2Fc-wfdqx/api/v1/namespaces/dparsons/pods/pyremotedebug-9ff9fc4c-c9pxz/portforward: invalid URL escape "%2F"

omrikiei commented 4 years ago

No worries, can you check how the cluster host appears in the kube config file and let me know?(~/.kube/config)

DrDonk commented 4 years ago

Here's the config file. I removed my token.

apiVersion: v1
clusters:
- cluster:
    server: https://rancher.plaidcloud.io/k8s/clusters/c-wfdqx
  name: io
contexts:
- context:
    cluster: io
    namespace: dparsons
    user: io
  name: io
current-context: io
kind: Config
preferences: {}
users:
- name: io
  user:
    token:
omrikiei commented 4 years ago

@DrDonk I can't seem to reproduce it in my environment, are you positive that you've been testing with version 1.1.5a? can you send me a checksum of that executable please?

DrDonk commented 4 years ago

The download checksum is the same as in the file 21b4e5d7e88f83699330de641871b8da234c37c0a83b8ae1ed7747fe2ced03ee ktunnel_1.1.5-alpha_Darwin_x86_64.tar.gz

The executable is: e2d2de3b42e31e7c0eeaeed29bfaea4ec5f6a605680f0f13b68657233412273d /Users/dave/xfer/ktunnel

I've actually been debugging it in Jetbrains Goland IDE and it seems to be a problem in library code but still tracking it down.

omrikiei commented 4 years ago

@DrDonk let me know if there's anything I can do to help, looking forward for your findings! thank you

DrDonk commented 4 years ago

The issue is that the Rancher host is actually a host and partial path which needs separating before constructing the serverURL.

Using a dummy URL the config has: https://rancher.xyz.io/k8s/clusters/c-wfdqx

Currently the parsing creates the url.URL struct with the fields like this:

serverURL.Scheme = https
serverURL.Path = /api/v1/namespaces/dparsons/pods/pyremotedebug-6c75b75cf5-7wbrb/portforward
serverURL.Host = rancher.xyz.io/k8s/clusters/c-wfdqx

The serverURL needs to be like this:

serverURL.Scheme = https
serverURL.Path = /k8s/clusters/c-wfdqx/api/v1/namespaces/dparsons/pods/pyremotedebug-6c75b75cf5-7wbrb/portforward
serverURL.Host = rancher.xyz.io

When I hard code the serverURL with the fields set up as above it works. I hope that makes sense. I don't develop in Go so not sure best way to acheive that when the host name includes a partial path.

omrikiei commented 4 years ago

I'll get to fixing it tonight/tomorrow night. Thank you!

omrikiei commented 4 years ago

@DrDonk it should be fixed in v1.1.7 I've tested it for correct behaviour, but it would be great if you can confirm that it works now. Thank you for all your efforts so far, and for this great catch!

DrDonk commented 4 years ago

I just pulled latest master and works in the IDE. So should be good to go. Thanks for writing this utility. I can debug in my test pods with SSH and Pycharm remote debugging, but for our staging and production pods we have to either use VSCode or Pycharm with the callback to the IDE to the debug server.

omrikiei commented 4 years ago

Thanks for being patient! Closing this now