Thanks to visit codestin.com
Credit goes to github.com

Skip to content

draft: Validate 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

Draft
wants to merge 1 commit into
base: 4.19
Choose a base branch
from

Conversation

bernardodemarco
Copy link
Collaborator

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.

This PR proposes to restrict users from creating Kubernetes clusters whose names do not meet the following criteria:

  • Contain at most 43 characters;
  • Contain only lowercase alphanumeric characters or -;
  • Start with a letter; and,
  • End with an alphanumeric character.

The length requirement is defined as 43, because, in the worst case scenario, the node names will contain 43 characters (cluster name) + 9 characters (-control-) + 11 characters (hash), resulting in 63 characters in total.

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?

  • Verified that it is only possible to create Kubernetes clusters when the above-mentioned naming requirements are met.

@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

Attention: Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.

Project coverage is 15.17%. Comparing base (55c8138) to head (cef6250).

Files with missing lines Patch % Lines
...bernetes/cluster/KubernetesClusterManagerImpl.java 94.44% 1 Missing ⚠️
...KubernetesClusterResourceModifierActionWorker.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.19   #10778   +/-   ##
=========================================
  Coverage     15.16%   15.17%           
- Complexity    11332    11336    +4     
=========================================
  Files          5412     5412           
  Lines        475033   475041    +8     
  Branches      57963    57962    -1     
=========================================
+ Hits          72048    72068   +20     
+ Misses       394930   394916   -14     
- Partials       8055     8057    +2     
Flag Coverage Δ
uitests 4.29% <ø> (ø)
unittests 15.89% <89.47%> (+<0.01%) ⬆️

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
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.

3 participants