Skip to content

Commit

Permalink
feat(log): node-client support for streaming logs (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
Silas Boyd-Wickizer committed May 31, 2019
1 parent 238fbb6 commit 8be6b5a
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions backends/kubernetes-client-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const pascalcase = require('pascalcase')
const { Readable } = require('stream')
const { PassThrough, Readable } = require('stream')

//
// https://github.com/kubernetes-client/javascript
Expand All @@ -24,8 +24,33 @@ class ClientNodeBackend {
return this.apiClients[apiType]
}

async getLogByteStream (options) {
throw new Error('getLogByteStream is not implemented')
getLogByteStream (options) {
const log = new this.client.Log(this.kubeconfig)
const qs = options.qs || options.parameters || {}
const containerName = qs.container
const stream = new PassThrough()

//
// node-client pipes to the log stream iff the apiserver returns 200. Assume
// that if the stream is readable, then node-client has attached the pipe
// and the call was successful.
//
// Otherwise, node-client calls the callback with an err.
//
// node-client also calls the callback when the connection terminates. We
// ignore that.
//
return new Promise((resolve, reject) => {
stream.once('readable', () => {
resolve(stream)
})
log.log(options.pathnameParameters.namespace,
options.pathnameParameters.name,
containerName,
stream,
err => { if (err) return reject(err) },
qs)
})
}

async getWatchObjectStream (options) {
Expand Down

0 comments on commit 8be6b5a

Please sign in to comment.