Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add catch around Delete Service invocation #187

Merged
merged 5 commits into from
Mar 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/common/Kubernetes/KubernetesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Net.Sockets;
using System.Net.WebSockets;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using k8s;
Expand Down Expand Up @@ -398,8 +399,21 @@ await RestClient.CoreV1.ListServiceForAllNamespacesAsync(labelSelector: labelSel
}
catch (HttpOperationException e) when (e.Response.StatusCode == HttpStatusCode.Conflict)
{
await RestClient.CoreV1.DeleteNamespacedServiceAsync(service.Metadata.Name, namespaceName);
try
{
_log.Warning("Initial CreateNamespacedServiceAsync failed, deleting namespace");
await RestClient.CoreV1.DeleteNamespacedServiceAsync(service.Metadata.Name, namespaceName);
}
catch (JsonException ex)
elenavillamil marked this conversation as resolved.
Show resolved Hide resolved
{
// Delete service can through Json error when kubernetes server and client version are incompatible:
// 1.21 and 1.22 DeleteService returns v1.Status (6.0 client sdk)
// while in 1.23, DeleteService returns v1.Service (7.0+ client sdk)
// more details on this issue: https://github.com/kubernetes-client/csharp/issues/824
_log.Exception(ex);
}
return await RestClient.CoreV1.CreateNamespacedServiceAsync(service, namespaceName, cancellationToken: cancellationToken);

}
}, nameof(CreateOrReplaceV1ServiceAsync), cancellationToken);
}
Expand Down