Skip to content

Normalize naming of Kubernetes clusters #10778

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 7 commits into
base: 4.19
Choose a base branch
from

Conversation

bernardodemarco
Copy link
Collaborator

@bernardodemarco bernardodemarco commented Apr 25, 2025

Description

Kubernetes has naming conventions for some type of resources. It requires, for instance, that some of them must:

  • contain at most 63 characters;
  • contain only lowercase alphanumeric characters or -;
  • start with an alphabetic character; and,
  • end with an alphanumeric character.

More information regarding Kubernetes naming constraints can be found on its Object Names and IDs documentation section.

Apache CloudStack names the control and worker cluster nodes using the following format: <cluster-name> + <"control" | "node"> + <hash>. When generating the names of the nodes, firstly, the cluster name is normalized, in order to meet the Kubernetes naming requirements:

protected String getKubernetesClusterNodeNamePrefix() {
String prefix = kubernetesCluster.getName();
if (!NetUtils.verifyDomainNameLabel(prefix, true)) {
prefix = prefix.replaceAll("[^a-zA-Z0-9-]", "");
if (prefix.length() == 0) {
prefix = kubernetesCluster.getUuid();
}
prefix = "k8s-" + prefix;
}
if (prefix.length() > 40) {
prefix = prefix.substring(0, 40);
}
return prefix;
}

However, not all required normalization operations are performed. When a Kubernetes cluster contains uppercase letters in its name, for instance, the static method NetUtils.verifyDomainLabel returns true (it verifies the domain name label in a case-insensitive manner). Thus, the uppercase letters are not removed from the string (prefix.replaceAll("[^a-zA-Z0-9-]", "") is not executed) and the Kubernetes nodes end up with names containing uppercase letters. As a consequence of that, some inconsistencies when consuming the Kubernetes services are faced, because Kubernetes is not able to properly identify its nodes.

Therefore, this PR applies all the required normalization steps to Kubernetes cluster names to always meet the above-mentioned naming requirements. When required, unsupported characters are removed, names are truncated and converted to lower case. Unit tests have been implemented to cover all possible normalization scenarios.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

  • Manually reproduced the unit tests scenarios

@bernardodemarco
Copy link
Collaborator Author

@blueorangutan package

@blueorangutan
Copy link

@bernardodemarco a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

Copy link

codecov bot commented Apr 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 15.18%. Comparing base (55c8138) to head (4fae561).
Report is 40 commits behind head on 4.19.

Additional details and impacted files
@@             Coverage Diff              @@
##               4.19   #10778      +/-   ##
============================================
+ Coverage     15.16%   15.18%   +0.01%     
- Complexity    11332    11368      +36     
============================================
  Files          5412     5416       +4     
  Lines        475033   475887     +854     
  Branches      57963    58091     +128     
============================================
+ Hits          72048    72260     +212     
- Misses       394930   395540     +610     
- Partials       8055     8087      +32     
Flag Coverage Δ
uitests 4.28% <ø> (-0.02%) ⬇️
unittests 15.91% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@weizhouapache
Copy link
Member

good idea.
This will avoid some issues caused by the name of k8s nodes.
However, I suggest to try our best to generate the name matching the convention, instead of throwing an exception.
For example, lower the upper case, replace or remove unsupported chars, truncate the cluster name

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 13185

@bernardodemarco
Copy link
Collaborator Author

@weizhouapache yes, this approach would be much better from a UX perspective. I'll mark this PR as draft while I refactor it.

@bernardodemarco bernardodemarco marked this pull request as draft April 28, 2025 11:54
@bernardodemarco bernardodemarco changed the title Validate naming of Kubernetes clusters draft: Validate naming of Kubernetes clusters Apr 28, 2025
@bernardodemarco
Copy link
Collaborator Author

@blueorangutan package

@blueorangutan
Copy link

@bernardodemarco a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 13499

@DaanHoogland
Copy link
Contributor

@blueorangutan test

@blueorangutan
Copy link

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan
Copy link

[SF] Trillian test result (tid-13404)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 47185 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10778-t13404-kvm-ol8.zip
Smoke tests completed. 133 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

Copy link
Member

@weizhouapache weizhouapache left a comment

Choose a reason for hiding this comment

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

overall lgtm

not tested

@bernardodemarco bernardodemarco changed the title draft: Validate naming of Kubernetes clusters Normalize naming of Kubernetes clusters May 27, 2025
@bernardodemarco bernardodemarco marked this pull request as ready for review May 27, 2025 19:57
@bernardodemarco
Copy link
Collaborator Author

@blueorangutan package

@blueorangutan
Copy link

@bernardodemarco a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 13528

@bernardodemarco
Copy link
Collaborator Author

@weizhouapache @Pearl1594, can we run the CI again for this one?

@bernardodemarco
Copy link
Collaborator Author

@julien-vaz, could you test this one, please?

@sureshanaparti sureshanaparti modified the milestones: 4.19.3, 4.19.4 Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants