add TokenFileAUth which reloads token if it expires (#440)

This commit is contained in:
Shihang Zhang
2020-05-18 15:01:36 -07:00
committed by GitHub
parent 914c78b5f9
commit 6d5fefdbab
5 changed files with 71 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.IO;
using k8s.Authentication;
using k8s.Exceptions;
namespace k8s
@@ -42,7 +43,6 @@ namespace k8s
"unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined");
}
var token = File.ReadAllText(Path.Combine(ServiceAccountPath, ServiceAccountTokenKeyFileName));
var rootCAFile = Path.Combine(ServiceAccountPath, ServiceAccountRootCAKeyFileName);
var host = Environment.GetEnvironmentVariable("KUBERNETES_SERVICE_HOST");
var port = Environment.GetEnvironmentVariable("KUBERNETES_SERVICE_PORT");
@@ -50,7 +50,7 @@ namespace k8s
return new KubernetesClientConfiguration
{
Host = new UriBuilder("https", host, Convert.ToInt32(port)).ToString(),
AccessToken = token,
TokenProvider = new TokenFileAuth(Path.Combine(ServiceAccountPath, ServiceAccountTokenKeyFileName)),
SslCaCerts = CertUtils.LoadPemFileCert(rootCAFile),
};
}