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

Helm: sanitize resource name lengths #3250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mruoss
Copy link

@mruoss mruoss commented Oct 17, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

This PR addresses a but in the Helm chart. Some of the resources generated by the Helm chart are very long. Combined with the release name, they can easily get too long.

Example

Let's look at the resource {{ include "kueue.fullname" . }}-controller-manager-metrics-service of kind: Service. When generated for a somewhat long release name like project-foo-cluster-bar-kueue, the resulting resource name is project-foo-cluster-bar-kueue-controller-manager-metrics-service which is 65 characters long and we get the following error when trying to apply/install:

Service "project-foo-cluster-bar-kueue-controller-manager-metrics-service" is invalid: metadata.name: Invalid value: "project-foo-cluster-bar-kueue-controller-manager-metrics-service": must be no more than 63 characters

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE (it only affects names for resources that would have been too long and therefore failed anyway. Existing resources remain unchanged)

Helm: Sanitize resource names by truncating them to a maximum length of 63 characters

@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. labels Oct 17, 2024
Copy link

linux-foundation-easycla bot commented Oct 17, 2024

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 Oct 17, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @mruoss!

It looks like this is your first PR to kubernetes-sigs/kueue 🎉. 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/kueue 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 Oct 17, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @mruoss. 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.

Copy link

netlify bot commented Oct 17, 2024

Deploy Preview for kubernetes-sigs-kueue ready!

Name Link
🔨 Latest commit 516f0b2
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/6710b77ded65cf00084c000a
😎 Deploy Preview https://deploy-preview-3250--kubernetes-sigs-kueue.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. 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 Oct 17, 2024
@mruoss mruoss changed the title sanitaze resource name lengths sanitize resource name lengths Oct 17, 2024
@mruoss mruoss changed the title sanitize resource name lengths Helm: sanitize resource name lengths Oct 17, 2024
Copy link
Contributor

@mimowo mimowo left a comment

Choose a reason for hiding this comment

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

LGTM, but I would prefer to also give it a pass by @mbobrovskyi or @tenzen-y

@tenzen-y
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 17, 2024
Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

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

Thank you!
/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 Oct 17, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 349bf9f82635964031b89b1094f32c5883f92094

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mruoss, tenzen-y

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 Oct 17, 2024
@mbobrovskyi
Copy link
Contributor

/hold

I tried to test with "project-foo-cluster-bar-kueue-controller-manager-metrics-service" and it's not working.

Error: INSTALLATION FAILED: clusterroles.rbac.authorization.k8s.io "kueue-project-foo-cluster-bar-kueue-controller-manager-metrics" already exists

@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 Oct 18, 2024
@mbobrovskyi
Copy link
Contributor

mbobrovskyi commented Oct 18, 2024

I think we need to add some e2e test case for helm.

@mimowo @tenzen-y WDYT?

@mimowo
Copy link
Contributor

mimowo commented Oct 18, 2024

+1 on e2e tests, feel free to open the issue and follow up. I guess they could have a dedicated run like mk, but we can discuss details later.

We often have issues with helm which are hard to see just by static code analysis. Thanks for checking.

@mruoss
Copy link
Author

mruoss commented Oct 18, 2024

I tried to test with "project-foo-cluster-bar-kueue-controller-manager-metrics-service" and it's not working.

Yeah okay, if the release name itself is longer than 63 chars, all resources are named the same (first 63 chars of the release name). I haven't seen any chart accounting for that, though. But one could change the order (start with the specific resource name and suffix it with the release name). Or obviously: truncate the release name to a max length instead of the resulting resource name...

I think we need to add some e2e test case for helm.

Agreed. Especially these bulk search-and-replace fixes don't come without risks... Chart tests would however already be a start.

@mbobrovskyi
Copy link
Contributor

mbobrovskyi commented Oct 18, 2024

Or obviously: truncate the release name to a max length instead of the resulting resource name...

We already do that:

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "kueue.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

@mruoss
Copy link
Author

mruoss commented Oct 18, 2024

Or obviously: truncate the release name to a max length instead of the resulting resource name...

We already do that https://github.com/kubernetes-sigs/kueue/blob/main/charts/kueue/templates/_helpers.tpl#L21.

I see. But it should be truncated to a length that is 63 - charlength(longsest_suffix) if you know what I mean. This would make the changes in this PR redundant. But it's harder to maintain.

@mbobrovskyi
Copy link
Contributor

mbobrovskyi commented Oct 18, 2024

Or obviously: truncate the release name to a max length instead of the resulting resource name...

We already do that https://github.com/kubernetes-sigs/kueue/blob/main/charts/kueue/templates/_helpers.tpl#L21.

I see. But it should be truncated to a length that is 63 - charlength(longsest_suffix) if you know what I mean. This would make the changes in this PR redundant. But it's harder to maintain.

Can we calculate charlength(longsest_suffix)?

@mruoss
Copy link
Author

mruoss commented Oct 18, 2024

Can we calculate charlength(longsest_suffix)?

I don't think you can do that globally in _helpers.tpl. You could probably do it in each resource's template...

@mbobrovskyi
Copy link
Contributor

mbobrovskyi commented Oct 18, 2024

Can we calculate charlength(longsest_suffix)?

I don't think you can do that globally in _helpers.tpl. You could probably do it in each resource's template...

We can probably calculate it in update-helm.sh when generating the templates, and then update longest_suffix_length in _helpers.tpl.

Copy link
Contributor

@alculquicondor alculquicondor left a comment

Choose a reason for hiding this comment

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

I'm not convinced that we should be doing this.
For one, it's a lot more (and repetitive) code to maintain. Maybe you can submit a PR to helm to support a method called resource-name-sanitize (or something along those lines) that can be used in templates.
Second, a user might still come and put invalid characters in their value.yaml file and not be able to install Kueue.

So I would categorize this as user-error unless helm provides some better mechanism to prevent this issues.

Comment on lines +21 to +22
- '{{ printf "%s-webhook-service.%s.svc" (include "kueue.fullname" .) .Release.Namespace | trunc 63 | trimSuffix "-" }}'
- '{{ printf "%s-webhook-service.%s.svc.%s" (include "kueue.fullname" .) .Release.Namespace .Values.kubernetesClusterDomain | trunc 63 | trimSuffix "-" }}'
Copy link
Contributor

Choose a reason for hiding this comment

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

would this actually work?

Doesn't it always have to finish in .svc or .svc.{ClusterDomain}?

Do we need to worry about length for dns names?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 12, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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
Copy link
Contributor

@mruoss: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kueue-verify-main 516f0b2 link true /test pull-kueue-verify-main
pull-kueue-test-tas-e2e-main 516f0b2 link true /test pull-kueue-test-tas-e2e-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. 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. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

6 participants