diff --git a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs index cfc34a1..25eb05e 100644 --- a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs +++ b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs @@ -39,6 +39,7 @@ namespace k8s } /// + /// Initializes a new instance of the from config file /// /// Fileinfo of the kubeconfig, cannot be null /// override the context in config file, set null if do not want to override @@ -60,10 +61,11 @@ namespace k8s } /// + /// Initializes a new instance of the from config file /// - /// Fileinfo of the kubeconfig, cannot be null, whitespaced or empty - /// override the context in config file, set null if do not want to override - /// overrider kube api server endpoint, set null if do not want to override + /// Stream of the kubeconfig, cannot be null + /// Override the current context in config, set null if do not want to override + /// Override the Kubernetes API server endpoint, set null if do not want to override public static KubernetesClientConfiguration BuildConfigFromConfigFile(Stream kubeconfig, string currentContext = null, string masterUrl = null) { @@ -85,6 +87,15 @@ namespace k8s return k8SConfiguration; } + /// + /// Initializes a new instance of from pre-loaded config object. + /// + /// A , for example loaded from + /// Override the current context in config, set null if do not want to override + /// Override the Kubernetes API server endpoint, set null if do not want to override + 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(); diff --git a/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs b/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs index fb8065e..40fbfd5 100755 --- a/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs +++ b/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs @@ -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); + } + /// /// Checks Host is loaded from the default configuration file ///