Skip to content

Commit ed4c1b5

Browse files
authored
feat: use local context (#533)
1 parent 159cbdc commit ed4c1b5

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ For overriding the default mappings when using `lazy.nvim` [check out our wiki p
238238
diff = {
239239
bin = "kubediff" -- or any other binary
240240
},
241-
kubectl_cmd = { cmd = "kubectl", env = {}, args = {} },
241+
kubectl_cmd = { cmd = "kubectl", env = {}, args = {}, persist_context_change = false },
242242
namespace = "All",
243243
namespace_fallback = {}, -- If you have limited access you can list all the namespaces here
244244
hints = true,

lua/kubectl/actions/commands.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ function M.configure_command(cmd, envs, args)
1818
end
1919
vim.list_extend(result.args, vim.iter(options_args):map(mixer):totable())
2020
vim.list_extend(result.env, vim.iter(options_env):map(mixer):totable())
21+
22+
local state = require("kubectl.state")
23+
if state.context["current-context"] then
24+
table.insert(result.args, "--context")
25+
table.insert(result.args, state.context["current-context"])
26+
vim.print(result.args)
27+
end
2128
end
2229

2330
table.insert(result.env, "PATH=" .. current_env["PATH"])

lua/kubectl/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ local defaults = {
2828
-- The subshells invoked will have PATH, HOME and the environments listed below
2929
-- NOTE: Some executions using the io.open and vim.fn.terminal will still have default shell environments,
3030
-- in that case, the environments below will not override the defaults and should not be in your .zshrc/.bashrc files
31-
kubectl_cmd = { cmd = "kubectl", env = {}, args = {} },
31+
kubectl_cmd = { cmd = "kubectl", env = {}, args = {}, persist_context_change = false },
3232
namespace = "All",
3333
namespace_fallback = {},
3434
headers = true,

lua/kubectl/views/contexts/init.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ end
6363
--- @param cmd string
6464
function M.change_context(cmd)
6565
local state = require("kubectl.state")
66-
local results = commands.shell_command("kubectl", { "config", "use-context", cmd })
66+
local config = require("kubectl.config")
67+
if config.kubectl_cmd.persist_context_change then
68+
local results = commands.shell_command("kubectl", { "config", "use-context", cmd })
6769

68-
if not results then
69-
vim.notify(results, vim.log.levels.INFO)
70+
if not results then
71+
vim.notify(results, vim.log.levels.INFO)
72+
end
7073
end
74+
state.context["current-context"] = cmd
7175
state.set_session()
7276
kube.stop_kubectl_proxy()
7377
kube.start_kubectl_proxy(function()

0 commit comments

Comments
 (0)