Last active
August 11, 2020 02:00
-
-
Save oscar60310/06829bc36cead82339851016a2a6ccce to your computer and use it in GitHub Desktop.
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
const k8s = require("@kubernetes/client-node"); | |
async function run() { | |
const kc = new k8s.KubeConfig(); | |
kc.loadFromDefault(); | |
const appsApi = kc.makeApiClient(k8s.AppsV1Api); | |
const watch = new k8s.Watch(kc); | |
const deploymentCache = new k8s.ListWatch( | |
`/apis/apps/v1/namespaces/default/deployments`, | |
watch, | |
() => { | |
console.log("ls"); | |
return appsApi.listNamespacedDeployment( | |
"default", | |
undefined, | |
undefined, | |
undefined, | |
undefined, | |
undefined, | |
undefined, | |
undefined, | |
10 | |
); | |
}, | |
false | |
); | |
deploymentCache.on("error", (e) => { | |
if (e.metadata.name === "sql-engine-coordinator") { | |
console.log("error", e.spec.replicas); | |
} | |
}); | |
deploymentCache.on("delete", (e) => { | |
if (e.metadata.name === "sql-engine-coordinator") { | |
console.log("delete", e.spec.replicas); | |
} | |
}); | |
deploymentCache.on("add", (e) => { | |
if (e.metadata.name === "sql-engine-coordinator") { | |
console.log("add", e.spec.replicas); | |
} | |
}); | |
deploymentCache.on("update", (e) => { | |
if (e.metadata.name === "sql-engine-coordinator") { | |
console.log("update", e.spec.replicas); | |
} | |
}); | |
deploymentCache.start(); | |
return true; | |
} | |
run().then(console.log).catch(console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment