-
Notifications
You must be signed in to change notification settings - Fork 0
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
connectPostPodExec
is not implemented
#2
Comments
The open API json for the command parameter for this function: {
"uniqueItems": true,
"type": "string",
"description": "Command is the remote command to execute. argv array. Not executed within a shell.",
"name": "command",
"in": "query"
} It does say "argv array" but I'm not sure how you should know its an array rather than an individual string in this case just from that definition. Here is the corresponding code in the nodejs Kube client: |
Ok, so if I'm understanding the desync correctly, I'm only accepting a single string and it needs to also be valid to pass an array of strings. Based on that JSON snippet it seems the only signal that an array is acceptable would be that So, this might be best as some sort of special-casing, the pod-specific streaming APIs tend to not fit well into the cookie cutter openAPI specs. Just so I know, can you confirm if you've noticed other issues with this API function beyond the string array issue? I can put together my own repros but it'll take a little more time. You can also use the Thanks for the report! I haven't done much with the raw exec API yet. 😄 |
I tried hacking on it by extending some classes and getting my own version of the function to call the api but it still did not work so I need to do a little more work to prove absolutely the right fix. But I'm looking at it and will report back. |
You know what, I think this is why its not working: I think that this particular API needs to be upgraded to a websocket to handle the stdin/out/err streams, etc. This is a good clue I should have an example tomorrow. |
Ok, if it's one of the things that need websockets then this is actually a sizable piece of work I think, because That module also tries polyfilling the http requests on developer machines by shelling out to I'm busy with real life things the next couple days, so feel free to try some things out! In any case I should be able to tackle exposing websockets etc sometime this weekend
To be clear, what I was referring to is that the |
Yeah I have a working way to patch it so I can adjust just the one function, I haven't gotten it to work yet but here is an example for future users who think they may need to patch a single function too: import { CoreV1Api, CoreV1NamespacedApi, RestClient } from "../deps.ts";
// We need to patch the pod/exec function to pass multiple commands
// todo: Remove these classes once issue cloudydeno/deno-kubernetes_apis#2 is fixed
// https://github.com/cloudydeno/deno-kubernetes_apis/issues/2
export class PatchedCoreV1Api extends CoreV1Api {
#client: RestClient
constructor(client: RestClient) {
super(client)
this.#client = client;
}
patchedNamespace(name: string) {
return new PatchedCoreV1NamespacedApi(this.#client, name);
}
}
export class PatchedCoreV1NamespacedApi extends CoreV1NamespacedApi {
#client: RestClient
#root: string
constructor(client: RestClient, namespace: string) {
super(client, namespace)
this.#client = client;
this.#root = `/api/v1/namespaces/${namespace}/`;
}
public async patchedConnectPostPodExec(name: string, opts: {
command?: string[]; // this is different
container?: string;
stderr?: boolean;
stdin?: boolean;
stdout?: boolean;
tty?: boolean;
abortSignal?: AbortSignal;
} = {}) {
const query = new URLSearchParams;
if (opts["command"] != null) opts["command"].forEach(command => query.append("command", command)); // this is different
if (opts["container"] != null) query.append("container", opts["container"]);
if (opts["stderr"] != null) query.append("stderr", opts["stderr"] ? '1' : '0');
if (opts["stdin"] != null) query.append("stdin", opts["stdin"] ? '1' : '0');
if (opts["stdout"] != null) query.append("stdout", opts["stdout"] ? '1' : '0');
if (opts["tty"] != null) query.append("tty", opts["tty"] ? '1' : '0');
const _resp = await this.#client.performRequest({
method: "POST",
path: `${this.#root}pods/${name}/exec`,
expectJson: true,
querystring: query,
abortSignal: opts.abortSignal,
});
}
} |
Hey, I've started a WIP here for pod/exec and pod/portforward: https://github.com/cloudydeno/deno-kubernetes_client/pull/6/files This currently only works with I'm also still undecided on the API of this, because my initial thought was to split out stdout and stderr but when I was actually using the API I kept wanting to receive one stream with both types of packets preserving order. I think that Also, Deno WS has a bug where you won't receive the final output after closing stdin, so that's probably relevant if you'll be doing stdin stuff. There's an open PR to fix it. Anyway; if you're still looking for this functionality in Deno then feel free to look at my WIP and see if it can function in your usecase. |
Awesome, I can't think of a reason why you'd want to have two seperate outputs, of course you'd need to be able to differentiate between them but having one for loop would be better probably. Ultimately I had to switch to node to solve my immediate issue but I keep coming up with these little ideas for apps which use the kubernetes api from within a pod, so I will probably try it again soon. Also, I have a PR here for an unrelated topic, that I'd love to get some more eyes on it if you have a minute: It doesn't quite help the websocket cert issue but its in a related code area, modifying the |
When i try to use this function, i get a Also when will there a be fix directly landing here? its over two years :D |
Yea, that's understandable, because of the On developer setups, But The blocker is that
Well, as far as this issue, the 'today' fix would be removing Some things to try if you want to DIY:
|
Amazing answer, I would have never figured all that out on my own. |
Yea, honestly as a client implementor, the tunnel commands have taken more of my energy than the rest of the Kubernetes API :) I want to finally close this feature out, so here's my plan:
I'll report back after step 4. |
If you tag me on PR's I'll do my best to review. |
I tagged I haven't done anything on Feel free to try the approach out now and see if websockets works in your setup. (Customize the namespace, container name, etc) The biggest weakness for Deno WebSockets is lack of TLS certificate setup (cluster CA, client-cert auth) which means that you must use token auth and you must trust the server CA with Deno's CLI flags if it is self-signed. |
connectPostPodExec
doesn't work, has possibly incorrect command arg typeconnectPostPodExec
is not implemented
hi again, I have a draft at #6 which fixes up const exec = await coreApi.tunnelPodExec('my-pod', {
command: ['uname', '-a'],
stdout: true,
});
const output = await exec.output();
return new TextDecoder().decode(output.stdout).trimEnd(); I also added an emulation to the Any validation of the utility class is appreciated. I've been focused on a limited set of usecases so maybe haven't accounted for particular others. but in general I'll merge+tag this likely next weekend. |
This is tagged at When using import { tunnelBeta, makeClientProviderChain } from 'https://deno.land/x/[email protected]/client.ts';
// Set up a Kubernetes API client which can use WebSockets:
const client = await makeClientProviderChain(tunnelBeta.WebsocketRestClient).getClient(); For in-cluster you'll also want to set Anyway then you can use execs or port-fowards. There are several small examples here: https://github.com/cloudydeno/deno-kubernetes_apis/tree/main/lib/examples Hopefully these new APIs serve people well, I welcome suggestions or bug reports |
Here is my code:
Using the official nodejs client this works... except there their API for the command argument is
command: string[]
.This is the generated code for this function:
According to this blog:
https://www.openshift.com/blog/executing-commands-in-pods-using-k8s-api
To send the command
sh -c "kill -s TERM 1"
you need to be able to send multiple command parameters so:Which then would then append each command into a query string such as:
That means the generated code maybe should look like this:
The text was updated successfully, but these errors were encountered: