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: decouple the bootstraptoken API from the kubeadm API #102964

Merged

Conversation

neolit123
Copy link
Member

@neolit123 neolit123 commented Jun 17, 2021

What this PR does / why we need it:

Since kubeadm started using bootstrap tokens for bootstrap, it included a wrapper API (BoostrapToken and BoostrapTokenString) + some utilities to convert to and from a v1.Secret.

This API + utilities were duplicated in both the public main kubeadm API (versioned) and the internal API used for conversion.
This is completely not needed if the same API + utilities are extracted to their own group, so that kubeadm can use this both externally and internally the same way it is using metav1 or corev1.

  • Decouple the API + utilities into an new API group called bootstraptoken
  • Include a public version v1, since this mechanism has been used in a GA workflow for 10+ releases.
    • Conversion is not needed for the time being since this is the only version. The rest of kubeadm can just use the public type for the time being the same way we are using a v1.Pod.
  • Do not remove the same API + utilities from v1beta2 since there is binding with the "output" API. Problem should be resolved when we remove v1beta2:

Which issue(s) this PR fixes:

xref kubernetes/kubeadm#2427
xref kubernetes/kubeadm#1796

Special notes for your reviewer:

better to review one commit at a time.

Does this PR introduce a user-facing change?

kubeadm: move the BootstrapToken* API and related utilities from v1beta3 to a separate API group/version - bootstraptoken/v1.

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


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. 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 17, 2021
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubeadm sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 17, 2021
@neolit123 neolit123 force-pushed the 1.22-decouple-bootstraptoken-api branch from 8c97641 to 6363000 Compare June 17, 2021 21:48
@neolit123
Copy link
Member Author

/kind cleanup
/priority important-soon
/triage accepted

/cc @fabriziopandini

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 17, 2021
@neolit123
Copy link
Member Author

/hold for review

@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 17, 2021
@@ -0,0 +1,212 @@
/*
Copy link
Member Author

Choose a reason for hiding this comment

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

these and the tests in utils_test.go are copied from the versioned / internal bootstrap* files.

)

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BootstrapToken) DeepCopyInto(out *BootstrapToken) {
Copy link
Member Author

Choose a reason for hiding this comment

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

DeepCopyInto is needed because the BootstrapToken type is used in conversion in the "kubeadm" group.

@neolit123 neolit123 force-pushed the 1.22-decouple-bootstraptoken-api branch 3 times, most recently from 28b7eac to cb41d8f Compare June 17, 2021 22:11
Copy link
Member

@SataQiu SataQiu left a comment

Choose a reason for hiding this comment

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

/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 24, 2021
@SataQiu
Copy link
Member

SataQiu commented Jun 24, 2021

/retest

@neolit123
Copy link
Member Author

/cc @SataQiu @pacoxu

i think @fabriziopandini might be on PTO until next week. the 8th of July is code freeze and we should get this merged before then. do you have any more comments here?

@k8s-ci-robot k8s-ci-robot requested review from pacoxu and SataQiu June 29, 2021 14:21
// and internal usage. It also automatically validates that the given token
// is of the right format
func NewBootstrapTokenString(token string) (*BootstrapTokenString, error) {
substrs := bootstraputil.BootstrapTokenRegexp.FindStringSubmatch(token)
Copy link
Member

@pacoxu pacoxu Jul 1, 2021

Choose a reason for hiding this comment

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

Overall LGTM
/lgtm

When I go thought the code, I find IsValidBootstrapToken , BootstrapTokenRegexp are only used in /cmd/

Not sure if we need to move Regexp and isVaild func in kubernetes/staging/src/k8s.io/cluster-bootstrap/token/util/helpers.go to this utils.

And there is an old comment:

// TODO(dixudx): refactor this to util/secrets and util/tokens

Copy link
Member

Choose a reason for hiding this comment

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

@dixudx any ideas?

Copy link
Member Author

@neolit123 neolit123 Jul 1, 2021

Choose a reason for hiding this comment

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

originally we wanted the kubeadm bootstraptoken utils to live in k8s.io/cluster-bootstrap, but the idea was rejected with the argument that these introduce wrapper APIs that are kubeadm specific. only the bootstrap token Secret format matters as a specification and not the kubeadm originated BootstrapTokenString.

so what we ended up having is:

  • generic utils that can be used outside of kubeadm and residing in a library under k8s.io/cluster-bootstrap
  • kubeadm specific code in /cmd/kubeadm/...api including the one responsible converting token data <-> secret

overall what is in k8s.io/cluster-bootstrap is a library API at this point and moving it can be a breaking change to users, so we rather not do it.

things like BootstrapTokenRegexp and IsValidBootstrapToken makes sense to be in k8s.io/cluster-bootstrap. if someone wishes to use bootstrap tokens with their own bootstrap mechanism and without kubeadm.
the kubeadm "token data <-> secret" and other utils are quite useful but were not accepted in k8s.io/cluster-bootstrap.

Copy link
Member Author

Choose a reason for hiding this comment

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

// TODO(dixudx): refactor this to util/secrets and util/tokens

this TODO seems still relevant as something that can be done in /staging/... /cluster-bootstrap, e.g. having to separate files tokens.go and secrets.go. i don't remember the discussions about it.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 1, 2021
@neolit123
Copy link
Member Author

i will rebase this later today.

neolit123 added 4 commits July 2, 2021 00:11
Package bootstraptoken contains an API and utilities wrapping the
"bootstrap.kubernetes.io/token" Secret type to ease its usage in kubeadm.

The API is released as v1, since these utilities have been part of a
GA workflow for 10+ releases.

The "bootstrap.kubernetes.io/token" Secret type is also GA.
- Make v1beta3 use bootstraptoken/v1 instead of local copies
- Make the internal API use bootstraptoken/v1
- Update validation, /cmd, /util and other packages
- Update v1beta2 conversion
Given bootstraptoken/v1 is now a separate GV, there is no need
to duplicate the API and utilities inside v1beta3 and the internal
version.

v1beta2 must continue to use its internal copy due, since output/v1alpha1
embeds the v1beta2.BootstrapToken object. See issue 2427 in k/kubeadm.
@neolit123 neolit123 force-pushed the 1.22-decouple-bootstraptoken-api branch from 41be23d to 622f69b Compare July 1, 2021 21:12
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 1, 2021
@neolit123
Copy link
Member Author

@pacoxu rebased; conflict was in v1beta3/doc.go

@pacoxu
Copy link
Member

pacoxu commented Jul 2, 2021

/lgtm
/hold cancel
since there are no objections

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jul 2, 2021
@pacoxu
Copy link
Member

pacoxu commented Jul 2, 2021

/retest

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. 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/XXL Denotes a PR that changes 1000+ 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.

5 participants