-
Notifications
You must be signed in to change notification settings - Fork 306
Improve README.md with better example and descriptions. #250
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,33 +10,68 @@ | |
dotnet add package KubernetesClient | ||
``` | ||
|
||
# Generating the Client Code | ||
# Usage | ||
|
||
## Prerequisites | ||
## Authentication/Configuration | ||
You should be able to use an standard KubeConfig file with this library, | ||
see the `BuildConfigFromConfigFile` function below. Most authentication | ||
methods are currently supported, but a few are not, see the | ||
[known-issues](https://github.com/kubernetes-client/csharp#known-issues) | ||
|
||
You'll need a Linux machine with Docker. | ||
You should also be able to authenticate using the in-cluster service | ||
account using the `InClusterConfig` function shown below. | ||
|
||
The generated code works on all platforms supported by .NET or .NET Core. | ||
## Sample Code | ||
|
||
Check out the generator project into some other directory | ||
(henceforth `$GEN_DIR`) | ||
### Creating the client | ||
```c# | ||
// Load from the default kubeconfig on the machine. | ||
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); | ||
|
||
```bash | ||
cd $GEN_DIR/.. | ||
git clone https://github.com/kubernetes-client/gen | ||
// Load from a specific file: | ||
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(Environment.GetEnvironmentVariable("KUBECONFIG")); | ||
|
||
// Load from in-cluster configuration: | ||
var config = KubernetesClientConfiguration.InClusterConfig() | ||
|
||
// Use the config object to create a client. | ||
var client = new Kubernetes(config); | ||
``` | ||
|
||
## Generating code | ||
### Listing Objects | ||
```c# | ||
var namespaces = client.ListNamespace(); | ||
foreach (var ns in namespaces.Items) { | ||
Console.WriteLine(ns.Metadata.Name); | ||
var list = client.ListNamespacedPod(ns.Metadata.Name); | ||
foreach (var item in list.Items) | ||
{ | ||
Console.WriteLine(item.Metadata.Name); | ||
} | ||
} | ||
``` | ||
|
||
```bash | ||
# Where REPO_DIR points to the root of the csharp repository | ||
cd ${REPO_DIR}/csharp/src/KubernetesClient | ||
${GEN_DIR}/openapi/csharp.sh generated ../csharp.settings | ||
### Creating and Deleting Objects | ||
```c# | ||
var ns = new V1Namespace | ||
{ | ||
Metadata = new V1ObjectMeta | ||
{ | ||
Name = "test" | ||
} | ||
}; | ||
|
||
var result = client.CreateNamespace(ns); | ||
Console.WriteLine(result); | ||
|
||
var status = client.DeleteNamespace(ns.Metadata.Name, new V1DeleteOptions()); | ||
``` | ||
|
||
# Usage | ||
## Examples | ||
|
||
There is extensive example code in the [examples directory](https://github.com/kubernetes-client/csharp/tree/master/examples). | ||
|
||
## Running the Examples | ||
### Running the Examples | ||
|
||
```bash | ||
git clone [email protected]:kubernetes-client/csharp.git | ||
|
@@ -80,6 +115,30 @@ dotnet restore | |
dotnet test | ||
``` | ||
|
||
# Generating the Client Code | ||
|
||
## Prerequisites | ||
|
||
You'll need a Linux machine with Docker. | ||
|
||
The generated code works on all platforms supported by .NET or .NET Core. | ||
|
||
Check out the generator project into some other directory | ||
(henceforth `$GEN_DIR`) | ||
|
||
```bash | ||
cd $GEN_DIR/.. | ||
git clone https://github.com/kubernetes-client/gen | ||
``` | ||
|
||
## Generating code | ||
|
||
```bash | ||
# Where REPO_DIR points to the root of the csharp repository | ||
cd ${REPO_DIR}/csharp/src/KubernetesClient | ||
${GEN_DIR}/openapi/csharp.sh generated ../csharp.settings | ||
``` | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to contribute. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: We should prefer showing the async methods to the blocking ones. It is easy to translate in either direction of course, but we should set the expectation that async is the 'normal' way to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the examples are all sync right now. Let's do this in a separate PR.