@@ -17,6 +17,7 @@ limitations under the License.
17
17
package genericclioptions
18
18
19
19
import (
20
+ "errors"
20
21
"os"
21
22
"path/filepath"
22
23
"regexp"
@@ -54,7 +55,17 @@ const (
54
55
flagHTTPCacheDir = "cache-dir"
55
56
)
56
57
57
- var defaultCacheDir = filepath .Join (homedir .HomeDir (), ".kube" , "http-cache" )
58
+ var (
59
+ defaultCacheDir = filepath .Join (homedir .HomeDir (), ".kube" , "http-cache" )
60
+
61
+ ErrEmptyConfig = errors .New (`Missing or incomplete configuration info. Please point to an existing, complete config file:
62
+
63
+ 1. Via the command-line flag --kubeconfig
64
+ 2. Via the KUBECONFIG environment variable
65
+ 3. In your home directory as ~/.kube/config
66
+
67
+ To view or setup config directly use the 'config' command.` )
68
+ )
58
69
59
70
// RESTClientGetter is an interface that the ConfigFlags describe to provide an easier way to mock for commands
60
71
// 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 {
108
119
// to a .kubeconfig file, loading rules, and config flag overrides.
109
120
// Expects the AddFlags method to have been called.
110
121
func (f * ConfigFlags ) ToRESTConfig () (* rest.Config , error ) {
111
- return f .ToRawKubeConfigLoader ().ClientConfig ()
122
+ config , err := f .ToRawKubeConfigLoader ().ClientConfig ()
123
+ // replace client-go's ErrEmptyConfig error with our custom, more verbose version
124
+ if clientcmd .IsEmptyConfig (err ) {
125
+ return nil , ErrEmptyConfig
126
+ }
127
+ return config , err
112
128
}
113
129
114
130
// ToRawKubeConfigLoader binds config flag values to config overrides
0 commit comments