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

apiserver identity: use persistent names for lease objects #113307

Merged

Conversation

andrewsykim
Copy link
Member

@andrewsykim andrewsykim commented Oct 24, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR updates the naming format for kube-apiserver Leases to use a format that persists even after a restart. The new format uses a hash of the hostname, so only apiservers using different hostnames will have unique identities. The holder identity of each Lease remains unique per start-up. This reduces system churn when lease objects are garbage collected, but still allows operators to identify when lease ownership is churning.

To support this change, the NewController constructor was updated for the lease controller to allow for overriding the lease name when it differs from the holder identity.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Update the Lease identity naming format for the APIServerIdentity feature to use a persistent name  

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. kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 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 Oct 24, 2022
@k8s-ci-robot k8s-ci-robot added area/apiserver area/test sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 24, 2022

// NewControllerWithLeaseName is a copy of NewController but accepts a leaseName parameter.
// Use this constructor in cases when the lease name and holder identity should be different.
func NewControllerWithLeaseName(clock clock.Clock, client clientset.Interface, holderIdentity string, leaseDurationSeconds int32, onRepeatedHeartbeatFailure func(), renewInterval time.Duration, leaseName, leaseNamespace string, newLeasePostProcessFunc ProcessLeaseFunc) Controller {
Copy link
Member Author

Choose a reason for hiding this comment

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

Alternative approach: add a WithLeaseName() method to the controller.

Don't feel too strongly and fine with either approach, both would prevent breaking compatibility for this package

Copy link
Contributor

Choose a reason for hiding this comment

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

I like breaking it

@leilajal
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 27, 2022
@@ -80,6 +81,28 @@ func NewController(clock clock.Clock, client clientset.Interface, holderIdentity
client: client,
leaseClient: leaseClient,
holderIdentity: holderIdentity,
leaseName: holderIdentity,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this NewControllerWithLeaseName to keep the paths unified?

@k8s-ci-robot k8s-ci-robot added area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. labels Nov 1, 2022
@deads2k
Copy link
Contributor

deads2k commented Nov 1, 2022

/lgtm
/approve

the separation of leaseName and holderIdentity is an important distinction. Without it we were pushed towards some sub-par options in the kube-apiserver usage pattern.

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

/assign @wojtek-t

@andrewsykim
Copy link
Member Author

/assign @lavalamp

Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
…e new naming format and hostname label

Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
…upport cases when the lease name and holder identity differ

Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
…entity

Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
…eter, remove NewControllerWithLeaseName

Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2022
@wojtek-t
Copy link
Member

wojtek-t commented Nov 4, 2022

/lgtm
/approve

Thanks!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewsykim, deads2k, wojtek-t

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 Nov 4, 2022
@andrewsykim
Copy link
Member Author

/retest

1 similar comment
@andrewsykim
Copy link
Member Author

/retest

@k8s-ci-robot k8s-ci-robot merged commit c8a3657 into kubernetes:master Nov 4, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Nov 4, 2022
klog.Fatalf("error getting hostname for apiserver identity: %v", err)
}

h := fnv.New32a()
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer a real hash function, this is only called at startup, there's no performance problem. Can you switch to SHA256? It is OK to truncate the result a bit, but 4 bytes is too small.

If we assume there are 1M k8s clusters, each with 3 apiservers, there is a 1000000*(1-e^(-(3^2)/(2^32))) = .2% one of them will have a collision. That's far too high, I would like a chance less than 1e-9. (google "birthday paradox estimator" if you want to check my math)

6 bytes is enough to pass that test, so I would go to 8 bytes selected from SHA256, where there is no question that it is very random.

Copy link
Member

Choose a reason for hiding this comment

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

(and sorry I wasn't able to review this until now)

Copy link
Member

Choose a reason for hiding this comment

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

(oh and if you want you can use the base58 encoder to save some characters)

Copy link
Member

Choose a reason for hiding this comment

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

Why bother truncating at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #113649 -- tests seem fine without needing to truncate, but still might be worthwhile just to avoid lease names that are really long. I don't feel too strongly with the lease name being that long but myabe some people do?

@enj
Copy link
Member

enj commented Nov 5, 2022

Aside: this should have been squashed before merge.

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/apiserver area/kubelet area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants