@@ -127,6 +127,10 @@ type ClientConfigLoadingRules struct {
127
127
// DefaultClientConfig is an optional field indicating what rules to use to calculate a default configuration.
128
128
// This should match the overrides passed in to ClientConfig loader.
129
129
DefaultClientConfig ClientConfig
130
+
131
+ // WarnIfAllMissing indicates whether the configuration files pointed by KUBECONFIG environment variable are present or not.
132
+ // In case of missing files, it warns the user about the missing files.
133
+ WarnIfAllMissing bool
130
134
}
131
135
132
136
// ClientConfigLoadingRules implements the ClientConfigLoader interface.
@@ -136,20 +140,23 @@ var _ ClientConfigLoader = &ClientConfigLoadingRules{}
136
140
// use this constructor
137
141
func NewDefaultClientConfigLoadingRules () * ClientConfigLoadingRules {
138
142
chain := []string {}
143
+ warnIfAllMissing := false
139
144
140
145
envVarFiles := os .Getenv (RecommendedConfigPathEnvVar )
141
146
if len (envVarFiles ) != 0 {
142
147
fileList := filepath .SplitList (envVarFiles )
143
148
// prevent the same path load multiple times
144
149
chain = append (chain , deduplicate (fileList )... )
150
+ warnIfAllMissing = true
145
151
146
152
} else {
147
153
chain = append (chain , RecommendedHomeFile )
148
154
}
149
155
150
156
return & ClientConfigLoadingRules {
151
- Precedence : chain ,
152
- MigrationRules : currentMigrationRules (),
157
+ Precedence : chain ,
158
+ MigrationRules : currentMigrationRules (),
159
+ WarnIfAllMissing : warnIfAllMissing ,
153
160
}
154
161
}
155
162
@@ -172,6 +179,7 @@ func (rules *ClientConfigLoadingRules) Load() (*clientcmdapi.Config, error) {
172
179
}
173
180
174
181
errlist := []error {}
182
+ missingList := []string {}
175
183
176
184
kubeConfigFiles := []string {}
177
185
@@ -195,10 +203,14 @@ func (rules *ClientConfigLoadingRules) Load() (*clientcmdapi.Config, error) {
195
203
}
196
204
197
205
config , err := LoadFromFile (filename )
206
+
198
207
if os .IsNotExist (err ) {
199
208
// skip missing files
209
+ // Add to the missing list to produce a warning
210
+ missingList = append (missingList , filename )
200
211
continue
201
212
}
213
+
202
214
if err != nil {
203
215
errlist = append (errlist , fmt .Errorf ("Error loading config file \" %s\" : %v" , filename , err ))
204
216
continue
@@ -207,6 +219,10 @@ func (rules *ClientConfigLoadingRules) Load() (*clientcmdapi.Config, error) {
207
219
kubeconfigs = append (kubeconfigs , config )
208
220
}
209
221
222
+ if rules .WarnIfAllMissing && len (missingList ) > 0 && len (kubeconfigs ) == 0 {
223
+ klog .Warningf ("Config not found: %s" , strings .Join (missingList , ", " ))
224
+ }
225
+
210
226
// first merge all of our maps
211
227
mapConfig := clientcmdapi .NewConfig ()
212
228
0 commit comments