Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Friedman authored and Adam Friedman committed Jan 17, 2024
2 parents 159057c + d9a0a3d commit b72266f
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,26 @@ public static IServiceCollection AddKubeClientOptionsFromKubeConfig(this IServic
/// <param name="services">
/// The service collection to configure.
/// </param>
/// <param name="defaultKubeNamespace">
/// The default namespace to use (if not specified, "default" is used).
/// </param>
/// <returns>
/// The configured service collection.
/// </returns>
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;
Expand All @@ -308,22 +315,29 @@ public static IServiceCollection AddKubeClientOptionsFromPodServiceAccount(this
/// <param name="name">
/// The name used to resolve these options.
/// </param>
/// <param name="defaultKubeNamespace">
/// The default namespace to use (if not specified, "default" is used).
/// </param>
/// <returns>
/// The configured service collection.
/// </returns>
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));

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;
Expand Down

0 comments on commit b72266f

Please sign in to comment.