Skip to content

Commit 74913dd

Browse files
authored
Merge pull request #68 from ityuhui/yh-list-secret
Fix the issue of parsing json string of kubernetes secret
2 parents d83ca5a + a4fdd8e commit 74913dd

33 files changed

+230
-81
lines changed

examples/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ all:
99
cd watch_list_pod; make
1010
cd multi_thread; make
1111
cd exec_pod; make
12+
cd list_secret; make
1213

1314
clean:
1415
cd create_pod; make clean
@@ -21,11 +22,13 @@ clean:
2122
cd watch_list_pod; make clean
2223
cd multi_thread; make clean
2324
cd exec_pod; make clean
25+
cd list_secret; make clean
2426

2527
test:
2628
cd create_pod; make test; sleep 10
2729
cd list_pod; make test
2830
cd delete_pod; make test
31+
cd list_secret; make test
2932
cd generic; make test
3033
cd multi_thread; make test; sleep 10
3134
kubectl describe po test-pod-8

examples/list_secret/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
list_secret_bin

examples/list_secret/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
INCLUDE:=-I../../kubernetes/include -I../../kubernetes/model -I../../kubernetes/api -I../../kubernetes/config
2+
LIBS:=-L../../kubernetes/build -lkubernetes -lyaml -lwebsockets -L/usr/local/lib
3+
CFLAGS:=-g
4+
BIN:=list_secret_bin
5+
6+
all:
7+
gcc main.c $(CFLAGS) $(INCLUDE) $(LIBS) -o $(BIN)
8+
clean:
9+
rm ./$(BIN)
10+
test:
11+
./$(BIN)

examples/list_secret/main.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <kube_config.h>
2+
#include <apiClient.h>
3+
#include <CoreV1API.h>
4+
#include <malloc.h>
5+
#include <stdio.h>
6+
#include <errno.h>
7+
8+
void list_secret(apiClient_t * apiClient)
9+
{
10+
v1_secret_list_t *secret_list = CoreV1API_listNamespacedSecret(apiClient,
11+
"default", // char *namespace
12+
"true", // char *pretty
13+
0, // int allowWatchBookmarks
14+
NULL, // char * _continue
15+
NULL, // char * fieldSelector
16+
NULL, // char * labelSelector
17+
0, // int limit
18+
NULL, // char * resourceVersion
19+
0, // int timeoutSeconds
20+
0 //int watch
21+
);
22+
23+
printf("The return code of HTTP request=%ld\n", apiClient->response_code);
24+
25+
if (200 == apiClient->response_code) {
26+
printf("List the secrets successfully.\n");
27+
} else {
28+
fprintf(stderr, "Failed to list the secrets.\n");
29+
return;
30+
}
31+
32+
if (secret_list && secret_list->items) {
33+
listEntry_t *secret_list_entry = NULL;
34+
v1_secret_t *secret = NULL;
35+
list_ForEach(secret_list_entry, secret_list->items) {
36+
secret = secret_list_entry->data;
37+
printf("\tThe secret name: %s\n", secret->metadata->name);
38+
39+
listEntry_t *data_entry = NULL;
40+
keyValuePair_t *pair = NULL;
41+
list_ForEach(data_entry, secret->data) {
42+
pair = data_entry->data;
43+
printf("\tkey=%s, value=%s\n", pair->key, (char *) pair->value);
44+
}
45+
}
46+
v1_secret_list_free(secret_list);
47+
secret_list = NULL;
48+
} else {
49+
fprintf(stderr, "The secret list is invalid.\n");
50+
}
51+
}
52+
53+
int main(int argc, char *argv[])
54+
{
55+
char *basePath = NULL;
56+
sslConfig_t *sslConfig = NULL;
57+
list_t *apiKeys = NULL;
58+
int rc = load_kube_config(&basePath, &sslConfig, &apiKeys, NULL); /* NULL means loading configuration from $HOME/.kube/config */
59+
if (rc != 0) {
60+
fprintf(stderr, "Cannot load kubernetes configuration.\n");
61+
return -1;
62+
}
63+
apiClient_t *apiClient = apiClient_create_with_base_path(basePath, sslConfig, apiKeys);
64+
if (!apiClient) {
65+
fprintf(stderr, "Cannot create a kubernetes client.\n");
66+
return -1;
67+
}
68+
69+
list_secret(apiClient);
70+
71+
apiClient_free(apiClient);
72+
apiClient = NULL;
73+
free_client_config(basePath, sslConfig, apiKeys);
74+
basePath = NULL;
75+
sslConfig = NULL;
76+
apiKeys = NULL;
77+
apiClient_unsetupGlobalEnv();
78+
79+
return 0;
80+
}

kubernetes/docs/admissionregistration_v1_webhook_client_config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6-
**ca_bundle** | **char** | &#x60;caBundle&#x60; is a PEM encoded CA bundle which will be used to validate the webhook&#39;s server certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
6+
**ca_bundle** | **char \*** | &#x60;caBundle&#x60; is a PEM encoded CA bundle which will be used to validate the webhook&#39;s server certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
77
**service** | [**admissionregistration_v1_service_reference_t**](admissionregistration_v1_service_reference.md) \* | | [optional]
88
**url** | **char \*** | &#x60;url&#x60; gives the location of the webhook, in standard URL form (&#x60;scheme://host:port/path&#x60;). Exactly one of &#x60;url&#x60; or &#x60;service&#x60; must be specified. The &#x60;host&#x60; should not refer to a service running in the cluster; use the &#x60;service&#x60; field instead. The host might be resolved via external DNS in some apiservers (e.g., &#x60;kube-apiserver&#x60; cannot resolve in-cluster DNS as that would be a layering violation). &#x60;host&#x60; may also be an IP address. Please note that using &#x60;localhost&#x60; or &#x60;127.0.0.1&#x60; as a &#x60;host&#x60; is risky unless you take great care to run this webhook on all hosts which run an apiserver which might need to make calls to this webhook. Such installs are likely to be non-portable, i.e., not easy to turn up in a new cluster. The scheme must be \&quot;https\&quot;; the URL must begin with \&quot;https://\&quot;. A path is optional, and if present may be any string permissible in a URL. You may use the path to pass an arbitrary string to the webhook, for example, a cluster identifier. Attempting to use a user or basic auth e.g. \&quot;user:password@\&quot; is not allowed. Fragments (\&quot;#...\&quot;) and query parameters (\&quot;?...\&quot;) are not allowed, either. | [optional]
99

kubernetes/docs/admissionregistration_v1beta1_webhook_client_config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6-
**ca_bundle** | **char** | &#x60;caBundle&#x60; is a PEM encoded CA bundle which will be used to validate the webhook&#39;s server certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
6+
**ca_bundle** | **char \*** | &#x60;caBundle&#x60; is a PEM encoded CA bundle which will be used to validate the webhook&#39;s server certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
77
**service** | [**admissionregistration_v1beta1_service_reference_t**](admissionregistration_v1beta1_service_reference.md) \* | | [optional]
88
**url** | **char \*** | &#x60;url&#x60; gives the location of the webhook, in standard URL form (&#x60;scheme://host:port/path&#x60;). Exactly one of &#x60;url&#x60; or &#x60;service&#x60; must be specified. The &#x60;host&#x60; should not refer to a service running in the cluster; use the &#x60;service&#x60; field instead. The host might be resolved via external DNS in some apiservers (e.g., &#x60;kube-apiserver&#x60; cannot resolve in-cluster DNS as that would be a layering violation). &#x60;host&#x60; may also be an IP address. Please note that using &#x60;localhost&#x60; or &#x60;127.0.0.1&#x60; as a &#x60;host&#x60; is risky unless you take great care to run this webhook on all hosts which run an apiserver which might need to make calls to this webhook. Such installs are likely to be non-portable, i.e., not easy to turn up in a new cluster. The scheme must be \&quot;https\&quot;; the URL must begin with \&quot;https://\&quot;. A path is optional, and if present may be any string permissible in a URL. You may use the path to pass an arbitrary string to the webhook, for example, a cluster identifier. Attempting to use a user or basic auth e.g. \&quot;user:password@\&quot; is not allowed. Fragments (\&quot;#...\&quot;) and query parameters (\&quot;?...\&quot;) are not allowed, either. | [optional]
99

kubernetes/docs/apiextensions_v1_webhook_client_config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6-
**ca_bundle** | **char** | caBundle is a PEM encoded CA bundle which will be used to validate the webhook&#39;s server certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
6+
**ca_bundle** | **char \*** | caBundle is a PEM encoded CA bundle which will be used to validate the webhook&#39;s server certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
77
**service** | [**apiextensions_v1_service_reference_t**](apiextensions_v1_service_reference.md) \* | | [optional]
88
**url** | **char \*** | url gives the location of the webhook, in standard URL form (&#x60;scheme://host:port/path&#x60;). Exactly one of &#x60;url&#x60; or &#x60;service&#x60; must be specified. The &#x60;host&#x60; should not refer to a service running in the cluster; use the &#x60;service&#x60; field instead. The host might be resolved via external DNS in some apiservers (e.g., &#x60;kube-apiserver&#x60; cannot resolve in-cluster DNS as that would be a layering violation). &#x60;host&#x60; may also be an IP address. Please note that using &#x60;localhost&#x60; or &#x60;127.0.0.1&#x60; as a &#x60;host&#x60; is risky unless you take great care to run this webhook on all hosts which run an apiserver which might need to make calls to this webhook. Such installs are likely to be non-portable, i.e., not easy to turn up in a new cluster. The scheme must be \&quot;https\&quot;; the URL must begin with \&quot;https://\&quot;. A path is optional, and if present may be any string permissible in a URL. You may use the path to pass an arbitrary string to the webhook, for example, a cluster identifier. Attempting to use a user or basic auth e.g. \&quot;user:password@\&quot; is not allowed. Fragments (\&quot;#...\&quot;) and query parameters (\&quot;?...\&quot;) are not allowed, either. | [optional]
99

kubernetes/docs/apiextensions_v1beta1_webhook_client_config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6-
**ca_bundle** | **char** | caBundle is a PEM encoded CA bundle which will be used to validate the webhook&#39;s server certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
6+
**ca_bundle** | **char \*** | caBundle is a PEM encoded CA bundle which will be used to validate the webhook&#39;s server certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
77
**service** | [**apiextensions_v1beta1_service_reference_t**](apiextensions_v1beta1_service_reference.md) \* | | [optional]
88
**url** | **char \*** | url gives the location of the webhook, in standard URL form (&#x60;scheme://host:port/path&#x60;). Exactly one of &#x60;url&#x60; or &#x60;service&#x60; must be specified. The &#x60;host&#x60; should not refer to a service running in the cluster; use the &#x60;service&#x60; field instead. The host might be resolved via external DNS in some apiservers (e.g., &#x60;kube-apiserver&#x60; cannot resolve in-cluster DNS as that would be a layering violation). &#x60;host&#x60; may also be an IP address. Please note that using &#x60;localhost&#x60; or &#x60;127.0.0.1&#x60; as a &#x60;host&#x60; is risky unless you take great care to run this webhook on all hosts which run an apiserver which might need to make calls to this webhook. Such installs are likely to be non-portable, i.e., not easy to turn up in a new cluster. The scheme must be \&quot;https\&quot;; the URL must begin with \&quot;https://\&quot;. A path is optional, and if present may be any string permissible in a URL. You may use the path to pass an arbitrary string to the webhook, for example, a cluster identifier. Attempting to use a user or basic auth e.g. \&quot;user:password@\&quot; is not allowed. Fragments (\&quot;#...\&quot;) and query parameters (\&quot;?...\&quot;) are not allowed, either. | [optional]
99

kubernetes/docs/v1_api_service_spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6-
**ca_bundle** | **char** | CABundle is a PEM encoded CA bundle which will be used to validate an API server&#39;s serving certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
6+
**ca_bundle** | **char \*** | CABundle is a PEM encoded CA bundle which will be used to validate an API server&#39;s serving certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
77
**group** | **char \*** | Group is the API group name this server hosts | [optional]
88
**group_priority_minimum** | **int** | GroupPriorityMininum is the priority this group should have at least. Higher priority means that the group is preferred by clients over lower priority ones. Note that other versions of this group might specify even higher GroupPriorityMininum values such that the whole group gets a higher priority. The primary sort is based on GroupPriorityMinimum, ordered highest number to lowest (20 before 10). The secondary sort is based on the alphabetical comparison of the name of the object. (v1.bar before v1.foo) We&#39;d recommend something like: *.k8s.io (except extensions) at 18000 and PaaSes (OpenShift, Deis) are recommended to be in the 2000s |
99
**insecure_skip_tls_verify** | **int** | InsecureSkipTLSVerify disables TLS certificate verification when communicating with this server. This is strongly discouraged. You should use the CABundle instead. | [optional]

kubernetes/docs/v1alpha1_webhook_client_config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6-
**ca_bundle** | **char** | &#x60;caBundle&#x60; is a PEM encoded CA bundle which will be used to validate the webhook&#39;s server certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
6+
**ca_bundle** | **char \*** | &#x60;caBundle&#x60; is a PEM encoded CA bundle which will be used to validate the webhook&#39;s server certificate. If unspecified, system trust roots on the apiserver are used. | [optional]
77
**service** | [**v1alpha1_service_reference_t**](v1alpha1_service_reference.md) \* | | [optional]
88
**url** | **char \*** | &#x60;url&#x60; gives the location of the webhook, in standard URL form (&#x60;scheme://host:port/path&#x60;). Exactly one of &#x60;url&#x60; or &#x60;service&#x60; must be specified. The &#x60;host&#x60; should not refer to a service running in the cluster; use the &#x60;service&#x60; field instead. The host might be resolved via external DNS in some apiservers (e.g., &#x60;kube-apiserver&#x60; cannot resolve in-cluster DNS as that would be a layering violation). &#x60;host&#x60; may also be an IP address. Please note that using &#x60;localhost&#x60; or &#x60;127.0.0.1&#x60; as a &#x60;host&#x60; is risky unless you take great care to run this webhook on all hosts which run an apiserver which might need to make calls to this webhook. Such installs are likely to be non-portable, i.e., not easy to turn up in a new cluster. The scheme must be \&quot;https\&quot;; the URL must begin with \&quot;https://\&quot;. A path is optional, and if present may be any string permissible in a URL. You may use the path to pass an arbitrary string to the webhook, for example, a cluster identifier. Attempting to use a user or basic auth e.g. \&quot;user:password@\&quot; is not allowed. Fragments (\&quot;#...\&quot;) and query parameters (\&quot;?...\&quot;) are not allowed, either. | [optional]
99

0 commit comments

Comments
 (0)