【发布时间】:2021-09-02 16:04:46
【问题描述】:
我们有以下代码(不要问我为什么......即使作为非 JavaScript 开发人员,它对我来说看起来也不漂亮),在 Kubernetes 升级后会引发错误:
module.exports.getReplicationControllers = async function getReplicationControllers(namespace) {
const kubeConfig = (await getNamespacesByCluster()).get(namespace);
if (!kubeConfig) throw new Error(`No clusters contain the namespace ${namespace}`)
const kubeConfigEscaped = shellEscape([kubeConfig]);
const namespaceEscaped = shellEscape([namespace]);
const result = await cpp(`kubectl --kubeconfig ${kubeConfigEscaped} get replicationcontrollers -o json -n ${namespaceEscaped}`);
console.error(result.stderr);
/** @type {{items: any[]}} */
const resultParsed = JSON.parse(result.stdout);
const serviceNames = resultParsed.items.map((item) => item.metadata.name);
return serviceNames;
}
ChildProcessError: stdout maxBuffer length exceeded kubectl --kubeconfig /kubeconfig-staging get replicationcontrollers -o json -n xxx(以错误代码 ERR_CHILD_PROCESS_STDIO_MAXBUFFER 退出)
到目前为止我尝试过的是:
const result = await cpp(`kubectl --kubeconfig ${kubeConfigEscaped} get replicationcontrollers -o=jsonpath='{.items[*].metadata.name}' -n ${namespaceEscaped}`);
console.error(result.stderr);
const serviceNames = result.split(' ');
return serviceNames;
返回
TypeError: result.split 不是函数
我不是非常精通 JavaScript,感谢任何帮助。
【问题讨论】:
-
有一个official Javascript Kubernetes client;你能用它来代替
kubectl吗? (这可能会更简单、更安全;GitHub 页面上的第一个示例列出了 pod,并且很容易将其调整为列出复制控制器或其他对象类型。)
标签: javascript node.js kubernetes