Skip to content

Add a client for the pod read-log endpoint #82

Closed

Description

@dbolkensteyn

Command-line: kubectl log <pod-name>
Documentation: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#read-log-pod-v1-core

From what I read so far on kubernetes/kubernetes#13885, the /log endpoints only expects binary.k8s.io as protocol. Without it (but still sending the *.channel.k8s.io ones), a 403 Forbidden status code is returned.

I'll try to submit a PR for this in the upcoming days, suggestions are welcome.

Right now I'm trying to fit this into WebSocketHandler, but there is already a binary handler that expects the first byte of the message to be the channel number, which is not the case for the /log endpoint. See https://github.com/kubernetes-client/javascript/blob/master/node-client/src/web-socket-handler.ts#L89-L94

Activity

  1. changed the title [-]Add a client for the pod read-log `/log` endpoint[/-] [+]Add a client for the pod read-log endpoint[/+] on Aug 15, 2018
  2. added a commit that references this issue on Aug 15, 2018
    78281b8
  3. dbolkensteyn commented on Aug 15, 2018

    @dbolkensteyn
    ContributorAuthor

    PR opened, let's discuss there

  4. added a commit that references this issue on Aug 15, 2018
    38d0e7e
  5. added 5 commits that reference this issue on Mar 19, 2019
    428bff4
    a649a15
    b00737d
    a091fb6
    1d18f90
  6. added a commit that references this issue on Mar 27, 2019
    4a5b84d
  7. chadbr commented on Nov 5, 2019

    @chadbr

    @dbolkensteyn Hey Dinesh -- Can you point me to an example of how to use the Log.log(..) method? I have not been able to figure out how to get something out the of the stream: Writable parameter.

    Thanks, Chad

  8. dbolkensteyn commented on Nov 5, 2019

    @dbolkensteyn
    ContributorAuthor

    It's been a while but try something along these lines @chadbr:

    const myStream = new stream.Writable({
        write(chunk, encoding, callback) {
          console.log(chunk.toString().trimRight())
          // or do something else more useful to you
          callback()
        }
      })
    

    and then pass myStream as the argument.

  9. chadbr commented on Nov 5, 2019

    @chadbr

    Thanks @dbolkensteyn -- I'm failing to grasp why we would pass a writable stream instead of getting a readable stream from the log function? I'm assuming the function is there to read log streams?

    Sorry for the dumb question...

    For example, when I call spawn - I get an object back with the process streams:

        // return this object when stdio option is undefined or not specified
        interface ChildProcessWithoutNullStreams extends ChildProcess {
            stdin: Writable;
            stdout: Readable;
            stderr: Readable;

    I would have assumed the log function would return something like `stdout: Readable;'? What am I missing?

  10. chadbr commented on Nov 5, 2019

    @chadbr

    As a side note -- I think I might have found a small bug?

    applyToRequest is async / returns a promise, and it's not awaited / resolved? I'm not sure if it matters...

            this.config.applyToRequest(requestOptions);

    javascript/src/log.ts

    Lines 78 to 79 in 9d5757e

    this.config.applyToRequest(requestOptions);

    Sorry for the noise...

  11. dbolkensteyn commented on Nov 6, 2019

    @dbolkensteyn
    ContributorAuthor

    I don't have a good answer to either of your points as my knowledge of TypeScript is limited. Feel free to further investigate and open new issues (and/or PRs).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions