Arnavion / k8s-openapi

Rust definitions of the resource types in the Kubernetes client API
Apache License 2.0
379 stars 41 forks source link

Exec command args #96

Closed jvenant closed 3 years ago

jvenant commented 3 years ago

Hi,

I'm trying to use the exec api using connect_get_namespaced_pod_exec of v1_20 to generate the http request, it works perfectly with a single command like ls through kube connect function. But I didn't find a way to pass commands with arguments like ls -la for example

The command variable definition doesn't seem to be compatible with the comment description :

pub struct ConnectGetNamespacedPodExecOptional<'a> {
    /// Command is the remote command to execute. argv array. Not executed within a shell.
    pub command: Option<&'a str>,
    ...

From my understanding, command should be an array of str.

Arnavion commented 3 years ago

The OpenAPI spec says it's a single string.

    "/api/v1/namespaces/{namespace}/pods/{name}/exec": {
      "get": {
        "consumes": [
          "*/*"
        ],
        "description": "connect GET requests to exec of Pod",
        "operationId": "connectCoreV1GetNamespacedPodExec",
[...]
      },
      "parameters": [
        {
          "description": "Command is the remote command to execute. argv array. Not executed within a shell.",
          "in": "query",
          "name": "command",
          "type": "string",
          "uniqueItems": true
        },

The golang type says it's a string slice.

Now, the JSON tag on the golang type doesn't matter because this type is serialized through the querystring, not as JSON body. So the OpenAPI spec is at least correct that the parameter location is query.

But as for whether it's a string or a string array, I haven't found the code that actually parses a PodExecOptions from the query string. If it does want a string array, I would need to look at the code to figure out how exactly does it want that when the serialization format is a query string - command=ls&command=-la ? URL-encoded JSON array? Something else?

MikailBag commented 3 years ago

FYI this is how kube does exec:

for c in command.into_iter() {
     qp.append_pair("command", &c.into());
}

It seems like kube specifies command parameter multiple times, once per each argument.

Arnavion commented 3 years ago

Thanks for confirming. So we'll need a fixup to change the parameter from Type::String to Type::Array { Type::String }, plus add support for that in write_operation

jvenant commented 3 years ago

Thank you very much !