Skip to content

Commit

Permalink
Add Gateway API delete func
Browse files Browse the repository at this point in the history
  • Loading branch information
weibaohui committed Jul 12, 2024
1 parent b185889 commit 80b2c6b
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 34 deletions.
7 changes: 4 additions & 3 deletions BlazorApp/Service/k8s/impl/BackendLBPolicyService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Entity.Crd.Gateway;
using k8s;

namespace BlazorApp.Service.k8s.impl;

Expand All @@ -8,7 +9,7 @@ public class BackendLBPolicyService(IKubeService kubeService)
{
public new async Task<object> Delete(string ns, string name)
{
return Task.CompletedTask;
// return await kubeService.Client().DeleteNamespacedBackendLBPolicyAsync(name, ns);
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha2", ns, "backendlbpolicies", name);
}
}
}
8 changes: 4 additions & 4 deletions BlazorApp/Service/k8s/impl/BackendTLSPolicyService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Entity.Crd.Gateway;
using k8s;

namespace BlazorApp.Service.k8s.impl;

Expand All @@ -8,8 +9,7 @@ public class BackendTLSPolicyService(IKubeService kubeService)
{
public new async Task<object> Delete(string ns, string name)
{
return Task.CompletedTask;

// return await kubeService.Client().DeleteNamespacedBackendTLSPolicyAsync(name, ns);
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha3", ns, "backendtlspolicies", name);
}
}
}
8 changes: 4 additions & 4 deletions BlazorApp/Service/k8s/impl/GatewayClassService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Threading.Tasks;
using Entity.Crd.Gateway;
using k8s;

namespace BlazorApp.Service.k8s.impl;

public class GatewayClassService(IKubeService kubeService) : CommonAction<V1GatewayClass>, IGatewayClassService
{
public new async Task<object> Delete(string ns, string name)
{
return Task.CompletedTask;

// return await kubeService.Client().DeleteNamespacedGatewayClassAsync(name, ns);
return await kubeService.Client().CustomObjects
.DeleteClusterCustomObjectAsync("gateway.networking.k8s.io", "v1", "gatewayclasses", name);
}
}
}
6 changes: 3 additions & 3 deletions BlazorApp/Service/k8s/impl/GatewayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using Entity.Crd.Gateway;
using k8s;
using k8s.Models;

namespace BlazorApp.Service.k8s.impl;
Expand All @@ -10,9 +11,8 @@ public class GatewayService(IKubeService kubeService) : CommonAction<V1Gateway>,
{
public new async Task<object> Delete(string ns, string name)
{
return Task.CompletedTask;

// return await kubeService.Client().DeleteNamespacedGatewayAsync(name, ns);
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1", ns, "gateways", name);
}

public IList<V1Gateway> ListByParentRefs(IList<ParentReference> parentRefs)
Expand Down
6 changes: 3 additions & 3 deletions BlazorApp/Service/k8s/impl/GrpcRouteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using Entity.Crd.Gateway;
using k8s;
using k8s.Models;

namespace BlazorApp.Service.k8s.impl;
Expand All @@ -10,9 +11,8 @@ public class GrpcRouteService(IKubeService kubeService) : CommonAction<V1GRPCRou
{
public new async Task<object> Delete(string ns, string name)
{
return Task.CompletedTask;

// return await kubeService.Client().DeleteNamespacedGrpcRouteAsync(name, ns);
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1", ns, "grpcroutes", name);
}

public IList<V1GRPCRoute> ListByServiceList(List<V1Service> services)
Expand Down
6 changes: 3 additions & 3 deletions BlazorApp/Service/k8s/impl/HttpRouteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using Entity.Crd.Gateway;
using k8s;
using k8s.Models;

namespace BlazorApp.Service.k8s.impl;
Expand All @@ -10,9 +11,8 @@ public class HttpRouteService(IKubeService kubeService) : CommonAction<V1HTTPRou
{
public new async Task<object> Delete(string ns, string name)
{
return Task.CompletedTask;

// return await kubeService.Client().DeleteNamespacedHttpRouteAsync(name, ns);
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1", ns, "httproutes", name);
}

public IList<V1HTTPRoute> ListByServiceList(List<V1Service> services)
Expand Down
8 changes: 4 additions & 4 deletions BlazorApp/Service/k8s/impl/ReferenceGrantService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Entity.Crd.Gateway;
using k8s;

namespace BlazorApp.Service.k8s.impl;

Expand All @@ -8,8 +9,7 @@ public class ReferenceGrantService(IKubeService kubeService)
{
public new async Task<object> Delete(string ns, string name)
{
return Task.CompletedTask;

// return await kubeService.Client().DeleteNamespacedReferenceGrantAsync(name, ns);
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha2", ns, "referencegrants", name);
}
}
}
70 changes: 70 additions & 0 deletions BlazorApp/Service/k8s/impl/ResourceCrudService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,80 @@ public Task<object> DeleteItem(string kind, string ns, string name)
"ClusterRoleBinding" => OnClusterRoleBindingDelete(ns, name),
"RoleBinding" => OnRoleBindingDelete(ns, name),
"CustomResourceDefinition" => OnCustomResourceDefinitionDelete(ns, name),
"GatewayClass" => OnGatewayClassDelete(ns, name),
"Gateway" => OnGatewayDelete(ns, name),
"HTTPRoute" => OnHttpRouteDelete(ns, name),
"TLSRoute" => OnTlsRouteDelete(ns, name),
"GRPCRoute" => OnGrpcRouteDelete(ns, name),
"UDPRoute" => OnUdpRouteDelete(ns, name),
"TCPRoute" => OnTcpRouteDelete(ns, name),
"ReferenceGrant" => OnReferenceGrantDelete(ns, name),
"BackendTLSPolicy" => OnBackendTlsPolicyDelete(ns, name),
"BackendLBPolicy" => OnBackendLbPolicyDelete(ns, name),
_ => OnXDelete(kind, ns, name)
});
}

