Skip to content

Commit

Permalink
Merge pull request kubernetes-client#210 from ityuhui/yh-intstar-1214
Browse files Browse the repository at this point in the history
Use int* as int or bool type function parameters
  • Loading branch information
k8s-ci-robot authored Dec 21, 2023
2 parents b02e6e5 + 6409031 commit 1315831
Show file tree
Hide file tree
Showing 104 changed files with 4,704 additions and 4,657 deletions.
64 changes: 54 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ list all pods:
pod_list = CoreV1API_listNamespacedPod(apiClient,
"default", /*namespace */
NULL, /* pretty */
0, /* allowWatchBookmarks */
NULL, /* allowWatchBookmarks */
NULL, /* continue */
NULL, /* fieldSelector */
NULL, /* labelSelector */
0, /* limit */
NULL, /* limit */
NULL, /* resourceVersion */
NULL, /* resourceVersionMatch */
0, /* sendInitialEvents */
0, /* timeoutSeconds */
0 /* watch */
NULL, /* sendInitialEvents */
NULL, /* timeoutSeconds */
NULL /* watch */
);
printf("return code=%ld\n", apiClient->response_code);
if (pod_list) {
Expand Down Expand Up @@ -132,16 +132,16 @@ list all pods in cluster:
pod_list = CoreV1API_listNamespacedPod(apiClient,
"default", /*namespace */
NULL, /* pretty */
0, /* allowWatchBookmarks */
NULL, /* allowWatchBookmarks */
NULL, /* continue */
NULL, /* fieldSelector */
NULL, /* labelSelector */
0, /* limit */
NULL, /* limit */
NULL, /* resourceVersion */
NULL, /* resourceVersionMatch */
0, /* sendInitialEvents */
0, /* timeoutSeconds */
0 /* watch */
NULL, /* sendInitialEvents */
NULL, /* timeoutSeconds */
NULL /* watch */
);
printf("return code=%ld\n", apiClient->response_code);
if (pod_list) {
Expand All @@ -157,6 +157,50 @@ list all pods in cluster:
apiClient_unsetupGlobalEnv();
```

## How to send integer or boolean parameters to API Server

If 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.

```c
// list or watch objects of kind Pod
//
v1_pod_list_t* CoreV1API_listNamespacedPod(apiClient_t *apiClient,
char *_namespace,
char *pretty,
int *allowWatchBookmarks, /* <-- here */
char *_continue,
char *fieldSelector,
char *labelSelector,
int *limit, /* <-- here */
char *resourceVersion,
char *resourceVersionMatch,
int *sendInitialEvents, /* <-- here */
int *timeoutSeconds, /* <-- here */
int *watch); /* <-- here */
```
For example we can send `timeoutSeconds` and `watch` using the following usage:
```c
int timeoutSeconds = 30;
int watch = 1;
pod_list = CoreV1API_listNamespacedPod(apiClient, "default", /*namespace */
NULL, /* pretty */
NULL, /* allowWatchBookmarks */
NULL, /* continue */
NULL, /* fieldSelector */
NULL, /* labelSelector */
NULL, /* limit */
NULL, /* resourceVersion */
NULL, /* resourceVersionMatch */
NULL, /* sendInitialEvents */
&timeoutSeconds, /* timeoutSeconds */
&watch /* watch */
);
```

Setting 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.

## Aggregated APIs and CRD-based APIs

If 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).
Expand Down
10 changes: 5 additions & 5 deletions examples/auth_provider/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ void list_pod(apiClient_t * apiClient)
v1_pod_list_t *pod_list = NULL;
pod_list = CoreV1API_listNamespacedPod(apiClient, "default", /*namespace */
NULL, /* pretty */
0, /* allowWatchBookmarks */
NULL, /* allowWatchBookmarks */
NULL, /* continue */
NULL, /* fieldSelector */
NULL, /* labelSelector */
0, /* limit */
NULL, /* limit */
NULL, /* resourceVersion */
NULL, /* resourceVersionMatch */
0, /* sendInitialEvents */
0, /* timeoutSeconds */
0 /* watch */
NULL, /* sendInitialEvents */
NULL, /* timeoutSeconds */
NULL /* watch */
);
printf("The return code of HTTP request=%ld\n", apiClient->response_code);
if (pod_list) {
Expand Down
52 changes: 26 additions & 26 deletions examples/configmap/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <unistd.h>

void create_configmap(apiClient_t * apiClient, char *name, char *namespace_)
{
{
char *api_version = strdup("v1");
char *kind = strdup("ConfigMap");

Expand Down Expand Up @@ -41,12 +41,12 @@ void create_configmap(apiClient_t * apiClient, char *name, char *namespace_)
meta);

v1_config_map_t *ret_config_map = CoreV1API_createNamespacedConfigMap(apiClient,
namespace_,
body,
NULL,
NULL,
NULL,
NULL);
namespace_,
body,
NULL,
NULL,
NULL,
NULL);

printf("%s: The return code of HTTP request=%ld\n", __func__, apiClient->response_code);

Expand All @@ -70,18 +70,18 @@ void create_configmap(apiClient_t * apiClient, char *name, char *namespace_)
void list_configmap(apiClient_t * apiClient, char *namespace_)
{
v1_config_map_list_t *config_map_list = CoreV1API_listNamespacedConfigMap(apiClient,
namespace_, // char *namespace
namespace_, // char *namespace
"true", // char *pretty
0, // int allowWatchBookmarks
NULL, // char * _continue
NULL, // char * fieldSelector
NULL, // char * labelSelector
0, // int limit
NULL, // char * resourceVersion
NULL, // char * resourceVersionMatch
0, // sendInitialEvents
0, // int timeoutSeconds
0 //int watch
NULL, // int *allowWatchBookmarks
NULL, // char *_continue
NULL, // char *fieldSelector
NULL, // char *labelSelector
NULL, // int *limit
NULL, // char *resourceVersion
NULL, // char *resourceVersionMatch
NULL, // sendInitialEvents
NULL, // int *timeoutSeconds
NULL //int *watch
);

printf("%s: The return code of HTTP request=%ld\n", __func__, apiClient->response_code);
Expand Down Expand Up @@ -117,14 +117,14 @@ void list_configmap(apiClient_t * apiClient, char *namespace_)
void delete_configmap(apiClient_t * apiClient, char *name, char *namespace_)
{
v1_status_t *status = CoreV1API_deleteNamespacedConfigMap(apiClient,
name, // char *name
namespace_, // char *namespace
NULL, // char *pretty
NULL, // char *dryRun
0, // int gracePeriodSeconds
0, // int orphanDependents
NULL, // char *propagationPolicy
NULL // v1_delete_options_t *body
name, // char *name
namespace_, // char *namespace
NULL, // char *pretty
NULL, // char *dryRun
NULL, // int *gracePeriodSeconds
NULL, // int *orphanDependents
NULL, // char *propagationPolicy
NULL // v1_delete_options_t *body
);

printf("The return code of HTTP request=%ld\n", apiClient->response_code);
Expand Down
16 changes: 8 additions & 8 deletions examples/delete_pod/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
void delete_a_pod(apiClient_t * apiClient)
{
v1_pod_t *pod = CoreV1API_deleteNamespacedPod(apiClient,
"test-pod-6", // char *name
"default", // char *namespace
NULL, // char *pretty
NULL, // char *dryRun
30, // int gracePeriodSeconds
0, // int orphanDependents
NULL, // char *propagationPolicy
NULL // v1_delete_options_t *body
"test-pod-6", // char *name
"default", // char *namespace
NULL, // char *pretty
NULL, // char *dryRun
NULL, // int *gracePeriodSeconds
NULL, // int *orphanDependents
NULL, // char *propagationPolicy
NULL // v1_delete_options_t *body
);

printf("The return code of HTTP request=%ld\n", apiClient->response_code);
Expand Down
10 changes: 5 additions & 5 deletions examples/exec_provider/list_pod_by_exec_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ void list_pod(apiClient_t * apiClient)
v1_pod_list_t *pod_list = NULL;
pod_list = CoreV1API_listNamespacedPod(apiClient, "default", /*namespace */
NULL, /* pretty */
0, /* allowWatchBookmarks */
NULL, /* allowWatchBookmarks */
NULL, /* continue */
NULL, /* fieldSelector */
NULL, /* labelSelector */
0, /* limit */
NULL, /* limit */
NULL, /* resourceVersion */
NULL, /* resourceVersionMatch */
0, /* sendInitialEvents */
0, /* timeoutSeconds */
0 /* watch */
NULL, /* sendInitialEvents */
NULL, /* timeoutSeconds */
NULL /* watch */
);
printf("The return code of HTTP request=%ld\n", apiClient->response_code);
if (pod_list) {
Expand Down
10 changes: 5 additions & 5 deletions examples/list_event/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ void list_event(apiClient_t * apiClient)
{
core_v1_event_list_t *event_list = CoreV1API_listNamespacedEvent(apiClient, "default", /*namespace */
"true", /* pretty */
0, /* allowWatchBookmarks */
NULL, /* allowWatchBookmarks */
NULL, /* continue */
NULL, /* fieldSelector */
NULL, /* labelSelector */
0, /* limit */
NULL, /* limit */
NULL, /* resourceVersion */
NULL, /* resourceVersionMatch */
0, /* sendInitialEvents */
0, /* timeoutSeconds */
0 /* watch */
NULL, /* sendInitialEvents */
NULL, /* timeoutSeconds */
NULL /* watch */
);
printf("The return code of HTTP request=%ld\n", apiClient->response_code);
if (event_list) {
Expand Down
10 changes: 5 additions & 5 deletions examples/list_pod/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ void list_pod(apiClient_t * apiClient)
v1_pod_list_t *pod_list = NULL;
pod_list = CoreV1API_listNamespacedPod(apiClient, "default", /*namespace */
NULL, /* pretty */
0, /* allowWatchBookmarks */
NULL, /* allowWatchBookmarks */
NULL, /* continue */
NULL, /* fieldSelector */
NULL, /* labelSelector */
0, /* limit */
NULL, /* limit */
NULL, /* resourceVersion */
NULL, /* resourceVersionMatch */
0, /* sendInitialEvents */
0, /* timeoutSeconds */
0 /* watch */
NULL, /* sendInitialEvents */
NULL, /* timeoutSeconds */
NULL /* watch */
);
printf("The return code of HTTP request=%ld\n", apiClient->response_code);
if (pod_list) {
Expand Down
Loading

0 comments on commit 1315831

Please sign in to comment.