{"id":24486843,"url":"https://github.com/neuroglia-io/k8s","last_synced_at":"2025-04-13T20:46:16.260Z","repository":{"id":132549352,"uuid":"303406093","full_name":"neuroglia-io/K8s","owner":"neuroglia-io","description":".NET Standard 2.1 library that provides abstractions and default implementations to manage Kubernetes Custom Resource Definitions thanks to an IKubernetes client","archived":false,"fork":false,"pushed_at":"2021-05-27T12:54:39.000Z","size":178,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T20:46:08.390Z","etag":null,"topics":["crd","dotnet","k8s","kubernetes"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neuroglia-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-12T13:47:22.000Z","updated_at":"2022-12-24T07:23:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"23a79081-a00a-45c6-827b-d4ef5aed9fd7","html_url":"https://github.com/neuroglia-io/K8s","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuroglia-io%2FK8s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuroglia-io%2FK8s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuroglia-io%2FK8s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuroglia-io%2FK8s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neuroglia-io","download_url":"https://codeload.github.com/neuroglia-io/K8s/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782275,"owners_count":21160716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crd","dotnet","k8s","kubernetes"],"created_at":"2025-01-21T15:20:11.126Z","updated_at":"2025-04-13T20:46:16.238Z","avatar_url":"https://github.com/neuroglia-io.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Neuroglia K8s\n.NET Standard 2.1 library that provides abstractions and default implementations to manage Kubernetes Custom Resource Definitions thanks to an [IKubernetes client](https://github.com/kubernetes-client/csharp)\n\n# Usage\n\n[Nuget Package](https://www.nuget.org/packages/Neuroglia.K8s/)\n\n```\n  dotnet add package Neuroglia.K8s\n```\n\n## Sample Code\n\n### Defining a Custom Resource Definition\n\n```c#\n  //Example of a 'TEST' CRD\n  public class TestDefinition\n    : CustomResourceDefinition\n  {\n\n      public TestDefinition()\n        : base(\"k8s.neuroglia.io/v1alpha1\", \"Test\", \"tests\")\n      {\n      \n      }\n\n  }\n\n  public static class CustomResourceDefinitions\n  {\n  \n      public static TestDefinition Test = new TestDefinition();\n  \n  }\n\n```\n\n### Defining a Custom Resource\n\n```c#\n  //Example of an instance of a 'Test' CRD\n  public class Test\n    : CustomResource\u003cTestSpec, TestStatus\u003e\n  {\n  \n      public Test() \n        : base(CustomResourceDefinitions.Test)\n      {\n\n      }\n      \n      public Test(V1ObjectMeta metadata, TestSpec spec) \n        : this()\n      {\n          this.Metadata = metadata;\n          this.Spec = spec;\n      }\n  \n  }\n  \n  //The spec of the Test CRD\n  public class TestSpec\n  {\n  \n      [JsonProperty(PropertyName = \"value\")]\n      public string Value { get; set; }\n\n  }\n  \n  //The status of the Test CRD\n  public class TestStatus\n  {\n  \n      [JsonProperty(PropertyName = \"status\")]\n      public string Status { get; set; }\n  \n  }\n```\n\n### Installing the CRD on Kubernetes\n\n1. Create the CRD yaml file\n\n```yaml\napiVersion: apiextensions.k8s.io/v1beta1\nkind: CustomResourceDefinition\nmetadata:\n  name: tests.k8s.neuroglia.io #must be the concatenation of the plural and the group parameters supplied in your CRD class ({plural}.{group})\nspec:\n  group: k8s.neuroglia.io #must be the same group than provided in your CRD class, in the ApiVersion parameter ({group}/{version})\n  subresources: #add this block if your CRD uses a status, otherwise remove\n    status: {}\n  versions:\n    - name: v1alpha1 #must be the same version than provided in your CRD class, in the ApiVersion parameter ({group}/{version})\n      served: true\n      storage: true\n  scope: Namespaced #add this line if the CRD is to be namespaced, otherwise remove\n  names:\n    plural: tests #must be the same than provided in your CRD class\n    singular: test #should be the singularized version of the plural value supplied in your CRD class\n    kind: Test #must be the same than provided in your CRD class\n```\n\n2. Apply the file using kubectl\n\n```powershell\nkubectl apply -f test-crd.yaml\n```\n\n### Creating a new Custom Resource programatically ([thanks to the IKubernetes C# client](https://github.com/kubernetes-client/csharp))\n\n```c#\nvar kube = new Kubernetes(KubernetesClientConfiguration.InClusterConfig());\nvar test = await kube.CreateNamespacedCustomObjectAsync(new Test(new TestSpec() { Value = \"Hello, world!\" }), \"mynamespace\");\n```\n\nCheck whether the Custom Resource has been successfully created\n\n```powershell\nkubectl get tests -n mynamespace\n```\n\n### Creating a new Custom Resource declaratively\n\n1. Create the Custom Resource's yaml file\n\n```yaml\napiVersion: k8s.neuroglia.io/v1alpha1\nkind: Test\nmetadata:\n  name: test\nspec:\n  value: \"hello, world\"\n```\n\n2. Apply the file using kubectl\n\n```powershell\nkubectl apply -f test.yaml\n```\n\n3. Check whether the Custom Resource has been successfully created\n\n```powershell\nkubectl get tests\n```\n\n### Watching events on a Custom Resource Definition\n\n```c#\nvar logger = LoggerFactory.Create\u003cCustomResourceEventWatcher\u003cTest\u003e\u003e();\nvar kube = new Kubernetes(KubernetesClientConfiguration.InClusterConfig());\nvar crd = CustomResourceDefinitions.Test;\nvar handler = new CustomResourceEventDelegate\u003cTest\u003e((e, test) =\u003e \n{\n    switch (e)\n    {\n        case WatchEventType.Added:\n            logger.LogInformation(\"Test added\");\n            break;\n        case WatchEventType.Modified:\n            logger.LogInformation(\"Test modified\");\n            break;\n        case WatchEventType.Deleted:\n            logger.LogInformation(\"Test deleted\");\n            break;\n        case WatchEventType.Bookmark:\n            logger.LogInformation(\"Test version changed\");\n            break;\n        case WatchEventType.Error:\n            logger.LogError(\"Test error\");\n            break;\n        default:\n            throw new NotSupportedException($\"The specified watch event type '{e}' is not supported\");\n    }\n});\nvar watcher = new CustomResourceEventWatcher\u003cTest\u003e(logger, kube, crd, namespaceProperty, handler);\nawait watcher.StartAsync();\n```\n\n## Examples\n\nThere is an extensive example in the [examples directory](https://github.com/neuroglia-io/K8s/tree/master/examples)\n\n### Running the examples\n\n```powershell\ngit clone git@github.com:neuroglia-io/K8s.git\ncd K8s\\examples\\watcher\ndotnet run\n```\n\n# Contributing\n\nPlease see [CONTRIBUTING.md](https://github.com/neuroglia-io/K8s/blob/master/CONTRIBUTING.md) for instructions on how to contribute.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuroglia-io%2Fk8s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneuroglia-io%2Fk8s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuroglia-io%2Fk8s/lists"}