Skip to content

fix: make sure nodeclaims hostname are also set #2156

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rajpopat27
Copy link

Fixes #2123

Description
Make sure karpenter considers nodeclaims while counting Domains

How was this change tested?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 21, 2025
Copy link

linux-foundation-easycla bot commented Apr 21, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Apr 21, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @rajpopat27!

It looks like this is your first PR to kubernetes-sigs/karpenter 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/karpenter has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 21, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @rajpopat27. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 21, 2025
@jonathan-innis
Copy link
Member

/assign @jonathan-innis

// ignore the node if it doesn't match the topology group
if !tg.nodeFilter.Matches(n.Node.Spec.Taints, scheduling.NewLabelRequirements(n.Node.Labels)) {
if !tg.nodeFilter.Matches(n.Taints(), scheduling.NewLabelRequirements(n.Labels())) {
Copy link
Member

Choose a reason for hiding this comment

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

n.Labels() doesn't have hostname hydrated into it if it still hasn't resolved to a Node -- we should consider injecting hostname into the labels, which would make this code work?

Copy link
Author

Choose a reason for hiding this comment

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

@jonathan-innis The nodeclaim get that kubernetes.io/hostname labels once it is launched

created, err := l.cloudProvider.Create(ctx, nodeClaim)

nodeClaim = PopulateNodeClaimDetails(nodeClaim, created)

And the only the nodeclaim that are launched will appear in state nodes
if providerID == "" {

and in the countDomains we are only checking nodes that are in state nodes so I guess should be fine

Copy link
Member

Choose a reason for hiding this comment

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

The hostname does not get propagated on launch -- for instance, on AWS, this change doesn't work because we don't see the hostname until the node actually joins the cluster so the same bug is present.

I'm suspecting you might be running into this because our KWOK cloudprovider doesn't model this quite right today

Choose a reason for hiding this comment

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

Oh I see okay let me make the changes for this

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rajpopat27
Once this PR has been reviewed and has the lgtm label, please ask for approval from jonathan-innis. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 28, 2025
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 28, 2025
@rajpopat27 rajpopat27 changed the title make sure nodeclaims hostname are also set fix: make sure nodeclaims hostname are also set Apr 28, 2025
@coveralls
Copy link

coveralls commented Apr 28, 2025

Pull Request Test Coverage Report for Build 15017125737

Details

  • 38 of 45 (84.44%) changed or added relevant lines in 3 files are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 81.923%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/test/expectations/expectations.go 20 27 74.07%
Files with Coverage Reduction New Missed Lines %
pkg/controllers/disruption/consolidation.go 4 85.55%
Totals Coverage Status
Change from base Build 15008130753: 0.03%
Covered Lines: 10138
Relevant Lines: 12375

💛 - Coveralls

@rajpopat27 rajpopat27 marked this pull request as ready for review April 28, 2025 09:28
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 28, 2025

// We special-case kubernetes.io/hostname primarily for stateNodes having NodeClaims without a node
// and since their domain won't be registered until the node joins the cluster.
if !exists && tg.Key == corev1.LabelHostname {
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused why we need to fake the value in this code here -- why don't we just fake the value at the StateNode and then we don't have to special-case code in this scheduling section. I think all this fix amounts to is passing the same value that n.HostName() has back through n.Labels(). Seems like that would simplify a lot of this and you wouldn't have to make any changes to this section of code

Choose a reason for hiding this comment

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

Currently, the NodeClaim name, which is used as the hostname in topologies, is a generated value created after the p.Create method provisions the NodeClaim using kubeClient.

Would you recommend issuing a patch request to update the NodeClaim's labels by setting the hostname label to match the NodeClaim name? If not, could you suggest a more appropriate stage or mechanism for assigning the hostname label based on the NodeClaim name?

An alternative approach I considered is to incorporate this logic into the c.UpdateNodeClaim method—specifically, to check whether the NodeClaim lacks a hostname label and has an empty hostname value, and if so, to assign the hostname label accordingly.

@@ -306,6 +306,39 @@ func ExpectProvisioned(ctx context.Context, c client.Client, cluster *state.Clus
return bindings
}

//nolint:gocyclo
func ExpectProvisionedNoNode(ctx context.Context, c client.Client, cluster *state.Cluster, cloudProvider cloudprovider.CloudProvider, provisioner *provisioning.Provisioner, pods ...*corev1.Pod) ([]*v1.NodeClaim, error) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Why return an error here when you can just enforce the lack of errors through expectations?

//nolint:gocyclo
func ExpectProvisionedNoNode(ctx context.Context, c client.Client, cluster *state.Cluster, cloudProvider cloudprovider.CloudProvider, provisioner *provisioning.Provisioner, pods ...*corev1.Pod) ([]*v1.NodeClaim, error) {
GinkgoHelper()
nodeClaims := []*v1.NodeClaim{}
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
nodeClaims := []*v1.NodeClaim{}
var nodeClaims []*v1.NodeClaim

nit: style

@@ -306,6 +306,39 @@ func ExpectProvisioned(ctx context.Context, c client.Client, cluster *state.Clus
return bindings
}

//nolint:gocyclo
func ExpectProvisionedNoNode(ctx context.Context, c client.Client, cluster *state.Cluster, cloudProvider cloudprovider.CloudProvider, provisioner *provisioning.Provisioner, pods ...*corev1.Pod) ([]*v1.NodeClaim, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Since this function is a subset of the other function, can you just use this function in ExepctProvisionedNoBinding()?

@@ -175,6 +175,13 @@ func (c *CloudProvider) Create(ctx context.Context, nodeClaim *v1.NodeClaim) (*v
labels[req.Key] = req.Any()
}

// add the derived nodeclaim requirement labels as we do in addInstanceLabels in KWOK provider
for _, r := range nodeClaim.Spec.Requirements {
Copy link
Member

Choose a reason for hiding this comment

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

Why specifically do you need this in your change if your change has to do with hostname specifically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Karpenter scaling unproportionately high nodes
5 participants