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

kubeadm: Honor cert-dir for cert operations #110709

Merged
merged 1 commit into from Jun 24, 2022

Conversation

chendave
Copy link
Member

  • cert-dir could be specified to a value other than the default value
  • we have tests that should be executed successfully on the working cluster

Signed-off-by: Dave Chen dave.chen@arm.com

What type of PR is this?

/kind bug

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #110708

Special notes for your reviewer:

This issue only exists with a working cluster since the code will fall back to use the cluster configuration when config file is not specified.

And if the cluster cannot be connected with the admin.conf, the cert-dir will be honored, this is why the test can pass with the CI jobs but fail with working cluster, pls check the log printed by this test pr: #110681

pls see #110708 for details.

Does this PR introduce a user-facing change?

`kubeadm certs renew` and   `kubeadm certs check-expiration`  now honor the `cert-dir` on a working kubernetes cluster.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


/cc @neolit123

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 22, 2022
@chendave
Copy link
Member Author

/sig cluster-lifecycle

@k8s-ci-robot k8s-ci-robot added sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. area/kubeadm and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 22, 2022
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

This seems like a flags vs config problem.
Is cert-dir the only flag we have to override in the incluster config?

The change seems ok, but i think the more accurate fix is to not download the incluster config if a single flag is passed, because flags are also config.

Having said that, i don't think we do it like that in orher places and we just check for the config flag "" string similarly.

@chendave
Copy link
Member Author

Is cert-dir the only flag we have to override in the incluster config?

I think so, other flags (CertificatesDir, cfgPath) that are added seem like are not related.

The change seems ok, but i think the more accurate fix is to not download the incluster config if a single flag is passed, because flags are also config.

Okay, will do as suggested.

@chendave
Copy link
Member Author

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 22, 2022
@neolit123
Copy link
Member

neolit123 commented Jun 22, 2022

Okay, will do as suggested.

Unclear if we want the override vs don't download if a flag is passed. Ideally we should have consistency with other commands / code paths.

@BenTheElder
Copy link
Member

IMHO override seems like the least surprising behavior for setting a flag.

@chendave
Copy link
Member Author

chendave commented Jun 23, 2022

Unclear if we want the override vs don't download if a flag is passed.

Read the code again, if we don't download if the flag is passed, then the config returned is a default config plus the customized cert directory (if cfgPath is not given here and won't be an issue if cfgPath is given), so the override sound like a little better for this case?

Besides, I print one line msg to tell the cert directory is been overridden. Is that okay for you? @neolit123

// certificate renewal or expiration checking doesn't depend on a running cluster, which means the CertificatesDir
// could be set to a value other than the default value or the value fetched from the cluster.
// cfg.CertificatesDir could be empty if the default value is set to empty (not true today).
fmt.Printf("Overriding the default cert dir with the value from command line flag: %s", cfg.CertificatesDir)
Copy link
Member

Choose a reason for hiding this comment

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

i think this should be a klog.V(1).Infof()
other than that LGTM.

/approve

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, thanks!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chendave, neolit123

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 23, 2022
@neolit123
Copy link
Member

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 23, 2022
klog.V(1).Infof("Overriding the default cert dir with the value from command line flag: %s", cfg.CertificatesDir)
if len(cfg.CertificatesDir) != 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
klog.V(1).Infof("Overriding the default cert dir with the value from command line flag: %s", cfg.CertificatesDir)
if len(cfg.CertificatesDir) != 0 {
if len(cfg.CertificatesDir) != 0 {
klog.V(1).Infof("Overriding the cluster certificate directory with the value from command line flag --%s: %s", options.CertificatesDir, cfg.CertificatesDir)

flag name comes from:

CertificatesDir = "cert-dir"

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks!

- `cert-dir` could be specified to a value other than the default value
- we have tests that should be executed successfully on the working cluster

Signed-off-by: Dave Chen <dave.chen@arm.com>
@neolit123
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 23, 2022
@chendave
Copy link
Member Author

/hold cancel

thanks for the review!

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 24, 2022
@k8s-ci-robot k8s-ci-robot merged commit 07dfdf0 into kubernetes:master Jun 24, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.25 milestone Jun 24, 2022
@chendave chendave deleted the fix_renew branch June 24, 2022 02:55
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. area/kubeadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubeadm: cert renew doesn't work with cert-dir set
4 participants