Skip to content

Commit bf995e5

Browse files
brendandburnsk8s-ci-robot
authored andcommitted
Improve README.md with better example and descriptions. (#250)
* Improve README.md with better example and descriptions. * Address comments.
1 parent 8eb33b3 commit bf995e5

File tree

1 file changed

+75
-16
lines changed

1 file changed

+75
-16
lines changed

README.md

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,68 @@
1010
dotnet add package KubernetesClient
1111
```
1212

13-
# Generating the Client Code
13+
# Usage
1414

15-
## Prerequisites
15+
## Authentication/Configuration
16+
You should be able to use an standard KubeConfig file with this library,
17+
see the `BuildConfigFromConfigFile` function below. Most authentication
18+
methods are currently supported, but a few are not, see the
19+
[known-issues](https://github.com/kubernetes-client/csharp#known-issues)
1620

17-
You'll need a Linux machine with Docker.
21+
You should also be able to authenticate using the in-cluster service
22+
account using the `InClusterConfig` function shown below.
1823

19-
The generated code works on all platforms supported by .NET or .NET Core.
24+
## Sample Code
2025

21-
Check out the generator project into some other directory
22-
(henceforth `$GEN_DIR`)
26+
### Creating the client
27+
```c#
28+
// Load from the default kubeconfig on the machine.
29+
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
2330

24-
```bash
25-
cd $GEN_DIR/..
26-
git clone https://github.com/kubernetes-client/gen
31+
// Load from a specific file:
32+
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(Environment.GetEnvironmentVariable("KUBECONFIG"));
33+
34+
// Load from in-cluster configuration:
35+
var config = KubernetesClientConfiguration.InClusterConfig()
36+
37+
// Use the config object to create a client.
38+
var client = new Kubernetes(config);
2739
```
2840

29-
## Generating code
41+
### Listing Objects
42+
```c#
43+
var namespaces = client.ListNamespace();
44+
foreach (var ns in namespaces.Items) {
45+
Console.WriteLine(ns.Metadata.Name);
46+
var list = client.ListNamespacedPod(ns.Metadata.Name);
47+
foreach (var item in list.Items)
48+
{
49+
Console.WriteLine(item.Metadata.Name);
50+
}
51+
}
52+
```
3053

31-
```bash
32-
# Where REPO_DIR points to the root of the csharp repository
33-
cd ${REPO_DIR}/csharp/src/KubernetesClient
34-
${GEN_DIR}/openapi/csharp.sh generated ../csharp.settings
54+
### Creating and Deleting Objects
55+
```c#
56+
var ns = new V1Namespace
57+
{
58+
Metadata = new V1ObjectMeta
59+
{
60+
Name = "test"
61+
}
62+
};
63+
64+
var result = client.CreateNamespace(ns);
65+
Console.WriteLine(result);
66+
67+
var status = client.DeleteNamespace(ns.Metadata.Name, new V1DeleteOptions());
3568
```
3669

37-
# Usage
70+
## Examples
71+
72+
There is extensive example code in the [examples directory](https://github.com/kubernetes-client/csharp/tree/master/examples).
3873

39-
## Running the Examples
74+
### Running the Examples
4075

4176
```bash
4277
git clone [email protected]:kubernetes-client/csharp.git
@@ -80,6 +115,30 @@ dotnet restore
80115
dotnet test
81116
```
82117

118+
# Generating the Client Code
119+
120+
## Prerequisites
121+
122+
You'll need a Linux machine with Docker.
123+
124+
The generated code works on all platforms supported by .NET or .NET Core.
125+
126+
Check out the generator project into some other directory
127+
(henceforth `$GEN_DIR`)
128+
129+
```bash
130+
cd $GEN_DIR/..
131+
git clone https://github.com/kubernetes-client/gen
132+
```
133+
134+
## Generating code
135+
136+
```bash
137+
# Where REPO_DIR points to the root of the csharp repository
138+
cd ${REPO_DIR}/csharp/src/KubernetesClient
139+
${GEN_DIR}/openapi/csharp.sh generated ../csharp.settings
140+
```
141+
83142
## Contributing
84143

85144
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to contribute.

0 commit comments

Comments
 (0)