Azure / Bridge-To-Kubernetes

Bridge To Kubernetes (B2K) is development tool to debug microservices, pods which redirects traffic to your local development machine and vice versa.
https://learn.microsoft.com/en-us/visualstudio/bridge/overview-bridge-to-kubernetes
Other
209 stars 57 forks source link

VS Code bridge-to-kubernetes task fails to connect with error "Patch Statefulset" #235

Closed r-delgadillo closed 1 year ago

r-delgadillo commented 1 year ago

Describe the bug I'm attempting to set up Bridge-to-kubernetes (B2K) by using VS Code w/ Bridge To Kubernetes extension. I've successfully configured B2K by running (Bridge to Kubernetes: Configer) but I'm not able to redirect the traffic from my Minikube K8 cluster to my local environment when launching the VS code task.

I'm connected to VS Code by using remote ssh.

Below is the example Task.json configuration:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "bridge-to-kubernetes.resource",
            "type": "bridge-to-kubernetes.resource",
            "resource": "refdata-store",
            "resourceType": "service",
            "ports": [
                8081
            ],
            "targetCluster": "minikube",
            "targetNamespace": "default",
            "useKubernetesServiceEnvironmentVariables": true
        }
    ]
}

To Reproduce Steps to reproduce the behavior:

  1. Launch VS Code using remote ssh
  2. Start Minikube
  3. Deploy Helm chart that contains the application
  4. Configure & Launch B2K VS code task

Expected behavior The development computer is connected when the VS Code Status bar turns orange and the Kubernetes extension shows you are connected.

Screenshots VS Code Error:

Error: Failed to establish a connection. Error: Patch StatefulSet 'default/bluefin-refdata-store' failed. Patch is {"Operations":[{"value":"IfNotPresent","path":"/spec/template/spec/containers/0/imagePullPolicy","op":"replace","from":null},{"value":"bridgetokubernetes.azurecr.io/lpkremoteagent:1.1.0","path":"/spec/template/spec/containers/0/image","op":"replace","from":null},{"value":[{"name":"E4K_URL","value":"mqtt://azedge-dmqtt-frontend.default.svc.cluster.local:1883","valueFrom":null},{"name":"POD_NAME","value":null,"valueFrom":{"configMapKeyRef":null,"fieldRef":{"apiVersion":"v1","fieldPath":"metadata.name"},"resourceFieldRef":null,"secretKeyRef":null}},{"name":"BRIDGE_COLLECT_TELEMETRY","value":"True","valueFrom":null},{"name":"CONSOLE_VERBOSITY","value":"Verbose","valueFrom":null},{"name":"BRIDGE_CORRELATION_ID","value":"16b704b9-68cc-44f3-b0a6-e167b27494711680712097777:6983d98c28ee:3680dd322ec8","valueFrom":null}],"path":"/spec/template/spec/containers/0/env","op":"replace","from":null}]}: **Bad Request: error decoding patch: json: cannot unmarshal object into Go value of type []handlers.jsonPatchO**

image

image

Desktop (please complete the following information): Remote machine: linux ubuntu amd64 cpu: Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz

hsubramanianaks commented 1 year ago

@r-delgadillo Thanks for raising this issue. we will triage and let you know for any further details.

r-delgadillo commented 1 year ago

@hsubramanianaks I switched my application to use a Deployment K8 object and it was able to redirect traffic correctly.

Eneuman commented 1 year ago

@hsubramanianaks This might have something to do with the code handling patching of Statefulset.

This line: https://github.com/Azure/Bridge-To-Kubernetes/blob/92d8d3fa7de1853df59f53f0e5f9932375d3a3e5/src/library/Connect/KubernetesRemoteEnvironmentManager.cs#L836

The V1Patch constructor is set with a object of type JsonPatchDocument<V1StatefulSet> but when we patching Deployments, we are using a string today: https://github.com/Azure/Bridge-To-Kubernetes/blob/92d8d3fa7de1853df59f53f0e5f9932375d3a3e5/src/library/Connect/KubernetesRemoteEnvironmentManager.cs#L739

More info here: https://github.com/kubernetes-client/csharp/issues/772 Serializing the object to json first might solve this issue.

hsubramanianaks commented 1 year ago

@Eneuman exactly I was looking at the same place and cause, thanks for the info. I will keep looking into.

r-delgadillo commented 1 year ago

@hsubramanianaks provided a .vsix file with the fix. I was able to verify on my local computer that it's not working with the .vsix file installed. We'll use this .vsix file until the official fix is released. Thank you!

hsubramanianaks commented 1 year ago

@r-delgadillo you said it is not working but it is working, correct? just a typo on the statement. Also, I have replied on the volume mounts questions you had. Thank you for raising this issue. we will move forward with this fix.

r-delgadillo commented 1 year ago

@hsubramanianaks Yes you're correct, it was a typo. The fix with the .vsix file IS working. Thank you

hsubramanianaks commented 1 year ago

@r-delgadillo this is released with version 1.0.20230418.1, closing the issue. Please feel free to reopen if it happens again. Thanks.