Show better message for empty contexts

This commit is contained in:
Andrei Pohilko
2022-11-08 10:10:19 +00:00
parent 96a7a429e1
commit 2454fcf47c

View File

@@ -129,22 +129,28 @@ function statusStyle(status, card, txt) {
} }
} }
function getCleanClusterName(rawClusterName){ function getCleanClusterName(rawClusterName) {
if (rawClusterName.indexOf('arn') === 0) { if (rawClusterName.indexOf('arn') === 0) {
// AWS cluster // AWS cluster
const clusterSplit = rawClusterName.split(':') const clusterSplit = rawClusterName.split(':')
const clusterName = clusterSplit.slice(-1)[0].replace('cluster/','') const clusterName = clusterSplit.slice(-1)[0].replace('cluster/', '')
const region = clusterSplit.at(-3) const region = clusterSplit.at(-3)
return region + "/" + clusterName + ' [AWS]' return region + "/" + clusterName + ' [AWS]'
} }
if (rawClusterName.indexOf('gke') === 0) { if (rawClusterName.indexOf('gke') === 0) {
// GKE cluster // GKE cluster
return rawClusterName.split('_').at(-2) + '/' + rawClusterName.split('_').at(-1) + ' [GKE]' return rawClusterName.split('_').at(-2) + '/' + rawClusterName.split('_').at(-1) + ' [GKE]'
} }
return rawClusterName return rawClusterName
} }
function fillClusterList(data, context) { function fillClusterList(data, context) {
if (!data || !data.length) {
$("#cluster").append("No clusters listed in kubectl config, please configure some")
return
}
data.forEach(function (elm) { data.forEach(function (elm) {
let label = getCleanClusterName(elm.Name) let label = getCleanClusterName(elm.Name)
let opt = $('<li><label><input type="radio" name="cluster" class="me-2"/><span></span></label></li>'); let opt = $('<li><label><input type="radio" name="cluster" class="me-2"/><span></span></label></li>');