3
3
using System . Linq ;
4
4
using System . Runtime . InteropServices ;
5
5
using System . Security . Cryptography . X509Certificates ;
6
- using System . Threading . Tasks ;
6
+ using System . Threading . Tasks ;
7
7
using k8s . Exceptions ;
8
8
using k8s . KubeConfigModels ;
9
-
9
+
10
10
namespace k8s
11
11
{
12
12
public partial class KubernetesClientConfiguration
@@ -29,7 +29,7 @@ public partial class KubernetesClientConfiguration
29
29
/// </summary>
30
30
/// <param name="masterUrl">kube api server endpoint</param>
31
31
/// <param name="kubeconfigPath">Explicit file path to kubeconfig. Set to null to use the default file path</param>
32
- public static KubernetesClientConfiguration BuildConfigFromConfigFile ( string kubeconfigPath ,
32
+ public static KubernetesClientConfiguration BuildConfigFromConfigFile ( string kubeconfigPath = null ,
33
33
string currentContext = null , string masterUrl = null )
34
34
{
35
35
return BuildConfigFromConfigFile ( new FileInfo ( kubeconfigPath ?? KubeConfigDefaultLocation ) , null ,
@@ -240,30 +240,30 @@ private void SetUserDetails(K8SConfiguration k8SConfig, Context activeContext)
240
240
throw new KubeConfigException (
241
241
$ "User: { userDetails . Name } does not have appropriate auth credentials in kubeconfig") ;
242
242
}
243
- }
244
-
243
+ }
244
+
245
245
/// <summary>
246
246
/// Loads entire Kube Config from default or explicit file path
247
247
/// </summary>
248
248
/// <param name="kubeconfigPath">Explicit file path to kubeconfig. Set to null to use the default file path</param>
249
- /// <returns></returns>
250
- public static async Task < K8SConfiguration > LoadKubeConfigAsync ( string kubeconfigPath = null )
251
- {
252
- var fileInfo = new FileInfo ( kubeconfigPath ?? KubeConfigDefaultLocation ) ;
253
-
254
- return await LoadKubeConfigAsync ( fileInfo ) ;
255
- }
256
-
249
+ /// <returns></returns>
250
+ public static async Task < K8SConfiguration > LoadKubeConfigAsync ( string kubeconfigPath = null )
251
+ {
252
+ var fileInfo = new FileInfo ( kubeconfigPath ?? KubeConfigDefaultLocation ) ;
253
+
254
+ return await LoadKubeConfigAsync ( fileInfo ) ;
255
+ }
256
+
257
257
/// <summary>
258
258
/// Loads entire Kube Config from default or explicit file path
259
259
/// </summary>
260
260
/// <param name="kubeconfigPath">Explicit file path to kubeconfig. Set to null to use the default file path</param>
261
- /// <returns></returns>
262
- public static K8SConfiguration LoadKubeConfig ( string kubeconfigPath = null )
263
- {
264
- return LoadKubeConfigAsync ( kubeconfigPath ) . GetAwaiter ( ) . GetResult ( ) ;
265
- }
266
-
261
+ /// <returns></returns>
262
+ public static K8SConfiguration LoadKubeConfig ( string kubeconfigPath = null )
263
+ {
264
+ return LoadKubeConfigAsync ( kubeconfigPath ) . GetAwaiter ( ) . GetResult ( ) ;
265
+ }
266
+
267
267
// <summary>
268
268
/// Loads Kube Config
269
269
/// </summary>
@@ -274,10 +274,10 @@ public static async Task<K8SConfiguration> LoadKubeConfigAsync(FileInfo kubeconf
274
274
if ( ! kubeconfig . Exists )
275
275
{
276
276
throw new KubeConfigException ( $ "kubeconfig file not found at { kubeconfig . FullName } ") ;
277
- }
278
-
277
+ }
278
+
279
279
using ( var stream = kubeconfig . OpenRead ( ) )
280
- {
280
+ {
281
281
return await Yaml . LoadFromStreamAsync < K8SConfiguration > ( stream ) ;
282
282
}
283
283
}
@@ -288,17 +288,17 @@ public static async Task<K8SConfiguration> LoadKubeConfigAsync(FileInfo kubeconf
288
288
/// <param name="kubeconfig">Kube config file contents</param>
289
289
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
290
290
public static K8SConfiguration LoadKubeConfig ( FileInfo kubeconfig )
291
- {
291
+ {
292
292
return LoadKubeConfigAsync ( kubeconfig ) . GetAwaiter ( ) . GetResult ( ) ;
293
- }
294
-
293
+ }
294
+
295
295
// <summary>
296
296
/// Loads Kube Config
297
297
/// </summary>
298
298
/// <param name="kubeconfigStream">Kube config file contents stream</param>
299
299
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
300
300
public static async Task < K8SConfiguration > LoadKubeConfigAsync ( Stream kubeconfigStream )
301
- {
301
+ {
302
302
return await Yaml . LoadFromStreamAsync < K8SConfiguration > ( kubeconfigStream ) ;
303
303
}
304
304
@@ -308,7 +308,7 @@ public static async Task<K8SConfiguration> LoadKubeConfigAsync(Stream kubeconfig
308
308
/// <param name="kubeconfig">Kube config file contents stream</param>
309
309
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
310
310
public static K8SConfiguration LoadKubeConfig ( Stream kubeconfigStream )
311
- {
311
+ {
312
312
return LoadKubeConfigAsync ( kubeconfigStream ) . GetAwaiter ( ) . GetResult ( ) ;
313
313
}
314
314
}
0 commit comments