-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the examples to demo listing/creating pods #3
Conversation
/cc @brendandburns |
examples/create_pod/main.c
Outdated
#include <stdio.h> | ||
#include <errno.h> | ||
|
||
#define K8S_APISERVER_BASEPATH "https://9.111.254.254:6443" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's anonymize this with something like "https://your.server.here"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to have been fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I have updated but not pushed to Github.
I want to
- Prepare a GNU Indent parameter list first and get your reviewed
- Use GNU Indent to check my new source
- Push the new source code to here for review again.
examples/create_pod/main.c
Outdated
} | ||
|
||
int | ||
loadK8sConfigInCluster(char *token, int token_buf_size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: function on the same line as the return type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
examples/create_pod/main.c
Outdated
return 0; | ||
} | ||
|
||
int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
examples/create_pod/main.c
Outdated
char token_in_cluster[K8S_TOKEN_BUF_SIZE]; | ||
memset(token_in_cluster, 0, sizeof(token_in_cluster)); | ||
|
||
//loadK8sConfigInCluster(token_in_cluster, K8S_TOKEN_BUF_SIZE); // in cluster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete commented out code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the //loadK8sConfigInCluster here to tell user that how to get config when the program is in a kubernets cluster. It maybe confused.
Deleting it is OK. I can provide another example or function to demo getting config in cluster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add a comment like:
// If you want to load in cluster you would use
// loadk8sConfigInCluster(...)
That's fine. As it is currently written it's not quite clear.
examples/create_pod/main.c
Outdated
|
||
char valueToken[K8S_TOKEN_BUF_SIZE]; | ||
memset(valueToken, 0, sizeof(valueToken)); | ||
//sprintf(valueToken, K8S_AUTH_VALUE_TEMPLATE, token); // in cluster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
examples/list_pod/main.c
Outdated
0 /* watch */ | ||
); | ||
printf("return code=%ld\n", apiClient->response_code); | ||
if(pod_list){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: spaces between if
and (pod_list)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
examples/list_pod/main.c
Outdated
printf("pod name=%s\n", pod->metadata->name); | ||
} | ||
|
||
}else{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too wrt spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
examples/list_pod/main.c
Outdated
} | ||
|
||
int | ||
loadK8sConfigInCluster(char *token, int token_buf_size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function and return type on same line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
examples/list_pod/main.c
Outdated
if (fp == NULL) { | ||
if (errno == ENOENT) { | ||
printf("\ | ||
%s: The file %s does not exist.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is there a line-break here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No special reason, just want to keep the message text in a dedicated line.
Removing the line-break is OK to me.
examples/list_pod/main.c
Outdated
char token_in_cluster[K8S_TOKEN_BUF_SIZE]; | ||
memset(token_in_cluster, 0, sizeof(token_in_cluster)); | ||
|
||
//loadK8sConfigInCluster(token_in_cluster, K8S_TOKEN_BUF_SIZE); // in cluster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
examples/list_pod/main.c
Outdated
|
||
char valueToken[K8S_TOKEN_BUF_SIZE]; | ||
memset(valueToken, 0, sizeof(valueToken)); | ||
//sprintf(valueToken, K8S_AUTH_VALUE_TEMPLATE, token); // in cluster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
Thanks for the examples! I think we need to adopt a style guide for this repo, and add some validation testing to ensure that code matches the style guide. Do you have any suggestions for a good C style guide? Perhaps Gnu Indent (https://www.gnu.org/software/indent/) |
@brendandburns Thank you for your review. I will update the code by your comment. And I agree that we should adopt a style guide for this repo. Let me learn and try Gnu Indent. |
Do you have a preferred GNU Indent parameter list ? If not, I will prepare a parameter list for your review. |
I don't have a preferred parameter list, let's start with what you suggest. |
Sounds great, let me know when this PR is ready to review again. Thanks! |
1. Anonymize the API server address 2. Remove useless line-break 3. Delete commented out code
I have prepared a parameter list of GNU Indent for your review: Parameter List-npro -nbad -nip -lp -npsl -npcs -i4 -ts4 -sob -br -ce -nut -bap -nbc -bbo -brs -cs -nfc1 -nfca -hnl -ip0 -nprs -saf -sai -saw -ci4 -cli0 -l200 Detail Description
ReferenceNew Example CodeI have used GNU Indent with this parameter list to generate the new example source code and pushed them here for review again. |
Looks great! /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, ityuhui The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Add two examples to demo how to use the c client library:
Because now kuberentes-client/c has no utility such as "config" functions in addition to the source code generated by OpenAPI c generator, these two examples implement the config utility functions in their own source code.
After this PR, I will implement and integrate the config utility to kuberentes-client/c. the same as other language client libraries.