Files
csharp/examples/customResource
Boshi Lian 5de1c25cf1 migrate to record (#1665)
* migrate to record

* chore: update project files and clean up unused references

* refactor: convert classes to records and simplify constructors for IntOrString, ResourceQuantity, and V1Patch

* fix: define IsExternalInit to resolve CS0518 error in IntOrString

* refactor: change IntOrString and ResourceQuantity from records to structs, update implicit conversions, and simplify null checks

* refactor: add JsonPropertyName attribute to Value property in IntOrString struct

* refactor: simplify V1Patch constructor and improve argument validation

* refactor: remove unnecessary CultureInfo parameter in ToInt method

* Update src/KubernetesClient/Models/ResourceQuantity.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/KubernetesClient/Models/IntOrString.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Revert "Update src/KubernetesClient/Models/ResourceQuantity.cs"

This reverts commit 62b20a691554659e28d419067220dc1a0620133b.

* refactor: remove commented-out formatting check and simplify build command

* refactor: remove IValidate.cs from project references in Aot and Classic

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-22 14:20:13 -07:00
..
2025-09-22 14:20:13 -07:00
2024-06-15 21:41:28 -07:00
2023-10-28 03:43:52 +02:00
2022-05-31 07:56:53 -07:00
2020-12-19 08:26:25 -08:00

Custom Resource Client Example

This example demonstrates how to use the C# Kubernetes Client library to create, get and list custom resources.

Pre-requisits

Make sure your have added the library package

dotnet add package KubernetesClient

Create Custom Resource Definition (CRD)

Make sure the CRD is created, in order to create an instance of it after.

kubectl create -f ./config/crd.yaml

You can test that the CRD is successfully added, by creating an instance of it using kubectl:

kubectl create -f ./config/yaml-cr-instance.yaml
kubectl get customresources.csharp.com

Execute the code

The client uses the BuildConfigFromConfigFile() function. If the KUBECONFIG environment variable is set, then that path to the k8s config file will be used.

dotnet run

Expected output:

strating main()...
working with CRD: customresources.csharp.com
creating CR cr-instance-london
CR list:
- CR Item 0 = cr-instance-london
- CR Item 1 = cr-instance-paris
fetchedCR = cr-instance-london (Labels: {identifier : city, newKey : newValue}), Spec: London
Deleted the CR

Under the hood

For more details, you can look at the Generic client implementation