private async Task<object> OnBackendLbPolicyDelete(string ns, string name)
{
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha2", ns, "backendlbpolicies", name);
}

private async Task<object> OnBackendTlsPolicyDelete(string ns, string name)
{
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha3", ns, "backendtlspolicies", name);
}

private async Task<object> OnReferenceGrantDelete(string ns, string name)
{
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha2", ns, "referencegrants", name);
}

private async Task<object> OnTcpRouteDelete(string ns, string name)
{
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha2", ns, "tcproutes", name);
}

private async Task<object> OnUdpRouteDelete(string ns, string name)
{
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha2", ns, "udproutes", name);
}

private async Task<object> OnGrpcRouteDelete(string ns, string name)
{
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1", ns, "grpcroutes", name);
}

private async Task<object> OnTlsRouteDelete(string ns, string name)
{
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha2", ns, "tlsroutes", name);
}

private async Task<object> OnHttpRouteDelete(string ns, string name)
{
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1", ns, "httproutes", name);
}

private async Task<object> OnGatewayDelete(string ns, string name)
{
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1", ns, "gateways", name);
}

private async Task<object> OnGatewayClassDelete(string ns, string name)
{
return await kubeService.Client().CustomObjects
.DeleteClusterCustomObjectAsync("gateway.networking.k8s.io", "v1", "gatewayclasses", name);
}

private async Task<V1PersistentVolumeClaim> OnPersistentVolumeClaimDelete(string ns, string name)
{
return await kubeService.Client().DeleteNamespacedPersistentVolumeClaimAsync(name, ns);
Expand Down
6 changes: 3 additions & 3 deletions BlazorApp/Service/k8s/impl/TcpRouteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using Entity.Crd.Gateway;
using k8s;
using k8s.Models;

namespace BlazorApp.Service.k8s.impl;
Expand All @@ -10,9 +11,8 @@ public class TcpRouteService(IKubeService kubeService) : CommonAction<V1Alpha2TC
{
public new async Task<object> Delete(string ns, string name)
{
return Task.CompletedTask;

// return await kubeService.Client().DeleteNamespacedTcpRouteAsync(name, ns);
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha2", ns, "tcproutes", name);
}

public IList<V1Alpha2TCPRoute> ListByServiceList(List<V1Service> services)
Expand Down
8 changes: 4 additions & 4 deletions BlazorApp/Service/k8s/impl/TlsRouteService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Threading.Tasks;
using Entity.Crd.Gateway;
using k8s;

namespace BlazorApp.Service.k8s.impl;

public class TlsRouteService(IKubeService kubeService) : CommonAction<V1Alpha2TLSRoute>, ITlsRouteService
{
public new async Task<object> Delete(string ns, string name)
{
return Task.CompletedTask;

// return await kubeService.Client().DeleteNamespacedTlsRouteAsync(name, ns);
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha2", ns, "tlsroutes", name);
}
}
}
6 changes: 3 additions & 3 deletions BlazorApp/Service/k8s/impl/UdpRouteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using Entity.Crd.Gateway;
using k8s;
using k8s.Models;

namespace BlazorApp.Service.k8s.impl;
Expand All @@ -10,9 +11,8 @@ public class UdpRouteService(IKubeService kubeService) : CommonAction<V1Alpha2UD
{
public new async Task<object> Delete(string ns, string name)
{
return Task.CompletedTask;

// return await kubeService.Client().DeleteNamespacedUdpRouteAsync(name, ns);
return await kubeService.Client().CustomObjects
.DeleteNamespacedCustomObjectAsync("gateway.networking.k8s.io", "v1alpha2", ns, "udproutes", name);
}

public IList<V1Alpha2UDPRoute> ListByServiceList(List<V1Service> services)
Expand Down

0 comments on commit 80b2c6b

Please sign in to comment.