-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #82 Add a client for the pod read-log endpoint
- Loading branch information
1 parent
a6d42ca
commit 78281b8
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import querystring = require('querystring'); | ||
import stream = require('stream'); | ||
|
||
import { KubeConfig } from './config'; | ||
import { WebSocketHandler } from './web-socket-handler'; | ||
|
||
export class Log { | ||
public 'handler': WebSocketHandler; | ||
|
||
public constructor(config: KubeConfig) { | ||
this.handler = new WebSocketHandler(config); | ||
} | ||
|
||
// TODO add support for limitBytes, previous, sinceSeconds and tailLines | ||
public log(namespace: string, podName: string, containerName: string, | ||
follow: boolean, | ||
timestamps: boolean, | ||
stream: stream.Writable): Promise<void> { | ||
const query = { | ||
container: containerName, | ||
follow: follow, | ||
timestamps: timestamps, | ||
}; | ||
const queryStr = querystring.stringify(query); | ||
const path = `/api/v1/namespaces/${namespace}/pods/${podName}/log?${queryStr}`; | ||
const promise = this.handler.connect(path, null, (streamNum: number, buff: Buffer) => { | ||
const charBuff = Buffer.allocUnsafe(1) | ||
charBuff.writeInt8(streamNum, 0) | ||
stream.write(Buffer.concat([charBuff, buff])); | ||
}); | ||
const result = new Promise<void>((resolvePromise, reject) => { | ||
promise.then(() => resolvePromise(), (err) => reject(err)); | ||
}); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters