diff --git a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs index 84a23a667..934b47157 100644 --- a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs +++ b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs @@ -69,13 +69,28 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(string kub /// file is located. When , the paths will be considered to be relative to the current working directory. public static KubernetesClientConfiguration BuildConfigFromConfigFile(FileInfo kubeconfig, string currentContext = null, string masterUrl = null, bool useRelativePaths = true) + { + return BuildConfigFromConfigFileAsync(kubeconfig, currentContext, masterUrl, useRelativePaths).GetAwaiter().GetResult(); + } + + /// + /// 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 + /// override the kube api server endpoint, set null if do not want to override + /// When , the paths in the kubeconfig file will be considered to be relative to the directory in which the kubeconfig + /// file is located. When , the paths will be considered to be relative to the current working directory. + + public static async Task BuildConfigFromConfigFileAsync(FileInfo kubeconfig, + string currentContext = null, string masterUrl = null, bool useRelativePaths = true) { if (kubeconfig == null) { throw new NullReferenceException(nameof(kubeconfig)); } - var k8SConfig = LoadKubeConfig(kubeconfig, useRelativePaths); + var k8SConfig = await LoadKubeConfigAsync(kubeconfig, useRelativePaths); var k8SConfiguration = GetKubernetesClientConfiguration(currentContext, masterUrl, k8SConfig); return k8SConfiguration; @@ -89,6 +104,18 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(FileInfo k /// 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) + { + return BuildConfigFromConfigFileAsync(kubeconfig, currentContext, masterUrl).GetAwaiter().GetResult(); + } + + /// + /// Initializes a new instance of the from config file + /// + /// 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 async Task BuildConfigFromConfigFileAsync(Stream kubeconfig, + string currentContext = null, string masterUrl = null) { if (kubeconfig == null) { @@ -102,7 +129,7 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(Stream kub kubeconfig.Position = 0; - var k8SConfig = Yaml.LoadFromStreamAsync(kubeconfig).GetAwaiter().GetResult(); + var k8SConfig = await Yaml.LoadFromStreamAsync(kubeconfig); var k8SConfiguration = GetKubernetesClientConfiguration(currentContext, masterUrl, k8SConfig); return k8SConfiguration;