Fix examples by re-adding the no-arg config file builder. (#137)
This commit is contained in:
@@ -3,10 +3,10 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using k8s.Exceptions;
|
using k8s.Exceptions;
|
||||||
using k8s.KubeConfigModels;
|
using k8s.KubeConfigModels;
|
||||||
|
|
||||||
namespace k8s
|
namespace k8s
|
||||||
{
|
{
|
||||||
public partial class KubernetesClientConfiguration
|
public partial class KubernetesClientConfiguration
|
||||||
@@ -29,7 +29,7 @@ namespace k8s
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="masterUrl">kube api server endpoint</param>
|
/// <param name="masterUrl">kube api server endpoint</param>
|
||||||
/// <param name="kubeconfigPath">Explicit file path to kubeconfig. Set to null to use the default file path</param>
|
/// <param name="kubeconfigPath">Explicit file path to kubeconfig. Set to null to use the default file path</param>
|
||||||
public static KubernetesClientConfiguration BuildConfigFromConfigFile(string kubeconfigPath,
|
public static KubernetesClientConfiguration BuildConfigFromConfigFile(string kubeconfigPath = null,
|
||||||
string currentContext = null, string masterUrl = null)
|
string currentContext = null, string masterUrl = null)
|
||||||
{
|
{
|
||||||
return BuildConfigFromConfigFile(new FileInfo(kubeconfigPath ?? KubeConfigDefaultLocation), null,
|
return BuildConfigFromConfigFile(new FileInfo(kubeconfigPath ?? KubeConfigDefaultLocation), null,
|
||||||
@@ -240,30 +240,30 @@ namespace k8s
|
|||||||
throw new KubeConfigException(
|
throw new KubeConfigException(
|
||||||
$"User: {userDetails.Name} does not have appropriate auth credentials in kubeconfig");
|
$"User: {userDetails.Name} does not have appropriate auth credentials in kubeconfig");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads entire Kube Config from default or explicit file path
|
/// Loads entire Kube Config from default or explicit file path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="kubeconfigPath">Explicit file path to kubeconfig. Set to null to use the default file path</param>
|
/// <param name="kubeconfigPath">Explicit file path to kubeconfig. Set to null to use the default file path</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<K8SConfiguration> LoadKubeConfigAsync(string kubeconfigPath = null)
|
public static async Task<K8SConfiguration> LoadKubeConfigAsync(string kubeconfigPath = null)
|
||||||
{
|
{
|
||||||
var fileInfo = new FileInfo(kubeconfigPath ?? KubeConfigDefaultLocation);
|
var fileInfo = new FileInfo(kubeconfigPath ?? KubeConfigDefaultLocation);
|
||||||
|
|
||||||
return await LoadKubeConfigAsync(fileInfo);
|
return await LoadKubeConfigAsync(fileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads entire Kube Config from default or explicit file path
|
/// Loads entire Kube Config from default or explicit file path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="kubeconfigPath">Explicit file path to kubeconfig. Set to null to use the default file path</param>
|
/// <param name="kubeconfigPath">Explicit file path to kubeconfig. Set to null to use the default file path</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static K8SConfiguration LoadKubeConfig(string kubeconfigPath = null)
|
public static K8SConfiguration LoadKubeConfig(string kubeconfigPath = null)
|
||||||
{
|
{
|
||||||
return LoadKubeConfigAsync(kubeconfigPath).GetAwaiter().GetResult();
|
return LoadKubeConfigAsync(kubeconfigPath).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
// <summary>
|
||||||
/// Loads Kube Config
|
/// Loads Kube Config
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -274,10 +274,10 @@ namespace k8s
|
|||||||
if (!kubeconfig.Exists)
|
if (!kubeconfig.Exists)
|
||||||
{
|
{
|
||||||
throw new KubeConfigException($"kubeconfig file not found at {kubeconfig.FullName}");
|
throw new KubeConfigException($"kubeconfig file not found at {kubeconfig.FullName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var stream = kubeconfig.OpenRead())
|
using (var stream = kubeconfig.OpenRead())
|
||||||
{
|
{
|
||||||
return await Yaml.LoadFromStreamAsync<K8SConfiguration>(stream);
|
return await Yaml.LoadFromStreamAsync<K8SConfiguration>(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,17 +288,17 @@ namespace k8s
|
|||||||
/// <param name="kubeconfig">Kube config file contents</param>
|
/// <param name="kubeconfig">Kube config file contents</param>
|
||||||
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
|
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
|
||||||
public static K8SConfiguration LoadKubeConfig(FileInfo kubeconfig)
|
public static K8SConfiguration LoadKubeConfig(FileInfo kubeconfig)
|
||||||
{
|
{
|
||||||
return LoadKubeConfigAsync(kubeconfig).GetAwaiter().GetResult();
|
return LoadKubeConfigAsync(kubeconfig).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
// <summary>
|
||||||
/// Loads Kube Config
|
/// Loads Kube Config
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="kubeconfigStream">Kube config file contents stream</param>
|
/// <param name="kubeconfigStream">Kube config file contents stream</param>
|
||||||
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
|
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
|
||||||
public static async Task<K8SConfiguration> LoadKubeConfigAsync(Stream kubeconfigStream)
|
public static async Task<K8SConfiguration> LoadKubeConfigAsync(Stream kubeconfigStream)
|
||||||
{
|
{
|
||||||
return await Yaml.LoadFromStreamAsync<K8SConfiguration>(kubeconfigStream);
|
return await Yaml.LoadFromStreamAsync<K8SConfiguration>(kubeconfigStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,7 +308,7 @@ namespace k8s
|
|||||||
/// <param name="kubeconfig">Kube config file contents stream</param>
|
/// <param name="kubeconfig">Kube config file contents stream</param>
|
||||||
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
|
/// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns>
|
||||||
public static K8SConfiguration LoadKubeConfig(Stream kubeconfigStream)
|
public static K8SConfiguration LoadKubeConfig(Stream kubeconfigStream)
|
||||||
{
|
{
|
||||||
return LoadKubeConfigAsync(kubeconfigStream).GetAwaiter().GetResult();
|
return LoadKubeConfigAsync(kubeconfigStream).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user