1919package kube
2020
2121import (
22+ "fmt"
23+
2224 "github.com/AlecAivazis/survey/v2/terminal"
2325 "github.com/docker/compose-cli/api/context/store"
2426 "github.com/docker/compose-cli/api/errdefs"
@@ -41,7 +43,7 @@ func (cp ContextParams) CreateContextData() (interface{}, string, error) {
4143 // we use the current kubectl context from a $KUBECONFIG path
4244 return store.KubeContext {
4345 FromEnvironment : cp .FromEnvironment ,
44- }, cp .Description , nil
46+ }, cp .getDescription () , nil
4547 }
4648 user := prompt.User {}
4749 selectContext := func () error {
@@ -67,7 +69,7 @@ func (cp ContextParams) CreateContextData() (interface{}, string, error) {
6769 ContextName : cp .KubeContextName ,
6870 KubeconfigPath : cp .KubeConfigPath ,
6971 FromEnvironment : cp .FromEnvironment ,
70- }, cp .Description , nil
72+ }, cp .getDescription () , nil
7173 }
7274 err := selectContext ()
7375 if err != nil {
@@ -105,5 +107,19 @@ func (cp ContextParams) CreateContextData() (interface{}, string, error) {
105107 ContextName : cp .KubeContextName ,
106108 KubeconfigPath : cp .KubeConfigPath ,
107109 FromEnvironment : cp .FromEnvironment ,
108- }, cp .Description , nil
110+ }, cp .getDescription (), nil
111+ }
112+
113+ func (cp ContextParams ) getDescription () string {
114+ if cp .Description != "" {
115+ return cp .Description
116+ }
117+ if cp .FromEnvironment {
118+ return "From environment variables"
119+ }
120+ configFile := "default kube config"
121+ if cp .KubeConfigPath != "" {
122+ configFile = cp .KubeConfigPath
123+ }
124+ return fmt .Sprintf ("%s (in %s)" , cp .KubeContextName , configFile )
109125}
0 commit comments