Make k8s context a URL param

This commit is contained in:
Andrei Pohilko
2022-09-28 15:00:10 +01:00
parent c1732c86a5
commit 870a1196f0
3 changed files with 16 additions and 13 deletions

View File

@@ -1,14 +1,14 @@
$(function () {
const clusterSelect = $("#cluster");
clusterSelect.change(function () {
Cookies.set("context", clusterSelect.find("input:radio:checked").val())
window.location.href = "/"
window.location.href = "/#context=" + clusterSelect.find("input:radio:checked").val()
window.location.reload()
})
$.getJSON("/api/kube/contexts").fail(function (xhr) {
reportError("Failed to get list of clusters", xhr)
}).done(function (data) {
const context = Cookies.get("context")
const context = getHashParam("context")
fillClusterList(data, context);
const namespace = getHashParam("namespace")
@@ -31,7 +31,6 @@ function reportError(err, xhr) {
}
function getHashParam(name) {
const params = new URLSearchParams(window.location.hash.substring(1))
return params.get(name)
@@ -75,18 +74,24 @@ function fillClusterList(data, context) {
opt.find("span").text(label)
if (elm.IsCurrent && !context) {
opt.find("input").prop("checked", true)
setCurrentContext(elm.Name)
} else if (context && elm.Name === context) {
opt.find("input").prop("checked", true)
$.ajaxSetup({
headers: {
'x-kubecontext': context
}
});
setCurrentContext(elm.Name)
}
$("#cluster").append(opt)
})
}
function setCurrentContext(ctx) {
setHashParam("context", ctx)
$.ajaxSetup({
headers: {
'x-kubecontext': context
}
});
}
function getAge(obj1, obj2) {
const date = luxon.DateTime.fromISO(obj1.updated);
let dateNext = luxon.DateTime.now()