Skip to content

Commit ee77895

Browse files
authored
Merge pull request #3 from ViniciusSouza/visouza/config-stream
checking if the stream can be seek
2 parents 4e7d8e4 + 13339c7 commit ee77895

File tree

3 files changed

+49
-25
lines changed

3 files changed

+49
-25
lines changed

src/KubernetesClient.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<PackageVersion>0.2.0-beta</PackageVersion>
3+
<PackageVersion>0.2.1-beta</PackageVersion>
44
<Authors>The Kubernetes Project Authors</Authors>
55
<Copyright>2017 The Kubernetes Project Authors</Copyright>
66
<Description>Client library for the Kubernetes open source container orchestrator.</Description>
@@ -11,6 +11,10 @@
1111

1212
<TargetFramework>netstandard1.4</TargetFramework>
1313
<RootNamespace>k8s</RootNamespace>
14+
<Version>1.1.0</Version>
15+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
16+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
17+
<PackageId>KubernetesClientDXBrazil</PackageId>
1418
</PropertyGroup>
1519
<ItemGroup>
1620
<Compile Remove="GlobalSuppressions.cs" />

src/KubernetesClientConfiguration.ConfigFile.cs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(FileInfo k
4949
throw new NullReferenceException(nameof(kubeconfig));
5050
}
5151

52-
var k8SConfig = LoadKubeConfig(kubeconfig);
52+
var k8SConfig = LoadKubeConfig(kubeconfig);
5353
var k8SConfiguration = GetKubernetesClientConfiguration(ref currentContext, masterUrl, k8SConfig);
54-
54+
5555
return k8SConfiguration;
56-
}
57-
56+
}
57+
5858
/// <summary>
5959
/// </summary>
6060
/// <param name="kubeconfig">Fileinfo of the kubeconfig, cannot be null, whitespaced or empty</param>
@@ -68,12 +68,12 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(string kub
6868
throw new NullReferenceException(nameof(kubeconfig));
6969
}
7070

71-
var k8SConfig = LoadKubeConfig(kubeconfig);
71+
var k8SConfig = LoadKubeConfig(kubeconfig);
7272
var k8SConfiguration = GetKubernetesClientConfiguration(ref currentContext, masterUrl, k8SConfig);
7373

7474
return k8SConfiguration;
75-
}
76-
75+
}
76+
7777
/// <summary>
7878
/// </summary>
7979
/// <param name="kubeconfig">Fileinfo of the kubeconfig, cannot be null, whitespaced or empty</param>
@@ -82,19 +82,26 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(string kub
8282
public static KubernetesClientConfiguration BuildConfigFromConfigFile(Stream kubeconfig,
8383
string currentContext = null, string masterUrl = null)
8484
{
85-
if (kubeconfig == null && kubeconfig.Length == 0)
85+
if (kubeconfig == null)
8686
{
8787
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;
8996

9097
var k8SConfig = LoadKubeConfig(kubeconfig);
9198
var k8SConfiguration = GetKubernetesClientConfiguration(ref currentContext, masterUrl, k8SConfig);
9299

93100
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+
{
98105
var k8SConfiguration = new KubernetesClientConfiguration();
99106

100107
currentContext = currentContext ?? k8SConfig.CurrentContext;
@@ -111,11 +118,11 @@ private static KubernetesClientConfiguration GetKubernetesClientConfiguration(re
111118
if (string.IsNullOrWhiteSpace(k8SConfiguration.Host))
112119
{
113120
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+
119126
/// <summary>
120127
/// Validates and Intializes Client Configuration
121128
/// </summary>
@@ -272,8 +279,8 @@ private static K8SConfiguration LoadKubeConfig(FileInfo kubeconfig)
272279
{
273280
return deserializer.Deserialize<K8SConfiguration>(kubeConfigTextStream);
274281
}
275-
}
276-
282+
}
283+
277284
/// <summary>
278285
/// Loads Kube Config from string
279286
/// </summary>
@@ -285,17 +292,17 @@ private static K8SConfiguration LoadKubeConfig(string kubeconfig)
285292
var deserializeBuilder = new DeserializerBuilder();
286293
var deserializer = deserializeBuilder.Build();
287294
return deserializer.Deserialize<K8SConfiguration>(kubeconfig);
288-
}
289-
295+
}
296+
290297
/// <summary>
291298
/// Loads Kube Config from stream.
292299
/// </summary>
293300
/// <param name="kubeconfig">Kube config file contents</param>
294301
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
295302
private static K8SConfiguration LoadKubeConfig(Stream kubeconfig)
296303
{
297-
StreamReader sr = new StreamReader(kubeconfig);
298-
string strKubeConfig = sr.ReadToEnd();
304+
StreamReader sr = new StreamReader(kubeconfig);
305+
string strKubeConfig = sr.ReadToEnd();
299306
return LoadKubeConfig(strKubeConfig);
300307
}
301308
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
This file is used by the publish/package process of your project. You can customize the behavior of this process
4+
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
5+
-->
6+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
7+
<PropertyGroup>
8+
<PublishProtocol>FileSystem</PublishProtocol>
9+
<Configuration>Release</Configuration>
10+
<TargetFramework>netstandard1.4</TargetFramework>
11+
<PublishDir>bin\Release\PublishOutput</PublishDir>
12+
</PropertyGroup>
13+
</Project>

0 commit comments

Comments
 (0)