GoogleCloudPlatform / cloud-code-vscode

Cloud Code for Visual Studio Code: Issues, Documentation and more
Other
414 stars 111 forks source link

Debugging on a remote docker + kubernetes not working #739

Open cheburakshu opened 1 year ago

cheburakshu commented 1 year ago

Type: Bug

Context

Extension version: 1.21.3 VS Code version: Code 1.75.1 (Universal) (441438abd1ac652551dbe4d408dfcec8a499b8bf, 2023-02-08T21:34:59.000Z) OS version: Darwin x64 22.2.0 Modes: Sandboxed: No

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz (16 x 2400)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off| |Load (avg)|3, 3, 3| |Memory (System)|32.00GB (2.71GB free)| |Process Argv|. --crash-reporter-id a0d9210e-6c09-416f-b4af-7c0f15ae8f41| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383cf:30185419 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 pythonvspyl392:30443607 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 vscoreces:30445986 pythondataviewer:30285071 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 cmake_vspar411:30581797 vsaa593:30376534 pythonvs932:30410667 cppdebug:30492333 vsclangdc:30486549 c4g48928:30535728 dsvsc012cf:30540253 pynewvextcfv2:30669238 azure-dev_surveyone:30548225 pyindex848:30662994 nodejswelcome1:30587005 3biah626:30602489 pyind779:30662992 89544117:30613380 pythonsymbol12:30657548 6233i204:30664135 ```
Description:

I am using a remote host that has both docker and kubernetes installed (pls see KUBECONFIG and DOCKER_HOST settings). skaffold is able to deploy it but unable to debug the code. Please find the repo steps below. Pls let me know if you need more information. The same works on a local kubernetes cluster.

bash-3.2$ env|grep -E "KUBECONFIG|DOCKER_HOST"
DOCKER_HOST=tcp://my-redacted-host.com:2375
KUBECONFIG=/tmp/k3s.yaml

bash-3.2$ pwd
/tmp/remote-debug

bash-3.2$ ls
Dockerfile.python   hello-python.yml    run.py          skaffold.yaml

bash-3.2$ cat Dockerfile.python 
FROM python:3.10.9-alpine3.17

RUN pip3 install flask

WORKDIR /app

COPY . .

CMD ["python3", "/app/run.py"]

bash-3.2$ cat hello-python.yml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-python
  labels:
    app: hello-python
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-python
  template:
    metadata:
      labels:
        app: hello-python
    spec:
      containers:
      - name: hello-python
        image: hello-python:latest
        imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
  name: hello-python
  labels:
    app: hello-python
spec:
  selector:
    app: hello-python
  ports:
    - port: 8082
      targetPort: 8082
      protocol: TCP
      name: hello-python
  type: LoadBalancer

bash-3.2$ cat run.py 
"""
Simple http endpoint with python
"""
from flask import Flask

app = Flask(__name__)

@app.route("/python")
def hello():
    return "Hello, Python!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8082)
bash-3.2$ cat skaffold.yaml 
apiVersion: skaffold/v4beta1
kind: Config
metadata:
  name: hello
build:
  artifacts:
  - image: hello-python
    context: .
    docker:
      dockerfile: Dockerfile.python
  tagPolicy:
    customTemplate:
      template: "latest"
  local:
    push: false

manifests:
  rawYaml:
  - "*.yml"

deploy:
  kubectl:
    defaultNamespace: default

bash-3.2$ code .

<start debugger in vscode now. chose /app as the remote source path when prompted>

Autogenerated launch.json looks like this

{
    "configurations": [
        {
            "name": "Kubernetes: Run/Debug",
            "type": "cloudcode.kubernetes",
            "request": "launch",
            "skaffoldConfig": "${workspaceFolder}/skaffold.yaml",
            "watch": true,
            "cleanUp": true,
            "portForward": true,
            "debug": [
                {
                    "image": "hello-python",
                    "containerName": "hello-python",
                    "sourceFileMap": {
                        "${workspaceFolder}": "/app"
                    }
                }
            ]
        }
    ]
}

Error:

image

The deployment itself works when hit with curl.

bash-3.2$ curl my-redacted-host.com:8082/python
Hello, Python!bash-3.2$ 
cheburakshu commented 1 year ago

The same issue exists for Java too as I have described here. Sometimes I get the pop up about debuggee unable to attach. https://github.com/GoogleContainerTools/skaffold/issues/8454

cheburakshu commented 1 year ago

Vscode log

[Cloud Code]: Validating deployment settings...
[Cloud Code]: Checking kubectl, skaffold dependencies...
[Cloud Code]: Checking kubectl current context...
[Cloud Code]: Checking active context...
[Cloud Code]: Checking additional dependencies gcloud and docker...
[Cloud Code]: Setting up image registry...
[Cloud Code]: Setting up build environment...
[Cloud Code]: Checking skaffold profile...
[Cloud Code]: Checking logged-in status for the user...
[Cloud Code]: Running: skaffold debug -v info --port-forward --auto-build --auto-deploy --auto-sync --rpc-http-port 59440 --filename /private/tmp/remote-debug/skaffold.yaml --wait-for-deletions-max 2m0s --wait-for-connection
starting gRPC server on port 59441
starting gRPC HTTP server on port 59440 (proxying to 59441)
Skaffold &{Version:v2.1.0 ConfigVersion:skaffold/v4beta2 GitVersion: GitCommit:c037d6f51276e178a2c05c1c59665956ff34aa4c BuildDate:2023-01-23T09:58:07Z GoVersion:go1.19.1 Compiler:gc Platform:darwin/amd64 User:}
Loaded Skaffold defaults from "/Users/x/.skaffold/config"
map entry found when executing locate for &{hello-python . <nil> {0xc000abe2c0 <nil> <nil> <nil> <nil> <nil> <nil>} [] {[] []} [] } of type *latest.Artifact and pointer: 824650027904
Using kubectl context: default
no kpt renderer or deployer found, skipping hydrated-dir creation
build concurrency first set to 1 parsed from *local.Builder[0]
final build concurrency value is 1
Generating tags...
 - hello-python -> hello-python:latest
Tags generated in 183.875µs
Checking cache...
 - hello-python: Found Locally
Cache check completed in 193.476483ms
Starting render...
starting render process
Render completed in 3.069324ms
Tags used in deployment:
 - hello-python -> hello-python:d6c2fe1b36789959b2a9bff4706b37ea1140b3b10f3a6222d9ddbbed8b6d00a7
Starting deploy...
Configuring "" for python debugging
"hello-python" requires debugging support image "python"
Configuring installation of debugging support files
 - deployment.apps/hello-python created
 - service/hello-python created
Waiting for deployments to stabilize...
 - pod/hello-python-6cc7c47c5f-rztwx: waiting for init container install-python-debug-support to complete
 - deployment/hello-python: waiting for init container install-python-debug-support to complete
    - pod/hello-python-6cc7c47c5f-rztwx: waiting for init container install-python-debug-support to complete
      > [hello-python-6cc7c47c5f-rztwx install-python-debug-support] Installing runtime debugging support files in /dbg
 - pod/hello-python-6cc7c47c5f-rztwx: running.
 - deployment/hello-python is ready.
Deployments stabilized in 7.813 seconds
Deploy completed in 9.183 seconds
Port forwarding service/hello-python in namespace default, remote port 8082 -> http://127.0.0.1:8082
Listing files to watch...
 - hello-python
List generated in 633.104µs
Press Ctrl+C to exit
Streaming logs from pod: hello-python-6cc7c47c5f-rztwx container: hello-python
Streaming logs from pod: hello-python-6cc7c47c5f-rztwx container: install-python-debug-support
Watching for changes...
[install-python-debug-support]Installing runtime debugging support files in /dbg
[install-python-debug-support]Installation complete
[install-python-debug-support]Installing runtime debugging support files in /dbg
[install-python-debug-support]Installation complete
[hello-python] * Serving Flask app 'run'
[hello-python] * Debug mode: off
[hello-python]WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
[hello-python] * Running on all addresses (0.0.0.0)
[hello-python] * Running on http://127.0.0.1:8082
[hello-python] * Running on http://10.42.0.110:8082
[hello-python]Press CTRL+C to quit
[hello-python] * Serving Flask app 'run'
[hello-python] * Debug mode: off
[hello-python]WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
[hello-python] * Running on all addresses (0.0.0.0)
[hello-python] * Running on http://127.0.0.1:8082
[hello-python] * Running on http://10.42.0.110:8082
[hello-python]Press CTRL+C to quit
Port forwarding pod/hello-python-6cc7c47c5f-rztwx in namespace default, remote port 5678 -> http://127.0.0.1:5678
[hello-python]10.42.0.1 - - [21/Feb/2023 18:18:29] "GET /python HTTP/1.1" 200 -
[hello-python]10.42.0.1 - - [21/Feb/2023 18:18:29] "GET /python HTTP/1.1" 200 -