Skip to content

Commit

Permalink
dirty update fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdi BEN ABDALLAH committed Jan 10, 2018
1 parent 1e58da4 commit aec811f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const identifier = (configmap) => [configmap.metadata.namespace, configmap.metadata.name].join("/");
const dashboardManifest = (configmap) => JSON.parse(configmap.data.json);
const key = (configmap) => [configmap.metadata.namespace, configmap.metadata.name].join("/");
const unwrapDashboard = (configmap) => JSON.parse(configmap.data.json);

class Controller {
constructor(configMapsWatcher, grafana) {
Expand All @@ -18,35 +18,35 @@ class Controller {

handleConfigMapCreated(configmap) {
this.grafana
.createDashboard(dashboardManifest(configmap))
.createDashboard(unwrapDashboard(configmap))
.then((result) => {
console.log("created dashboard for configmap", identifier(configmap), result);
console.log("created dashboard for configmap", key(configmap), result);
})
.catch((error) => {
console.error("unable to create dashboard for configmap", identifier(configmap), error);
console.error("unable to create dashboard for configmap", key(configmap), error);
});
}

handleConfigMapModified(configmap) {
this.grafana
.updateDashboard(dashboardManifest(configmap))
.updateDashboard(unwrapDashboard(configmap))
.then((result) => {
console.log("updated dashboard for configmap", identifier(configmap), result);
console.log("updated dashboard for configmap", key(configmap), result);
})
.catch((error) => {
console.error("unable to update dashboard for configmap", identifier(configmap), error);
console.error("unable to update dashboard for configmap", key(configmap), error);
});
}

handleConfigMapDeleted(configmap) {
this.grafana
.slug(dashboardManifest(configmap))
.slug(unwrapDashboard(configmap))
.then(this.grafana.deleteDashboard.bind(this.grafana))
.then(() => {
console.log("the dashboard managed by configmap", identifier(configmap), "has been deleted");
console.log("the dashboard managed by configmap", key(configmap), "has been deleted");
})
.catch((error) => {
console.error("unable to delete dashboard for configmap", identifier(configmap), error);
console.error("unable to delete dashboard for configmap", key(configmap), error);
});
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/grafana.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class Grafana {
.then(unwrapResponse);
}

updateDashboard({ dashboard }) {
return this.client
.post("dashboards/db", { dashboard })
updateDashboard(data) {
return this.slug(data)
.then(this.deleteDashboard.bind(this))
.then(() => this.createDashboard(data))
.then(unwrapResponse);
}

Expand Down

0 comments on commit aec811f

Please sign in to comment.