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

unexpected kubel--get-containers output on windows due to single quote (') usage for jsonpath #83

Open
nabero opened this issue Apr 15, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@nabero
Copy link

nabero commented Apr 15, 2022

Hello,

Getting logs from a single container pod fails under windows. It seems that the container name is single quoted in the cmd string.

Here's the output from kubel-process buffer:
command: kubectl --context mycontext logs --tail=100 pod-name-0 'container-name'

Unfortunately single quote doesn't seem to be valid in cmd.exe. The same command with double or without quotes works.

From my understanding, kubel--get-containers output is single quoted because single quote usage in jsonpath

C:\Users\user>kubectl get pods -n cvaas pod-name-0 -o jsonpath="{.spec.%s[*].name}"

C:\Users\user>kubectl get pods -n cvaas pod-name-0 -o jsonpath='{.spec.%s[*].name}'
''

Note sure why the command has the single container name inside the quotes (my elisp reading skills are...), but I could confirm replacing the single quotes from jsonpath by escaped double quotes fixes the issue.

Can't guarantee I'll be able to submit a PR with fully tested code before next week.
But here's the patch in the meantime : kubel-windows-support.txt, only tested the kubectl log part though.

Tested with :
kubectl version : 1.23
kubel version (latest master): b598b21
Windows 10.x

@abrochard
Copy link
Owner

Hi! Thank you for reporting this!
Unfortunately I do not use a windows machine so I cannot reproduce or confirm that your patch fix it, but I can test that it won't break for Linux/Mac.
No rush at all for a PR, I'm pretty swamped myself, but I thank you in any case.

@abrochard abrochard added the bug Something isn't working label Apr 18, 2022
@Suzamax
Copy link

Suzamax commented Jul 25, 2022

You can use the Linux (WSL2) kubectl :-)

Just use these files:

kubectl.bat

@echo off

@rem Just run the PowerShell script.

powershell -NoProfile -ExecutionPolicy Bypass -F "C:\Users\carlos.canellas\bin\kubectl.ps1" %*

kubectl.ps1

wsl -d Ubuntu-22.04 --exec bash -c "/home/carlos/kubectl.sh $args"

kubectl.sh

IMPORTANT: it must be edited on Linux due to CRLF/LF issues...

#!/usr/bin/env bash

export PATH=/home/carlos/google-cloud-sdk/bin:$PATH

kubectl $@

Replace the paths according to your current setup :-)

@jreicher
Copy link
Contributor

jreicher commented Aug 9, 2022

I can confirm this issue, and it's a problem with all the jsonpath queries (namespaces, resources, etc.). The single quotes end up at the ends of the lists literally, and so once the list is split one item has a single quote before, and one item has a single quote after. In the case of a singleton list (viewing log of a pod with one container) the item is entirely quoted.

However I fixed this by removing the single quotes altogether. I'm not sure they are needed on Mac/Linux either?

@abrochard
Copy link
Owner

Hi @jreicher ,

However I fixed this by removing the single quotes altogether. I'm not sure they are needed on Mac/Linux either?

What is your command extactly? kubectl get pods [pod] -o jsonpath={.spec.%s[*].name} with no single quote around the jsonpath arg?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants