kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
146 stars 46 forks source link

Add the examples to demo listing/creating pods #3

Closed ityuhui closed 4 years ago

ityuhui commented 4 years ago

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.

int loadK8sConfigInCluster(char *token, int token_buf_size);
int init_k8s_connector(const char *token_out_of_cluster);

After this PR, I will implement and integrate the config utility to kuberentes-client/c. the same as other language client libraries.

ityuhui commented 4 years ago

/cc @brendandburns

brendandburns commented 4 years ago

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/)

ityuhui commented 4 years ago

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

ityuhui commented 4 years ago

Hi @brendandburns

Do you have a preferred GNU Indent parameter list ? (e.g. -npro -nip -nlp -npsl -i4 -ts4 -sob -l200 -ss -bl -bli 0)

If not, I will prepare a parameter list for your review.

brendandburns commented 4 years ago

I don't have a preferred parameter list, let's start with what you suggest.

brendandburns commented 4 years ago

Sounds great, let me know when this PR is ready to review again.

Thanks!

ityuhui commented 4 years ago

Hi @brendandburns

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

Option Description
-npro Do not read ‘.indent.pro’ files.
-nbad Do not force blank lines after declarations.
-nip Zero width indentation for parameters.
-lp Line up continued lines at parentheses.
-npsl Put the type of a procedure on the same line as its name.
-npcs Do not put space after the function in function calls.
-i4 Set indentation level to 4 spaces.
-ts4 Set tab size to 4 spaces.
-sob Swallow optional blank lines.
-br Put braces on line with if, etc.
-ce Cuddle else and preceding ‘}’.
-nut Use spaces instead of tabs.
-bap Force blank lines after procedure bodies.
-nbc Do not force newlines after commas in declarations.
-bbo Prefer to break long lines before boolean operators.
-brs Put braces on struct declaration line.
-cs Put a space after a cast operator.
-nfc1 Do not format comments in the first column as normal.
-nfca Do not format any comments.
-hnl Prefer to break long lines at the position of newlines in the input.
-ip0 Indent parameter types in old-style function definitions by 0 spaces.
-nprs Do not put a space after every '(' and before every ')'.
-saf Put a space after each for.
-sai Put a space after each if.
-saw Put a space after each while.
-ci4 Continuation indent of 4 spaces.
-cli0 Case label indent of 0 spaces.
-l200 Set maximum line length for non-comment lines to 200.

Reference

GNU Indent Document

New Example Code

I have used GNU Indent with this parameter list to generate the new example source code and pushed them here for review again.

brendandburns commented 4 years ago

Looks great!

/lgtm /approve

k8s-ci-robot commented 4 years ago

[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: - ~~[OWNERS](https://github.com/kubernetes-client/c/blob/master/OWNERS)~~ [brendandburns,ityuhui] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment