mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Provide more verbose empty config error based on the context
This commit is contained in:
parent
b19ad9e7a7
commit
07dc17ffd9
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package genericclioptions
|
package genericclioptions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -54,7 +55,17 @@ const (
|
|||||||
flagHTTPCacheDir = "cache-dir"
|
flagHTTPCacheDir = "cache-dir"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultCacheDir = filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
|
var (
|
||||||
|
defaultCacheDir = filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
|
||||||
|
|
||||||
|
ErrEmptyConfig = errors.New(`Missing or incomplete configuration info. Please point to an existing, complete config file:
|
||||||
|
|
||||||
|
1. Via the command-line flag --kubeconfig
|
||||||
|
2. Via the KUBECONFIG environment variable
|
||||||
|
3. In your home directory as ~/.kube/config
|
||||||
|
|
||||||
|
To view or setup config directly use the 'config' command.`)
|
||||||
|
)
|
||||||
|
|
||||||
// RESTClientGetter is an interface that the ConfigFlags describe to provide an easier way to mock for commands
|
// RESTClientGetter is an interface that the ConfigFlags describe to provide an easier way to mock for commands
|
||||||
// and eliminate the direct coupling to a struct type. Users may wish to duplicate this type in their own packages
|
// and eliminate the direct coupling to a struct type. Users may wish to duplicate this type in their own packages
|
||||||
@ -108,7 +119,12 @@ type ConfigFlags struct {
|
|||||||
// to a .kubeconfig file, loading rules, and config flag overrides.
|
// to a .kubeconfig file, loading rules, and config flag overrides.
|
||||||
// Expects the AddFlags method to have been called.
|
// Expects the AddFlags method to have been called.
|
||||||
func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error) {
|
func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error) {
|
||||||
return f.ToRawKubeConfigLoader().ClientConfig()
|
config, err := f.ToRawKubeConfigLoader().ClientConfig()
|
||||||
|
// replace client-go's ErrEmptyConfig error with our custom, more verbose version
|
||||||
|
if clientcmd.IsEmptyConfig(err) {
|
||||||
|
return nil, ErrEmptyConfig
|
||||||
|
}
|
||||||
|
return config, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToRawKubeConfigLoader binds config flag values to config overrides
|
// ToRawKubeConfigLoader binds config flag values to config overrides
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNoContext = errors.New("no context chosen")
|
ErrNoContext = errors.New("no context chosen")
|
||||||
ErrEmptyConfig = errors.New("no configuration has been provided")
|
ErrEmptyConfig = errors.New("no configuration has been provided, try setting KUBERNETES_MASTER environment variable")
|
||||||
// message is for consistency with old behavior
|
// message is for consistency with old behavior
|
||||||
ErrEmptyCluster = errors.New("cluster has no server defined")
|
ErrEmptyCluster = errors.New("cluster has no server defined")
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user