Skip to content

Commit

Permalink
Add catch around Delete Service invocation (#187)
Browse files Browse the repository at this point in the history
* Delete service can through json exception if incompatible clien and server versions

* Add catch around Delete Service invocation

* remove changes to tasks.json

---------

Co-authored-by: elvilla <elvilla@microsoft.com>
Co-authored-by: Hariharan Subramanian <105889062+hsubramanianaks@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 10, 2023
1 parent 65e4e10 commit ca86744
Showing 1 changed file with 15 additions and 1 deletion.
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)
{
// 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

0 comments on commit ca86744

Please sign in to comment.