From f284527b2dda84241decf924a15e3d3f2dff87b6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 12:29:40 +0000 Subject: [PATCH 1/3] Initial plan From 785fc3100ed549ff5537bb3c73554f3704f342c3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 12:32:16 +0000 Subject: [PATCH 2/3] Add check to skip kubeconfig update for in-cluster contexts Co-authored-by: basebandit <8973567+basebandit@users.noreply.github.com> --- cluster/manager.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cluster/manager.go b/cluster/manager.go index 3f0a572..1b6ca9a 100644 --- a/cluster/manager.go +++ b/cluster/manager.go @@ -349,8 +349,11 @@ func (cm *Manager) SetCurrentContext(contextName string) error { contextInfo.IsActive = true // Update the kubeconfig file to reflect the context switch - if err := cm.updateKubeconfigCurrentContext(contextName, contextInfo.ConfigPath); err != nil { - return fmt.Errorf("failed to update kubeconfig file: %w", err) + // Skip the update for in-cluster configurations (empty ConfigPath) + if contextInfo.ConfigPath != "" { + if err := cm.updateKubeconfigCurrentContext(contextName, contextInfo.ConfigPath); err != nil { + return fmt.Errorf("failed to update kubeconfig file: %w", err) + } } } From 6915097552d1c5f5737c42c7d584462e270281d8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 12:33:23 +0000 Subject: [PATCH 3/3] Add test for SetCurrentContext with empty ConfigPath Co-authored-by: basebandit <8973567+basebandit@users.noreply.github.com> --- cluster/manager_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cluster/manager_test.go b/cluster/manager_test.go index f98daeb..64eb407 100644 --- a/cluster/manager_test.go +++ b/cluster/manager_test.go @@ -45,6 +45,7 @@ func TestExtendedClusterManager(t *testing.T) { t.Run("ListContexts", testListContexts) t.Run("LoadKubeConfigDuplicateName", testLoadKubeConfigDuplicateName) t.Run("SetCurrentContextUpdatesActiveStatus", testSetCurrentContextUpdatesActiveStatus) + t.Run("SetCurrentContextWithEmptyConfigPath", testSetCurrentContextWithEmptyConfigPath) t.Run("UpdateKubeconfigCurrentContext", testUpdateKubeconfigCurrentContext) } @@ -601,6 +602,41 @@ users: assert.Equal(t, testContext2, config.CurrentContext) } +func testSetCurrentContextWithEmptyConfigPath(t *testing.T) { + cm := New() + + fakeClient1 := fake.NewSimpleClientset() + fakeClient2 := fake.NewSimpleClientset() + + // Create a regular context with a config path + contextInfo1 := &kai.ContextInfo{ + Name: testContext1, + ConfigPath: "/some/path/to/config", + IsActive: true, + } + + // Create an in-cluster context with empty ConfigPath (simulating in-cluster config) + contextInfo2 := &kai.ContextInfo{ + Name: "in-cluster", + ConfigPath: "", // Empty config path for in-cluster + IsActive: false, + } + + cm.clients[testContext1] = fakeClient1 + cm.clients["in-cluster"] = fakeClient2 + cm.contexts[testContext1] = contextInfo1 + cm.contexts["in-cluster"] = contextInfo2 + cm.currentContext = testContext1 + + // Switch to in-cluster context - should succeed without trying to update kubeconfig + err := cm.SetCurrentContext("in-cluster") + assert.NoError(t, err) + + assert.Equal(t, "in-cluster", cm.currentContext) + assert.False(t, cm.contexts[testContext1].IsActive) + assert.True(t, cm.contexts["in-cluster"].IsActive) +} + func testUpdateKubeconfigCurrentContext(t *testing.T) { tempDir := t.TempDir() kubeconfigPath := filepath.Join(tempDir, "config")