Create KubernetesClientConfiguration from pre-loaded K8SConfiguration (#213)

* Create KubernetesClientConfiguration from pre-loaded K8SConfiguration

* Tweaked a couple more doc strings

* Fix duplicated tests

* Give the new method a more informative name
This commit is contained in:
itowlson
2018-10-26 23:25:22 -07:00
committed by k8s-ci-robot
parent 355d4a3927
commit 7c9cc88d38
2 changed files with 22 additions and 3 deletions

View File

@@ -39,6 +39,7 @@ namespace k8s
}
/// <summary>
/// Initializes a new instance of the <see cref="KubernetesClientConfiguration" /> from config file
/// </summary>
/// <param name="kubeconfig">Fileinfo of the kubeconfig, cannot be null</param>
/// <param name="currentContext">override the context in config file, set null if do not want to override</param>
@@ -60,10 +61,11 @@ namespace k8s
}
/// <summary>
/// Initializes a new instance of the <see cref="KubernetesClientConfiguration" /> from config file
/// </summary>
/// <param name="kubeconfig">Fileinfo of the kubeconfig, cannot be null, whitespaced or empty</param>
/// <param name="currentContext">override the context in config file, set null if do not want to override</param>
/// <param name="masterUrl">overrider kube api server endpoint, set null if do not want to override</param>
/// <param name="kubeconfig">Stream of the kubeconfig, cannot be null</param>
/// <param name="currentContext">Override the current context in config, set null if do not want to override</param>
/// <param name="masterUrl">Override the Kubernetes API server endpoint, set null if do not want to override</param>
public static KubernetesClientConfiguration BuildConfigFromConfigFile(Stream kubeconfig,
string currentContext = null, string masterUrl = null)
{
@@ -85,6 +87,15 @@ namespace k8s
return k8SConfiguration;
}
/// <summary>
/// Initializes a new instance of <see cref="KubernetesClientConfiguration"/> from pre-loaded config object.
/// </summary>
/// <param name="k8sConfig">A <see cref="K8SConfiguration"/>, for example loaded from <see cref="LoadKubeConfigAsync(string, bool)" /></param>
/// <param name="currentContext">Override the current context in config, set null if do not want to override</param>
/// <param name="masterUrl">Override the Kubernetes API server endpoint, set null if do not want to override</param>
public static KubernetesClientConfiguration BuildConfigFromConfigObject(K8SConfiguration k8SConfig, string currentContext = null, string masterUrl = null)
=> GetKubernetesClientConfiguration(currentContext, masterUrl, k8SConfig);
private static KubernetesClientConfiguration GetKubernetesClientConfiguration(string currentContext, string masterUrl, K8SConfiguration k8SConfig)
{
var k8SConfiguration = new KubernetesClientConfiguration();

View File

@@ -138,6 +138,14 @@ namespace k8s.Tests
KubernetesClientConfiguration.BuildConfigFromConfigFile(fi, "context-not-found"));
}
[Fact]
public void CreatedFromPreLoadedConfig()
{
var k8sConfig = KubernetesClientConfiguration.LoadKubeConfig(new FileInfo("assets/kubeconfig.yml"), useRelativePaths: false);
var cfg = KubernetesClientConfiguration.BuildConfigFromConfigObject(k8sConfig);
Assert.NotNull(cfg.Host);
}
/// <summary>
/// Checks Host is loaded from the default configuration file
/// </summary>