Skip to content

Commit 5e88155

Browse files
feat: Add a parameter to the GenericClient class that configures the disposal of the underlying client (#1274)
1 parent 2f29078 commit 5e88155

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/KubernetesClient/GenericClient.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,26 @@ public class GenericClient : IDisposable
1111
private readonly string group;
1212
private readonly string version;
1313
private readonly string plural;
14+
private readonly bool disposeClient;
1415

1516
[Obsolete]
1617
public GenericClient(KubernetesClientConfiguration config, string group, string version, string plural)
1718
: this(new Kubernetes(config), group, version, plural)
1819
{
1920
}
2021

21-
public GenericClient(IKubernetes kubernetes, string version, string plural)
22-
: this(kubernetes, "", version, plural)
22+
public GenericClient(IKubernetes kubernetes, string version, string plural, bool disposeClient = true)
23+
: this(kubernetes, "", version, plural, disposeClient)
2324
{
2425
}
2526

26-
public GenericClient(IKubernetes kubernetes, string group, string version, string plural)
27+
public GenericClient(IKubernetes kubernetes, string group, string version, string plural, bool disposeClient = true)
2728
{
2829
this.group = group;
2930
this.version = version;
3031
this.plural = plural;
3132
this.kubernetes = kubernetes;
33+
this.disposeClient = disposeClient;
3234
}
3335

3436
public async Task<T> CreateAsync<T>(T obj, CancellationToken cancel = default)
@@ -151,7 +153,10 @@ public void Dispose()
151153

152154
protected virtual void Dispose(bool disposing)
153155
{
154-
kubernetes.Dispose();
156+
if (disposeClient)
157+
{
158+
kubernetes.Dispose();
159+
}
155160
}
156161
}
157162
}

0 commit comments

Comments
 (0)