|
| 1 | +#include <config/kube_config.h> |
| 2 | +#include <api/CoreV1API.h> |
| 3 | +#include <stdio.h> |
| 4 | + |
| 5 | +#include <config/kube_config.h> |
| 6 | +#include <api/CoreV1API.h> |
| 7 | +#include <stdio.h> |
| 8 | + |
| 9 | +void list_event(apiClient_t * apiClient) |
| 10 | +{ |
| 11 | + core_v1_event_list_t *event_list = CoreV1API_listNamespacedEvent(apiClient, "default", /*namespace */ |
| 12 | + "true", /* pretty */ |
| 13 | + 0, /* allowWatchBookmarks */ |
| 14 | + NULL, /* continue */ |
| 15 | + NULL, /* fieldSelector */ |
| 16 | + NULL, /* labelSelector */ |
| 17 | + 0, /* limit */ |
| 18 | + NULL, /* resourceVersion */ |
| 19 | + NULL, /* resourceVersionMatch */ |
| 20 | + 0, /* timeoutSeconds */ |
| 21 | + 0 /* watch */ |
| 22 | + ); |
| 23 | + printf("The return code of HTTP request=%ld\n", apiClient->response_code); |
| 24 | + if (event_list) { |
| 25 | + if (event_list->items) { |
| 26 | + listEntry_t *listEntry = NULL; |
| 27 | + core_v1_event_t *event = NULL; |
| 28 | + list_ForEach(listEntry, event_list->items) { |
| 29 | + event = listEntry->data; |
| 30 | + if (event) { |
| 31 | + if (event->type) { |
| 32 | + printf("Event Type: %s\n", event->type); |
| 33 | + } |
| 34 | + if (event->message) { |
| 35 | + printf("Event Message: %s\n", event->message); |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + } else { |
| 40 | + fprintf(stderr, "There are no events in event list.\n"); |
| 41 | + } |
| 42 | + core_v1_event_list_free(event_list); |
| 43 | + event_list = NULL; |
| 44 | + } else { |
| 45 | + fprintf(stderr, "Cannot get event list.\n"); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +int main() |
| 50 | +{ |
| 51 | + char *basePath = NULL; |
| 52 | + sslConfig_t *sslConfig = NULL; |
| 53 | + list_t *apiKeys = NULL; |
| 54 | + int rc = load_kube_config(&basePath, &sslConfig, &apiKeys, NULL); /* NULL means loading configuration from $HOME/.kube/config */ |
| 55 | + if (rc != 0) { |
| 56 | + fprintf(stderr, "Cannot load kubernetes configuration.\n"); |
| 57 | + return -1; |
| 58 | + } |
| 59 | + apiClient_t *apiClient = apiClient_create_with_base_path(basePath, sslConfig, apiKeys); |
| 60 | + if (!apiClient) { |
| 61 | + fprintf(stderr, "Cannot create a kubernetes client.\n"); |
| 62 | + return -1; |
| 63 | + } |
| 64 | + |
| 65 | + list_event(apiClient); |
| 66 | + |
| 67 | + apiClient_free(apiClient); |
| 68 | + apiClient = NULL; |
| 69 | + free_client_config(basePath, sslConfig, apiKeys); |
| 70 | + basePath = NULL; |
| 71 | + sslConfig = NULL; |
| 72 | + apiKeys = NULL; |
| 73 | + apiClient_unsetupGlobalEnv(); |
| 74 | + |
| 75 | + return 0; |
| 76 | +} |
0 commit comments