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 18, 2024
2 parents d6f07f4 + 04180d3 commit 6d0bbcf
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public static IServiceCollection AddKubeClientOptionsFromKubeConfig(this IServic
KubeClientOptions optionsForTargetContext = config.ToKubeClientOptions(kubeContextName, defaultKubeNamespace);

optionsForTargetContext.CopyTo(kubeClientOptions);

kubeClientOptions.KubeNamespace = defaultKubeNamespace;
});

return services;
Expand Down Expand Up @@ -156,6 +158,8 @@ public static IServiceCollection AddKubeClientOptionsFromKubeConfig(this IServic
KubeClientOptions optionsForTargetContext = config.ToKubeClientOptions(kubeContextName, defaultKubeNamespace);

optionsForTargetContext.CopyTo(kubeClientOptions);

kubeClientOptions.KubeNamespace = defaultKubeNamespace;
});

return services;
Expand Down Expand Up @@ -186,25 +190,20 @@ public static IServiceCollection AddKubeClientOptionsFromKubeConfig(this IServic

FileInfo kubeConfigFile = GetKubeConfigFile(kubeConfigFileName);

// List of contexts is static for application lifetime...
K8sConfig config = K8sConfig.Load(kubeConfigFile);
foreach (Context targetContext in config.Contexts) // AF: List of contexts is static for application lifetime, but config for those contexts is dynamic.

foreach (Context targetContext in config.Contexts)
{
services.AddKubeClientOptions(targetContext.Name, kubeClientOptions =>
{
Cluster targetCluster = config.Clusters.Find(cluster => cluster.Name == targetContext.Config.ClusterName);
if (targetCluster == null)
throw new InvalidOperationException($"Cannot find a cluster in the Kubernetes client configuration named '{targetContext.Config.ClusterName}'.");
// ...but config for those contexts is dynamic.
K8sConfig currentConfig = K8sConfig.Load(kubeConfigFile);

UserIdentity targetUser = config.UserIdentities.Find(user => user.Name == targetContext.Config.UserName);
if (targetUser == null)
throw new InvalidOperationException($"Cannot find a user identity in the Kubernetes client configuration named '{targetContext.Config.UserName}'.");
KubeClientOptions optionsForTargetContext = currentConfig.ToKubeClientOptions(targetContext.Name, defaultKubeNamespace);
optionsForTargetContext.CopyTo(kubeClientOptions);

kubeClientOptions.ApiEndPoint = new Uri(targetCluster.Config.Server);
kubeClientOptions.KubeNamespace = defaultKubeNamespace;

kubeClientOptions.ClientCertificate = targetUser.Config.GetClientCertificate();
kubeClientOptions.CertificationAuthorityCertificate = targetCluster.Config.GetCACertificate();
kubeClientOptions.AccessToken = targetUser.Config.GetRawToken();
});
}

Expand Down

0 comments on commit 6d0bbcf

Please sign in to comment.