@@ -49,12 +49,12 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(FileInfo k
49
49
throw new NullReferenceException ( nameof ( kubeconfig ) ) ;
50
50
}
51
51
52
- var k8SConfig = LoadKubeConfig ( kubeconfig ) ;
52
+ var k8SConfig = LoadKubeConfig ( kubeconfig ) ;
53
53
var k8SConfiguration = GetKubernetesClientConfiguration ( ref currentContext , masterUrl , k8SConfig ) ;
54
-
54
+
55
55
return k8SConfiguration ;
56
- }
57
-
56
+ }
57
+
58
58
/// <summary>
59
59
/// </summary>
60
60
/// <param name="kubeconfig">Fileinfo of the kubeconfig, cannot be null, whitespaced or empty</param>
@@ -68,12 +68,12 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(string kub
68
68
throw new NullReferenceException ( nameof ( kubeconfig ) ) ;
69
69
}
70
70
71
- var k8SConfig = LoadKubeConfig ( kubeconfig ) ;
71
+ var k8SConfig = LoadKubeConfig ( kubeconfig ) ;
72
72
var k8SConfiguration = GetKubernetesClientConfiguration ( ref currentContext , masterUrl , k8SConfig ) ;
73
73
74
74
return k8SConfiguration ;
75
- }
76
-
75
+ }
76
+
77
77
/// <summary>
78
78
/// </summary>
79
79
/// <param name="kubeconfig">Fileinfo of the kubeconfig, cannot be null, whitespaced or empty</param>
@@ -82,19 +82,26 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(string kub
82
82
public static KubernetesClientConfiguration BuildConfigFromConfigFile ( Stream kubeconfig ,
83
83
string currentContext = null , string masterUrl = null )
84
84
{
85
- if ( kubeconfig == null && kubeconfig . Length == 0 )
85
+ if ( kubeconfig == null )
86
86
{
87
87
throw new NullReferenceException ( nameof ( kubeconfig ) ) ;
88
- }
88
+ }
89
+
90
+ if ( ! kubeconfig . CanSeek )
91
+ {
92
+ throw new Exception ( "Stream don't support seeking!" ) ;
93
+ }
94
+
95
+ kubeconfig . Position = 0 ;
89
96
90
97
var k8SConfig = LoadKubeConfig ( kubeconfig ) ;
91
98
var k8SConfiguration = GetKubernetesClientConfiguration ( ref currentContext , masterUrl , k8SConfig ) ;
92
99
93
100
return k8SConfiguration ;
94
- }
95
-
96
- private static KubernetesClientConfiguration GetKubernetesClientConfiguration ( ref string currentContext , string masterUrl , K8SConfiguration k8SConfig )
97
- {
101
+ }
102
+
103
+ private static KubernetesClientConfiguration GetKubernetesClientConfiguration ( ref string currentContext , string masterUrl , K8SConfiguration k8SConfig )
104
+ {
98
105
var k8SConfiguration = new KubernetesClientConfiguration ( ) ;
99
106
100
107
currentContext = currentContext ?? k8SConfig . CurrentContext ;
@@ -111,11 +118,11 @@ private static KubernetesClientConfiguration GetKubernetesClientConfiguration(re
111
118
if ( string . IsNullOrWhiteSpace ( k8SConfiguration . Host ) )
112
119
{
113
120
throw new KubeConfigException ( "Cannot infer server host url either from context or masterUrl" ) ;
114
- }
115
-
116
- return k8SConfiguration ;
117
- }
118
-
121
+ }
122
+
123
+ return k8SConfiguration ;
124
+ }
125
+
119
126
/// <summary>
120
127
/// Validates and Intializes Client Configuration
121
128
/// </summary>
@@ -272,8 +279,8 @@ private static K8SConfiguration LoadKubeConfig(FileInfo kubeconfig)
272
279
{
273
280
return deserializer . Deserialize < K8SConfiguration > ( kubeConfigTextStream ) ;
274
281
}
275
- }
276
-
282
+ }
283
+
277
284
/// <summary>
278
285
/// Loads Kube Config from string
279
286
/// </summary>
@@ -285,17 +292,17 @@ private static K8SConfiguration LoadKubeConfig(string kubeconfig)
285
292
var deserializeBuilder = new DeserializerBuilder ( ) ;
286
293
var deserializer = deserializeBuilder . Build ( ) ;
287
294
return deserializer . Deserialize < K8SConfiguration > ( kubeconfig ) ;
288
- }
289
-
295
+ }
296
+
290
297
/// <summary>
291
298
/// Loads Kube Config from stream.
292
299
/// </summary>
293
300
/// <param name="kubeconfig">Kube config file contents</param>
294
301
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
295
302
private static K8SConfiguration LoadKubeConfig ( Stream kubeconfig )
296
303
{
297
- StreamReader sr = new StreamReader ( kubeconfig ) ;
298
- string strKubeConfig = sr . ReadToEnd ( ) ;
304
+ StreamReader sr = new StreamReader ( kubeconfig ) ;
305
+ string strKubeConfig = sr . ReadToEnd ( ) ;
299
306
return LoadKubeConfig ( strKubeConfig ) ;
300
307
}
301
308
}
0 commit comments