diff --git a/src/KubeClient.Extensions.DependencyInjection/KubeClientOptionsRegistrationExtensions.cs b/src/KubeClient.Extensions.DependencyInjection/KubeClientOptionsRegistrationExtensions.cs index e757493..2a090bb 100644 --- a/src/KubeClient.Extensions.DependencyInjection/KubeClientOptionsRegistrationExtensions.cs +++ b/src/KubeClient.Extensions.DependencyInjection/KubeClientOptionsRegistrationExtensions.cs @@ -281,19 +281,26 @@ public static IServiceCollection AddKubeClientOptionsFromKubeConfig(this IServic /// /// The service collection to configure. /// + /// + /// The default namespace to use (if not specified, "default" is used). + /// /// /// The configured service collection. /// - public static IServiceCollection AddKubeClientOptionsFromPodServiceAccount(this IServiceCollection services) + public static IServiceCollection AddKubeClientOptionsFromPodServiceAccount(this IServiceCollection services, string defaultKubeNamespace = "default") { if (services == null) throw new ArgumentNullException(nameof(services)); + if (String.IsNullOrWhiteSpace(defaultKubeNamespace)) + throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(defaultKubeNamespace)}.", nameof(defaultKubeNamespace)); + services.AddKubeClientOptions(kubeClientOptions => { KubeClientOptions fromPodServiceAccount = KubeClientOptions.FromPodServiceAccount(); - fromPodServiceAccount.CopyTo(kubeClientOptions); + + kubeClientOptions.KubeNamespace = defaultKubeNamespace; }); return services; @@ -308,10 +315,13 @@ public static IServiceCollection AddKubeClientOptionsFromPodServiceAccount(this /// /// The name used to resolve these options. /// + /// + /// The default namespace to use (if not specified, "default" is used). + /// /// /// The configured service collection. /// - public static IServiceCollection AddKubeClientOptionsFromPodServiceAccount(this IServiceCollection services, string name) + public static IServiceCollection AddKubeClientOptionsFromPodServiceAccount(this IServiceCollection services, string name, string defaultKubeNamespace = "default") { if (services == null) throw new ArgumentNullException(nameof(services)); @@ -319,11 +329,15 @@ public static IServiceCollection AddKubeClientOptionsFromPodServiceAccount(this if (String.IsNullOrWhiteSpace(name)) throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(name)}.", nameof(name)); + if (String.IsNullOrWhiteSpace(defaultKubeNamespace)) + throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(defaultKubeNamespace)}.", nameof(defaultKubeNamespace)); + services.AddKubeClientOptions(name, kubeClientOptions => { KubeClientOptions fromPodServiceAccount = KubeClientOptions.FromPodServiceAccount(); - fromPodServiceAccount.CopyTo(kubeClientOptions); + + kubeClientOptions.KubeNamespace = defaultKubeNamespace; }); return services;