Skip to content

Commit

Permalink
feat: ENABLE_CLUSTER_LIST
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Nov 6, 2023
1 parent 7081ba7 commit 541c4bc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require("dotenv").config();
const RANCHER_SERVER = process.env.RANCHER_SERVER;
const RANCHER_TOKEN = process.env.RANCHER_TOKEN;
const API_TOKEN = process.env.API_TOKEN;
const ENABLE_CLUSTER_LIST = process.env.ENABLE_CLUSTER_LIST;

if(!RANCHER_SERVER){
throw new Error(`missing required env var RANCHER_SERVER`);
Expand All @@ -16,6 +17,10 @@ if (!API_TOKEN) {
throw new Error(`missing required env var API_TOKEN`);
}

const enableClusterList = ENABLE_CLUSTER_LIST
? JSON.parse(ENABLE_CLUSTER_LIST)
: null;

const clusterCache = {};
const getClusterName = async (clusterId) => {
if (clusterCache[clusterId]) {
Expand Down Expand Up @@ -44,8 +49,11 @@ const listProjectsByClusters = async () => {
continue
}
const clusterName = await getClusterName(project.clusterId);
if (!clusters[clusterName]){
clusters[clusterName] = []
if (enableClusterList && !enableClusterList.includes(clusterName)) {
continue
}
if (!clusters[clusterName]) {
clusters[clusterName] = [];
}
clusters[clusterName].push({
projectName: project.name,
Expand Down

0 comments on commit 541c4bc

Please # to comment.