Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Closed
r-delgadillo opened this issue Apr 5, 2023 · 8 comments

Comments

@r-delgadillo
Copy link

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
Copy link
Collaborator

hsubramanianaks commented Apr 5, 2023

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

@r-delgadillo
Copy link
Author

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

@Eneuman
Copy link
Contributor

Eneuman commented Apr 5, 2023

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

This line:

await _kubernetesClient.PatchV1StatefulSetAsync(namespaceName, statefulSetName, new V1Patch(patch, PatchType.JsonPatch), cancellationToken: cancellationToken);

The V1Patch constructor is set with a object of type JsonPatchDocument<V1StatefulSet>
but when we patching Deployments, we are using a string today:

await _kubernetesClient.PatchV1DeploymentAsync(namespaceName, deploymentName, new V1Patch(JsonHelpers.SerializeObject(patch), PatchType.JsonPatch), cancellationToken: cancellationToken);

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

@hsubramanianaks
Copy link
Collaborator

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

@r-delgadillo
Copy link
Author

@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
Copy link
Collaborator

@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
Copy link
Author

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

@hsubramanianaks
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants