{"id":20207900,"url":"https://github.com/kubernetes-client/c","last_synced_at":"2025-04-09T13:07:06.939Z","repository":{"id":37791201,"uuid":"247958425","full_name":"kubernetes-client/c","owner":"kubernetes-client","description":"Official C client library for Kubernetes","archived":false,"fork":false,"pushed_at":"2024-09-13T14:05:13.000Z","size":8657,"stargazers_count":146,"open_issues_count":3,"forks_count":46,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-10-02T09:04:50.520Z","etag":null,"topics":["client-library","kubernetes"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kubernetes-client.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY_CONTACTS","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-17T11:59:05.000Z","updated_at":"2024-09-13T14:05:24.000Z","dependencies_parsed_at":"2023-02-10T11:15:41.635Z","dependency_job_id":"99da0827-9424-4497-96d3-52d4b4f6b0d4","html_url":"https://github.com/kubernetes-client/c","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":"kubernetes/kubernetes-template-project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubernetes-client%2Fc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubernetes-client%2Fc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubernetes-client%2Fc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubernetes-client%2Fc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kubernetes-client","download_url":"https://codeload.github.com/kubernetes-client/c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248045231,"owners_count":21038553,"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":["client-library","kubernetes"],"created_at":"2024-11-14T05:33:11.153Z","updated_at":"2025-04-09T13:07:06.920Z","avatar_url":"https://github.com/kubernetes-client.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# Kubernetes Client Library for C\n\n[![Client Capabilities](https://img.shields.io/badge/Kubernetes%20client-Silver-blue.svg?style=flat\u0026colorB=C0C0C0\u0026colorA=306CE8)](https://github.com/kubernetes/design-proposals-archive/blob/main/api-machinery/csi-new-client-library-procedure.md#client-capabilities)\n[![Client Support Level](https://img.shields.io/badge/kubernetes%20client-beta-green.svg?style=flat\u0026colorA=306CE8)](https://github.com/kubernetes/design-proposals-archive/blob/main/api-machinery/csi-new-client-library-procedure.md#client-support-level)\n[![Code Check](https://github.com/kubernetes-client/c/workflows/Code%20Check/badge.svg)](https://github.com/kubernetes-client/c/actions?query=workflow%3A%22Code+Check%22)\n[![Build](https://github.com/kubernetes-client/c/workflows/Build/badge.svg)](https://github.com/kubernetes-client/c/actions?query=workflow%3ABuild)\n\nThis is the official Kubernetes client library for the C programming language.\n\n## Building the library\n```bash\n# Clone the repo\ngit clone https://github.com/kubernetes-client/c\nCLIENT_REPO_ROOT=${PWD}/c\n\n# Install pre-requisites\nsudo apt-get install libssl-dev libcurl4-openssl-dev libwebsockets-dev uncrustify\n\n# Build pre-requisite: libyaml\ngit clone https://github.com/yaml/libyaml --depth 1 --branch release/0.2.5\ncd libyaml\nmkdir build\ncd build\ncmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_TESTING=OFF  -DBUILD_SHARED_LIBS=ON ..\nmake\nsudo make install\n\n# Move into the Kubernetes directory\ncd ${CLIENT_REPO_ROOT}/kubernetes\n\n# Build\nmkdir build\ncd build\n# If you don't need to debug the C client library:\ncmake -DCMAKE_INSTALL_PREFIX=/usr/local ..\n# If you want to use `gdb` to debug the C client library, add `-DCMAKE_BUILD_TYPE=Debug` to the cmake command line, e.g.\n# cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local ..\nmake\nsudo make install\n```\n\n## (Optional) Installing using vcpkg on Windows\nIf you want to install the C client using vcpkg, please refer to [vcpkg.md](https://github.com/kubernetes-client/c/blob/master/docs/vcpkg.md)\n\n## (Optional) Installing using conan on Windows, Linux, Mac\nIf you want to install the C client using conan, please refer to [conan.md](https://github.com/kubernetes-client/c/blob/master/docs/conan.md)\n\n## Building an example\n```bash\ncd ${CLIENT_REPO_ROOT}/examples/list_pod\nmake\n```\n\n## Running the example\n```bash\n./list_pod_bin\n```\n\n## Usage example\n\nlist all pods:\n\n```c\n    char *basePath = NULL;\n    sslConfig_t *sslConfig = NULL;\n    list_t *apiKeys = NULL;\n    int rc = load_kube_config(\u0026basePath, \u0026sslConfig, \u0026apiKeys, NULL);/* NULL means loading configuration from $HOME/.kube/config */\n    if (rc != 0) {\n        printf(\"Cannot load kubernetes configuration.\\n\");\n        return -1;\n    }\n    apiClient_t *apiClient = apiClient_create_with_base_path(basePath, sslConfig, apiKeys);\n    if (!apiClient) {\n        printf(\"Cannot create a kubernetes client.\\n\");\n        return -1;\n    }\n\n    v1_pod_list_t *pod_list = NULL;\n    pod_list = CoreV1API_listNamespacedPod(apiClient,\n                                          \"default\",    /*namespace */\n                                           NULL,    /* pretty */\n                                           NULL,    /* allowWatchBookmarks */\n                                           NULL,    /* continue */\n                                           NULL,    /* fieldSelector */\n                                           NULL,    /* labelSelector */\n                                           NULL,    /* limit */\n                                           NULL,    /* resourceVersion */\n                                           NULL,    /* resourceVersionMatch */\n                                           NULL,    /* sendInitialEvents */\n                                           NULL,    /* timeoutSeconds */\n                                           NULL     /* watch */\n        );\n    printf(\"return code=%ld\\n\", apiClient-\u003eresponse_code);\n    if (pod_list) {\n      ...\n    }\n\n    apiClient_free(apiClient);\n    apiClient = NULL;\n    free_client_config(basePath, sslConfig, apiKeys);\n    basePath = NULL;\n    sslConfig = NULL;\n    apiKeys = NULL;\n    apiClient_unsetupGlobalEnv();\n```\n\nlist all pods in cluster:\n\n```c\n    char *basePath = NULL;\n    sslConfig_t *sslConfig = NULL;\n    list_t *apiKeys = NULL;\n    int rc = load_incluster_config(\u0026basePath, \u0026sslConfig, \u0026apiKeys);\n    if (rc != 0) {\n        printf(\"Cannot load kubernetes configuration in cluster.\\n\");\n        return -1;\n    }\n    apiClient_t *apiClient = apiClient_create_with_base_path(basePath, sslConfig, apiKeys);\n    if (!apiClient) {\n        printf(\"Cannot create a kubernetes client.\\n\");\n        return -1;\n    }\n\n    v1_pod_list_t *pod_list = NULL;\n    pod_list = CoreV1API_listNamespacedPod(apiClient,\n                                          \"default\",    /*namespace */\n                                           NULL,    /* pretty */\n                                           NULL,    /* allowWatchBookmarks */\n                                           NULL,    /* continue */\n                                           NULL,    /* fieldSelector */\n                                           NULL,    /* labelSelector */\n                                           NULL,    /* limit */\n                                           NULL,    /* resourceVersion */\n                                           NULL,    /* resourceVersionMatch */\n                                           NULL,    /* sendInitialEvents */\n                                           NULL,    /* timeoutSeconds */\n                                           NULL     /* watch */\n        );\n    printf(\"return code=%ld\\n\", apiClient-\u003eresponse_code);\n    if (pod_list) {\n      ...\n    }\n\n    apiClient_free(apiClient);\n    apiClient = NULL;\n    free_client_config(basePath, sslConfig, apiKeys);\n    basePath = NULL;\n    sslConfig = NULL;\n    apiKeys = NULL;\n    apiClient_unsetupGlobalEnv();\n```\n\n## How to send integer or boolean parameters to API Server\n\nIf you want to send an integer or boolean parameter to the API server, you will see that the data type in API function is `int *`, e.g.\n\n```c\n// list or watch objects of kind Pod\n//\nv1_pod_list_t* CoreV1API_listNamespacedPod(apiClient_t *apiClient, \n                                           char *_namespace, \n                                           char *pretty, \n                                           int *allowWatchBookmarks, /* \u003c-- here */\n                                           char *_continue, \n                                           char *fieldSelector, \n                                           char *labelSelector, \n                                           int *limit,               /* \u003c-- here */\n                                           char *resourceVersion, \n                                           char *resourceVersionMatch, \n                                           int *sendInitialEvents,   /* \u003c-- here */\n                                           int *timeoutSeconds,      /* \u003c-- here */\n                                           int *watch);              /* \u003c-- here */\n```\n\nFor example we can send `timeoutSeconds` and `watch` using the following usage:\n\n```c\nint timeoutSeconds = 30;\nint watch = 1;\npod_list = CoreV1API_listNamespacedPod(apiClient, \"default\",    /*namespace */\n                                       NULL,    /* pretty */\n                                       NULL,    /* allowWatchBookmarks */\n                                       NULL,    /* continue */\n                                       NULL,    /* fieldSelector */\n                                       NULL,    /* labelSelector */\n                                       NULL,    /* limit */\n                                       NULL,    /* resourceVersion */\n                                       NULL,    /* resourceVersionMatch */\n                                       NULL,    /* sendInitialEvents */\n                                       \u0026timeoutSeconds,    /* timeoutSeconds */\n                                       \u0026watch   /* watch */\n);\n```\n\nSetting the parameter to `NULL` means not to send the parameter to the API Server, and the API Server will use the default value for this parameter.\n\n## Aggregated APIs and CRD-based APIs\n\nIf you want to implement a client for aggregated APIs (such as the metrics server API `apis/metrics.k8s.io` ) or CRD-based APIs, use the [generic client](./kubernetes/src/generic.c). See [example](./examples/generic/main.c).\n\n## Multi-threaded Usage\n\nIf the C client library is used in multi-threaded program, the following 2 actions are required:\n\n1. After the program starts up, main thread must call the function ```apiClient_setupGlobalEnv()``` before any worker thread is created.\n\n2. If the C client is no longer used, main thread must call the function ```apiClient_unsetupGlobalEnv()``` after all worker threads end.\n\nRefer to the [example](https://github.com/kubernetes-client/c/tree/master/examples/multi_thread/) for detail. \n\n## Documentation\n\nAll APIs and Models' documentation can be found at the [Generated client's README file](https://github.com/kubernetes-client/c/blob/master/kubernetes/README.md#documentation-for-api-endpoints)\n\n## Versions and Compatibility\n\nSee [versioning-and-compatibility.md](./docs/versioning-and-compatibility.md)\n\n## Community, discussion, contribution, and support\n\nLearn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).\n\nYou can reach the maintainers of this project at:\n\n- [Slack](http://slack.k8s.io/)\n- [Mailing List](https://groups.google.com/a/kubernetes.io/g/dev)\n\n### Code of conduct\n\nParticipation in the Kubernetes community is governed by the [Kubernetes Code of Conduct](code-of-conduct.md).\n\n[owners]: https://git.k8s.io/community/contributors/guide/owners.md\n[Creative Commons 4.0]: https://git.k8s.io/website/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubernetes-client%2Fc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkubernetes-client%2Fc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubernetes-client%2Fc/lists"}