-
Notifications
You must be signed in to change notification settings - Fork 305
Description
Describe the bug
KubernetesClientConfiguration is mutated by the Kubernetes.Dispose() Method as the Kubernetes constructor just copies the reference to the SslCaCerts property and Kubernetes.Dispose() disposes that collection, which is actually coming from the KubernetesClientConfiguration instance.
See
| CaCerts = config.SslCaCerts; |
And
csharp/src/KubernetesClient/Kubernetes.cs
Lines 213 to 222 in f55d1fa
| // Dispose the certificates | |
| if (CaCerts is not null) | |
| { | |
| foreach (var caCert in CaCerts) | |
| { | |
| caCert.Dispose(); | |
| } | |
| CaCerts.Clear(); | |
| } |
Kubernetes C# SDK Client Version
12.1.1
Server Kubernetes Version
v1.27.3
Dotnet Runtime Version
net7
To Reproduce
- Load a
KubernetesClientConfigurationinstance which containsSslCaCertsentries - Pass that instance to the
Kubernetesconstructor - Dispose the
Kubernetesinstance - Check the
KuberenetesClientConfiguration.SSlCaCertscollection- The collection is now empty
Expected behavior
The KubernetesClientConfiguration should not be modified. Maybe expose a Dispose method on the KubernetesClientConfiguration to dispose the CaCerts.
Alternatively document explicitly that a KubernetesClientConfiguration can be used only by exactly on Kubernetes instance and must be abandoned after passing it to a single Kubernetes constructor.