feat: Add a parameter to the GenericClient class that configures the disposal of the underlying client (#1274)

This commit is contained in:
Ivan Josipovic
2023-04-23 17:45:12 -07:00
committed by GitHub
parent 2f290783e4
commit 5e881551e6

View File

@@ -11,6 +11,7 @@ namespace k8s
private readonly string group;
private readonly string version;
private readonly string plural;
private readonly bool disposeClient;
[Obsolete]
public GenericClient(KubernetesClientConfiguration config, string group, string version, string plural)
@@ -18,17 +19,18 @@ namespace k8s
{
}
public GenericClient(IKubernetes kubernetes, string version, string plural)
: this(kubernetes, "", version, plural)
public GenericClient(IKubernetes kubernetes, string version, string plural, bool disposeClient = true)
: this(kubernetes, "", version, plural, disposeClient)
{
}
public GenericClient(IKubernetes kubernetes, string group, string version, string plural)
public GenericClient(IKubernetes kubernetes, string group, string version, string plural, bool disposeClient = true)
{
this.group = group;
this.version = version;
this.plural = plural;
this.kubernetes = kubernetes;
this.disposeClient = disposeClient;
}
public async Task<T> CreateAsync<T>(T obj, CancellationToken cancel = default)
@@ -151,7 +153,10 @@ namespace k8s
protected virtual void Dispose(bool disposing)
{
kubernetes.Dispose();
if (disposeClient)
{
kubernetes.Dispose();
}
}
}
}