2021-09-04 22:16:17 -03:00
|
|
|
#include <config/kube_config.h>
|
|
|
|
|
#include <api/CoreV1API.h>
|
2020-03-19 09:56:19 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2020-03-20 22:13:28 +08:00
|
|
|
void list_pod(apiClient_t * apiClient)
|
2020-03-19 09:56:19 +08:00
|
|
|
{
|
|
|
|
|
v1_pod_list_t *pod_list = NULL;
|
2020-03-20 22:13:28 +08:00
|
|
|
pod_list = CoreV1API_listNamespacedPod(apiClient, "default", /*namespace */
|
|
|
|
|
NULL, /* pretty */
|
|
|
|
|
0, /* allowWatchBookmarks */
|
|
|
|
|
NULL, /* continue */
|
|
|
|
|
NULL, /* fieldSelector */
|
|
|
|
|
NULL, /* labelSelector */
|
|
|
|
|
0, /* limit */
|
|
|
|
|
NULL, /* resourceVersion */
|
2021-09-15 14:23:19 +08:00
|
|
|
NULL, /* resourceVersionMatch */
|
2020-03-20 22:13:28 +08:00
|
|
|
0, /* timeoutSeconds */
|
|
|
|
|
0 /* watch */
|
|
|
|
|
);
|
2020-04-05 19:34:24 +08:00
|
|
|
printf("The return code of HTTP request=%ld\n", apiClient->response_code);
|
2020-03-20 22:13:28 +08:00
|
|
|
if (pod_list) {
|
2020-04-05 19:34:24 +08:00
|
|
|
printf("Get pod list:\n");
|
2020-03-19 09:56:19 +08:00
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
v1_pod_t *pod = NULL;
|
2020-03-20 22:13:28 +08:00
|
|
|
list_ForEach(listEntry, pod_list->items) {
|
2020-03-19 09:56:19 +08:00
|
|
|
pod = listEntry->data;
|
2020-04-05 19:34:24 +08:00
|
|
|
printf("\tThe pod name: %s\n", pod->metadata->name);
|
2020-03-19 09:56:19 +08:00
|
|
|
}
|
2020-06-01 12:00:58 +00:00
|
|
|
v1_pod_list_free(pod_list);
|
|
|
|
|
pod_list = NULL;
|
2020-03-20 22:13:28 +08:00
|
|
|
} else {
|
2020-04-05 19:34:24 +08:00
|
|
|
printf("Cannot get any pod.\n");
|
2020-03-19 09:56:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 21:00:43 -03:00
|
|
|
int main()
|
2020-03-19 09:56:19 +08:00
|
|
|
{
|
2020-06-28 12:24:08 +08:00
|
|
|
char *basePath = NULL;
|
2020-04-05 19:34:24 +08:00
|
|
|
sslConfig_t *sslConfig = NULL;
|
|
|
|
|
list_t *apiKeys = NULL;
|
2020-06-28 12:24:08 +08:00
|
|
|
int rc = load_kube_config(&basePath, &sslConfig, &apiKeys, NULL); /* NULL means loading configuration from $HOME/.kube/config */
|
|
|
|
|
if (rc != 0) {
|
2020-04-05 19:34:24 +08:00
|
|
|
printf("Cannot load kubernetes configuration.\n");
|
|
|
|
|
return -1;
|
2020-03-19 09:56:19 +08:00
|
|
|
}
|
2020-06-28 12:24:08 +08:00
|
|
|
apiClient_t *apiClient = apiClient_create_with_base_path(basePath, sslConfig, apiKeys);
|
|
|
|
|
if (!apiClient) {
|
|
|
|
|
printf("Cannot create a kubernetes client.\n");
|
|
|
|
|
return -1;
|
2020-03-19 09:56:19 +08:00
|
|
|
}
|
|
|
|
|
|
2020-06-28 12:24:08 +08:00
|
|
|
list_pod(apiClient);
|
|
|
|
|
|
|
|
|
|
apiClient_free(apiClient);
|
|
|
|
|
apiClient = NULL;
|
|
|
|
|
free_client_config(basePath, sslConfig, apiKeys);
|
|
|
|
|
basePath = NULL;
|
2020-04-05 19:34:24 +08:00
|
|
|
sslConfig = NULL;
|
|
|
|
|
apiKeys = NULL;
|
2020-10-27 20:33:38 +08:00
|
|
|
apiClient_unsetupGlobalEnv();
|
2020-03-19 09:56:19 +08:00
|
|
|
|
2020-06-28 12:24:08 +08:00
|
|
|
return 0;
|
2020-03-19 09:56:19 +08:00
|
|
|
}
|