Repository: vmware-tanzu/tanzu-framework (language: go)

Issue:
CurrentServer (`current`) field in ClientConfig should not point to TMC context
**Bug description**

current field in the config.yaml is meant to be used to just include managment-cluster/k8s context and it should not include tmc context

For configuring tmc context CLI should use currentContext.mission-control field.

Also, TMC plugins should be using currentContext.mission-control to determine the active tmc context.

This is required for backward compatibility of kubernetes targeted plugins with new context/target functionality

**Affected product area (please put an X in all that apply)**

- ( ) APIs
- ( ) Addons
- (x) CLI
- ( ) Docs
- ( ) IAM
- ( ) Installation
- ( ) Plugin
- ( ) Security
- ( ) Test and Release
- ( ) User Experience
- ( ) Developer Experience

**Expected behavior**

CurrentServer (`current`) field in ClientConfig should not point to TMC context.

**Steps to reproduce the bug**

**Version** (include the SHA if the version is not obvious)

**Environment where the bug was observed (cloud, OS, etc)**

**Relevant Debug Output (Logs, manifests, etc)**



Discussion / hints:

Fix patch:
diff --git a/cli/runtime/config/contexts.go b/cli/runtime/config/contexts.go
index 7e2832b6a0..1d868636b3 100644
--- a/cli/runtime/config/contexts.go
+++ b/cli/runtime/config/contexts.go
@@ -80,7 +80,7 @@ func SetContext(c *configapi.Context, setCurrent bool) error {
 	}
 
 	// Set current server
-	if setCurrent {
+	if setCurrent && s.Type == configapi.ManagementClusterServerType {
 		persist, err = setCurrentServer(node, s.Name)
 		if err != nil {
 			return err
diff --git a/cli/runtime/config/servers.go b/cli/runtime/config/servers.go
index b586f847f6..cdcbfcf649 100644
--- a/cli/runtime/config/servers.go
+++ b/cli/runtime/config/servers.go
@@ -6,6 +6,8 @@ package config
 import (
 	"fmt"
 
+	"github.com/pkg/errors"
+
 	configapi "github.com/vmware-tanzu/tanzu-framework/cli/runtime/apis/config/v1alpha1"
 	"github.com/vmware-tanzu/tanzu-framework/cli/runtime/config/nodeutils"
 
@@ -135,7 +137,7 @@ func SetServer(s *configapi.Server, setCurrent bool) error {
 			return err
 		}
 	}
-	if setCurrent {
+	if setCurrent && s.Type == configapi.ManagementClusterServerType {
 		persist, err = setCurrentServer(node, s.Name)
 		if err != nil {
 			return err
@@ -226,6 +228,15 @@ func RemoveServer(name string) error {
 }
 
 func setCurrentServer(node *yaml.Node, name string) (persist bool, err error) {
+	s, err := getServer(node, name)
+	if err != nil {
+		return false, err
+	}
+
+	if s.Type != configapi.ManagementClusterServerType {
+		return false, errors.Errorf("cannot set non management-cluster server as current server")
+	}
+
 	// find current server node
 	keys := []nodeutils.Key{
 		{Name: KeyCurrentServer, Type: yaml.ScalarNode, Value: ""},


Test patch: