K8s Resource Watch自行断开连接

时间:2019-02-13 03:42:41

标签: node.js kubernetes watch disconnection

我正在使用nodejs在某些资源上运行k8s手表。它会工作一分钟,然后自行断开连接。使用以下内容:

const ndjson = require('ndjson')
const request = require('request');
var options =  {
      "method": "GET",
      "uri": "https://xxxx/apis/xxxx/v1/xxx",
      "headers": {
        "Authorization": "Bearer xxxxxx"
      },
      "json": true,
      "qs": {
        "watch": true
      }
}
var stream = request(options);
stream
    .pipe(ndjson.parse())
    .on('data', (data) => {
        this._handleChange(data.type, data.object);
    })
    .on('finish', () => {
        this._logger.info('STREAM ::finish...');
    })
    .on('end', () => {
        this._logger.info('STREAM ::end...');
    })
    .on('error', () => {
        this._logger.error('STREAM ::error...');
    })

因此,大约1-2分钟后,我收到“完成”和“结束”事件,并且连接关闭。

如何防止这种情况发生?我需要无限期地关注资源变化。在GCP中运行K8s 1.11.6。

谢谢。

0 个答案:

没有答案
相关问题