Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ctxName by adding a non-global val #839

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions pkg/command/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func newCreateCtxCmd() *cobra.Command {
# Create a TKG management cluster context using default kubeconfig path and a kubeconfig context
tanzu context create mgmt-cluster --kubecontext kubecontext

# Create a TMC(mission-control) context using endpoint and type
# Create a TMC(mission-control) context using endpoint and type
tanzu context create mytmc --endpoint tmc.example.com:443 --type tmc

# Create a Tanzu context with the default endpoint (--type is not necessary for the default endpoint)
Expand All @@ -154,7 +154,7 @@ func newCreateCtxCmd() *cobra.Command {
# Create a Tanzu context but skip TLS verification (this is insecure):
tanzu context create mytanzu --endpoint https://api.tanzu.cloud.vmware.com --insecure-skip-tls-verify

Notes:
Notes:
1. TMC context: To create Mission Control (TMC) context an API Key is required. It can be provided using the
TANZU_API_TOKEN environment variable or entered during context creation.
2. Tanzu context: To create Tanzu context an API Key is optional. If provided using the TANZU_API_TOKEN environment
Expand Down Expand Up @@ -474,6 +474,9 @@ func createContextWithKubeconfig() (context *configtypes.Context, err error) {
}

func createContextWithTMCEndpoint() (context *configtypes.Context, err error) {
// Create a non-global context name, ctxName is global and when NewRootCmd is called, it gets lost
var contextName string

if endpoint == "" {
endpoint, err = promptEndpoint("")
if err != nil {
Expand All @@ -486,6 +489,8 @@ func createContextWithTMCEndpoint() (context *configtypes.Context, err error) {
return context, err
}
}

contextName = ctxName
exists, err := config.ContextExists(ctxName)
if err != nil {
return context, err
Expand All @@ -500,7 +505,7 @@ func createContextWithTMCEndpoint() (context *configtypes.Context, err error) {
}

context = &configtypes.Context{
Name: ctxName,
Name: contextName,
ContextType: configtypes.ContextTypeTMC,
GlobalOpts: &configtypes.GlobalServer{Endpoint: sanitizeEndpoint(endpoint)},
}
Expand All @@ -510,6 +515,9 @@ func createContextWithTMCEndpoint() (context *configtypes.Context, err error) {

// createContextWithClusterEndpoint creates context for cluster endpoint with pinniped auth
func createContextWithClusterEndpoint() (context *configtypes.Context, err error) {
// Create a non-global context name, ctxName is global and when NewRootCMD is called, it gets lost
var contextName string

if endpoint == "" {
endpoint, err = promptEndpoint("")
if err != nil {
Expand All @@ -522,6 +530,8 @@ func createContextWithClusterEndpoint() (context *configtypes.Context, err error
return context, err
}
}

contextName = ctxName
exists, err := config.ContextExists(ctxName)
if err != nil {
return context, err
Expand All @@ -539,7 +549,7 @@ func createContextWithClusterEndpoint() (context *configtypes.Context, err error
}

context = &configtypes.Context{
Name: ctxName,
Name: contextName,
ContextType: configtypes.ContextTypeK8s,
ClusterOpts: &configtypes.ClusterServer{
Path: kubeConfig,
Expand All @@ -565,6 +575,9 @@ func getIDPType(endpoint string) config.IdpType {
}

func createContextWithTanzuEndpoint() (context *configtypes.Context, err error) {
// Create a non-global context name, ctxName is global and when NewRootCMD is called, it gets lost
var contextName string

if endpoint == "" {
endpoint, err = promptEndpoint(centralconfig.DefaultTanzuPlatformEndpoint)
if err != nil {
Expand All @@ -578,6 +591,7 @@ func createContextWithTanzuEndpoint() (context *configtypes.Context, err error)
}
}

contextName = ctxName
exists, err := config.ContextExists(ctxName)
if err != nil {
return context, err
Expand All @@ -596,7 +610,7 @@ func createContextWithTanzuEndpoint() (context *configtypes.Context, err error)

// Tanzu context would have both CSP(GlobalOpts) auth details and kubeconfig(ClusterOpts),
context = &configtypes.Context{
Name: ctxName,
Name: contextName,
ContextType: configtypes.ContextTypeTanzu,
GlobalOpts: &configtypes.GlobalServer{Endpoint: tanzuUCPEndpoint},
ClusterOpts: &configtypes.ClusterServer{},
Expand Down
Loading