Skip to content
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

[Configuration] Support exec for kubeconfig #12

Merged
merged 1 commit into from
May 28, 2020

Conversation

ityuhui
Copy link
Member

@ityuhui ityuhui commented May 22, 2020

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 22, 2020
return -1;
}
snprintf(env_string, env_string_length, "%s=%s", pair->key, (char *) (pair->value));
rc = putenv(env_string);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use setenv instead of putenv for clearer/simpler memory semantics. Otherwise this will leak memory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. The function setenv is very good to use.

@@ -21,15 +24,34 @@ static int setBasePath(char **pBasePath, char *basePath)
return -1;
}

static char *kubeconfig_mk_cert_key_tempfile(const char *b64data)
static int is_cert_or_key_base64_encoded(const char *data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can assume c99 at this point, so static bool is_cert_or_key_base64_encoded(...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

const char *cert_key_data = NULL;
int cert_key_data_bytes = 0;

if (0 == is_cert_or_key_base64_encoded(data)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove 0 == once we switch to bool return value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

fprintf(stderr, "%s: Base64 decodes failed.\n", fname);
return NULL;
}
cert_key_data = b64decode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This memory is leaked, I think. We should free cert_key_data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. you're right. I will handle it.

int new_command_length = strlen(kube_config_dirname) + strlen("/") + strlen(original_command) + 1 /* 1 for the terminal of string */ ;
exec->command = calloc(1, new_command_length);
if (!exec->command) {
fprintf(stderr, "%s: Cannot allocate memory for exec command.[%s]\n", fname, strerror(errno));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to leak the memory in original_command

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I will handle it.

@brendandburns
Copy link
Contributor

Some comments. We should consider adding valgrind testing to catch memory leaks.

@ityuhui
Copy link
Member Author

ityuhui commented May 24, 2020

Thank you @brendandburns. I have addressed your comments.
Thank you for your finding about these memory leaks.

And I also have run valgrind to check memory and logged two issues #13,#15
I will add the valgrind memory check to Github/Actions sometimes later

@brendandburns
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 28, 2020
@k8s-ci-robot
Copy link
Contributor

[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 [brendandburns,ityuhui]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit fb29e6c into kubernetes-client:master May 28, 2020
@ityuhui ityuhui deleted the yhkubeconfigexec branch May 29, 2020 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants