feat: Add a parameter to the GenericClient class that configures the disposal of the underlying client (#1274)
This commit is contained in:
@@ -11,6 +11,7 @@ namespace k8s
|
|||||||
private readonly string group;
|
private readonly string group;
|
||||||
private readonly string version;
|
private readonly string version;
|
||||||
private readonly string plural;
|
private readonly string plural;
|
||||||
|
private readonly bool disposeClient;
|
||||||
|
|
||||||
[Obsolete]
|
[Obsolete]
|
||||||
public GenericClient(KubernetesClientConfiguration config, string group, string version, string plural)
|
public GenericClient(KubernetesClientConfiguration config, string group, string version, string plural)
|
||||||
@@ -18,17 +19,18 @@ namespace k8s
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericClient(IKubernetes kubernetes, string version, string plural)
|
public GenericClient(IKubernetes kubernetes, string version, string plural, bool disposeClient = true)
|
||||||
: this(kubernetes, "", version, plural)
|
: 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.group = group;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.plural = plural;
|
this.plural = plural;
|
||||||
this.kubernetes = kubernetes;
|
this.kubernetes = kubernetes;
|
||||||
|
this.disposeClient = disposeClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<T> CreateAsync<T>(T obj, CancellationToken cancel = default)
|
public async Task<T> CreateAsync<T>(T obj, CancellationToken cancel = default)
|
||||||
@@ -151,7 +153,10 @@ namespace k8s
|
|||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
kubernetes.Dispose();
|
if (disposeClient)
|
||||||
|
{
|
||||||
|
kubernetes.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user