Skip to content

Commit 507be06

Browse files
committed
Add a fluent Kubernetes API
1 parent cf00214 commit 507be06

File tree

3 files changed

+926
-0
lines changed

3 files changed

+926
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Net.Http;
3+
4+
namespace k8s
5+
{
6+
public partial class Kubernetes
7+
{
8+
/// <summary>Creates a new <see cref="KubernetesRequest"/> using the given <see cref="HttpMethod"/>
9+
/// (<see cref="HttpMethod.Get"/> by default).
10+
/// </summary>
11+
public KubernetesRequest New(HttpMethod method = null) => new KubernetesRequest(this).Method(method);
12+
13+
/// <summary>Creates a new <see cref="KubernetesRequest"/> using the given <see cref="HttpMethod"/>
14+
/// and resource URI components.
15+
/// </summary>
16+
public KubernetesRequest New(
17+
HttpMethod method, string type = null, string ns = null, string name = null, string group = null, string version = null) =>
18+
new KubernetesRequest(this).Method(method).Group(group).Version(version).Type(type).Namespace(ns).Name(name);
19+
20+
/// <summary>Creates a new <see cref="KubernetesRequest"/> to access the given type of object.</summary>
21+
public KubernetesRequest New(Type type) => new KubernetesRequest(this).GVK(type);
22+
23+
/// <summary>Creates a new <see cref="KubernetesRequest"/> to access the given type of object with an optional name and namespace.</summary>
24+
public KubernetesRequest New(HttpMethod method, Type type, string ns = null, string name = null) =>
25+
New(method).GVK(type).Namespace(ns).Name(name);
26+
27+
/// <summary>Creates a new <see cref="KubernetesRequest"/> to access the given type of object with an optional name and namespace.</summary>
28+
public KubernetesRequest New<T>(string ns = null, string name = null) => New(null, typeof(T), ns, name);
29+
30+
/// <summary>Creates a new <see cref="KubernetesRequest"/> to access the given type of object with an optional name and namespace.</summary>
31+
public KubernetesRequest New<T>(HttpMethod method, string ns = null, string name = null) =>
32+
New(method, typeof(T), ns, name);
33+
34+
/// <summary>Creates a new <see cref="KubernetesRequest"/> to access the given object.</summary>
35+
public KubernetesRequest New(IKubernetesObject obj, bool setBody = true) => new KubernetesRequest(this).Set(obj, setBody);
36+
37+
/// <summary>Creates a new <see cref="KubernetesRequest"/> to access the given object.</summary>
38+
public KubernetesRequest New(HttpMethod method, IKubernetesObject obj, bool setBody = true) => New(method).Set(obj, setBody);
39+
}
40+
}

0 commit comments

Comments
 (0)