From a66596b0c275fe16396554186bcaeca9b2d578c3 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Sun, 22 Mar 2020 21:56:55 -0700 Subject: [PATCH] Improve the READMEs for the client. --- README.md | 78 +++++++++++++++++++++++++++++----- examples/create_pod/.gitignore | 1 + examples/create_pod/main.c | 7 ++- examples/list_pod/.gitignore | 1 + examples/list_pod/main.c | 7 ++- kubernetes/README.md | 18 +++++++- 6 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 examples/create_pod/.gitignore create mode 100644 examples/list_pod/.gitignore diff --git a/README.md b/README.md index ba5444f..f4f28fb 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,72 @@ -# Kubernetes Template Project +# Kubernetes Client Library for C -The Kubernetes Template Project is a template for starting new projects in the GitHub organizations owned by Kubernetes. All Kubernetes projects, at minimum, must have the following files: +This is the official Kubernetes client library for the C programming language. +It is a work in progress and should be considered _alpha_ quality software at this +time. -- a `README.md` outlining the project goals, sponsoring sig, and community contact information -- an `OWNERS` with the project leads listed as approvers ([docs on `OWNERS` files][owners]) -- a `CONTRIBUTING.md` outlining how to contribute to the project -- an unmodified copy of `code-of-conduct.md` from this repo, which outlines community behavior and the consequences of breaking the code -- a `LICENSE` which must be Apache 2.0 for code projects, or [Creative Commons 4.0] for documentation repositories, without any custom content -- a `SECURITY_CONTACTS` with the contact points for the Product Security Team - to reach out to for triaging and handling of incoming issues. They must agree to abide by the - [Embargo Policy](https://git.k8s.io/security/private-distributors-list.md#embargo-policy) - and will be removed and replaced if they violate that agreement. +## Building the library +```bash +# Clone the repo +git clone https://github.com/kubernetes-client/c +CLIENT_REPO_ROOT=${PWD}/c + +# Install pre-requisites +sudo apt-get install libcurl4-openssl-dev uncrustify + +# Move into the Kubernetes directory +cd ${CLIENT_REPO_ROOT}/kubernetes + +# Build +mkdir build +cd build +cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lib .. +make +sudo make install +``` + +## Building an example +```bash +cd ${CLIENT_REPO_ROOT}/examples/list_pod +make +``` + +## Running the example +For now, you need to use `kubectl proxy` to handle authentication. + +```bash +kubectl proxy +./list_pod_bin +``` + +## Usage example + +```c + list_t *apiKeys; + apiKeys = list_create(); + + keyValuePair_t *keyPairToken = keyValuePair_create(keyToken, valueToken); + list_addElement(apiKeys, keyPairToken); + + g_k8sAPIConnector = apiClient_create_with_base_path(K8S_APISERVER_BASEPATH, NULL, apiKeys); + + v1_pod_list_t *pod_list = NULL; + pod_list = CoreV1API_listNamespacedPod(apiClient, + "default", /*namespace */ + NULL, /* pretty */ + 0, /* allowWatchBookmarks */ + NULL, /* continue */ + NULL, /* fieldSelector */ + NULL, /* labelSelector */ + 0, /* limit */ + NULL, /* resourceVersion */ + 0, /* timeoutSeconds */ + 0 /* watch */ + ); + printf("return code=%ld\n", apiClient->response_code); + if (pod_list) { + ... + } +``` ## Community, discussion, contribution, and support diff --git a/examples/create_pod/.gitignore b/examples/create_pod/.gitignore new file mode 100644 index 0000000..85b2da0 --- /dev/null +++ b/examples/create_pod/.gitignore @@ -0,0 +1 @@ +create_pod_bin diff --git a/examples/create_pod/main.c b/examples/create_pod/main.c index 6795bcb..8242c03 100644 --- a/examples/create_pod/main.c +++ b/examples/create_pod/main.c @@ -4,7 +4,12 @@ #include #include -#define K8S_APISERVER_BASEPATH "https://your.server.here" +// kubectl proxy server +#define K8S_APISERVER_BASEPATH "http://localhost:8001" + +// Alternately from within a Kubernetes cluster: +// #define K8S_APISERVER_BASEPATH https://your.server.here + #define K8S_TOKEN_FILE_IN_CLUSTER "/var/run/secrets/kubernetes.io/serviceaccount/token" #define K8S_TOKEN_BUF_SIZE 1024 #define K8S_AUTH_KEY "Authorization" diff --git a/examples/list_pod/.gitignore b/examples/list_pod/.gitignore new file mode 100644 index 0000000..919c641 --- /dev/null +++ b/examples/list_pod/.gitignore @@ -0,0 +1 @@ +list_pod_bin diff --git a/examples/list_pod/main.c b/examples/list_pod/main.c index de53111..9693a86 100644 --- a/examples/list_pod/main.c +++ b/examples/list_pod/main.c @@ -4,7 +4,12 @@ #include #include -#define K8S_APISERVER_BASEPATH "https://your.server.here" +// kubectl proxy server +#define K8S_APISERVER_BASEPATH "http://localhost:8001" + +// Alternately from within a Kubernetes cluster: +// #define K8S_APISERVER_BASEPATH https://your.server.here + #define K8S_TOKEN_FILE_IN_CLUSTER "/var/run/secrets/kubernetes.io/serviceaccount/token" #define K8S_TOKEN_BUF_SIZE 1024 #define K8S_AUTH_KEY "Authorization" diff --git a/kubernetes/README.md b/kubernetes/README.md index c60435d..01468ce 100644 --- a/kubernetes/README.md +++ b/kubernetes/README.md @@ -12,7 +12,14 @@ You'll need the `curl 7.58.0` package in order to build the API. To have code fo # Prerequisites -## Install the `curl 7.58.0` package with the following command on Linux. +## Install the `curl 7.58.0` + +### Install from package +```bash +sudo apt-get install libcurl4-openssl-dev +``` + +### Command line instructions ```bash sudo apt remove curl wget http://curl.haxx.se/download/curl-7.58.0.tar.gz @@ -22,7 +29,14 @@ cd curl-7.58.0/ make sudo make install ``` -## Install the `uncrustify 0.67` package with the following command on Linux. +## Install the `uncrustify 0.67` + +### Install using a package manager +```bash +sudo apt-get install uncrustify +``` + +### Command line instructions ```bash git clone https://github.com/uncrustify/uncrustify.git cd uncrustify