Skip to content

Instantly share code, notes, and snippets.

@harsh4870
Created October 29, 2022 07:31
Show Gist options
  • Save harsh4870/74df90e58e7dc6fcc6a5951562c5ffb1 to your computer and use it in GitHub Desktop.
Save harsh4870/74df90e58e7dc6fcc6a5951562c5ffb1 to your computer and use it in GitHub Desktop.
/* PubSub function get data from PubSub and resize the GKE cluster pools based on data */
const Buffer = require("safe-buffer").Buffer;
const container = require("@google-cloud/container");
const client = new container.v1.ClusterManagerClient();
exports.helloPubSub = async (message, context) => {
const payload = JSON.parse(Buffer.from(message.data, "base64").toString());
const request = {
projectId: payload.projectId,
zone: payload.zone,
clusterId: payload.cluster_id,
nodePoolId: payload.node_pool_id,
nodeCount: payload.node_count,
};
const result = await client.setNodePoolSize(request);
const operation = result[0];
console.log(operation);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment