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

MTV-1744 | Allow dots in the VM names #1281

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

Conversation

mnecas
Copy link
Member

@mnecas mnecas commented Dec 19, 2024

Issue:
Right now we are not allowing to keep the VM names which have the dots in the name but we replace the dots with dashes.

Fix:
Use the IsDNS1123Subdomain validation instead of IsDNS1123Label and ignore the dots in the replacemnet of the new name.

Ref:
https://issues.redhat.com/browse/MTV-1744

Issue:
Right now we are not allowing to keep the VM names which have the dots
in the name but we replace the dots with dashes.

Fix:
Use the IsDNS1123Subdomain validation instead of IsDNS1123Label and
ignore the dots in the replacemnet of the new name.

Signed-off-by: Martin Necas <mnecas@redhat.com>
@mnecas mnecas requested a review from yaacov as a code owner December 19, 2024 13:37
@@ -33,7 +33,7 @@ func (r *KubeVirt) changeVmNameDNS1123(vmName string, vmNamespace string) (gener

// changes VM name to match DNS1123 RFC convention.
func changeVmName(currName string) string {
var underscoreExcluded = regexp.MustCompile("[_.]")
var underscoreExcluded = regexp.MustCompile("[_]")
Copy link
Member

@yaacov yaacov Dec 19, 2024

Choose a reason for hiding this comment

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

we also need to replace or remove "." if it is in the start or end of the name

https://github.com/kubernetes/apimachinery/blob/master/pkg/util/validation/validation.go#L206

Copy link
Member Author

Choose a reason for hiding this comment

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

ahh yeah good point!

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm that's get tricky

Copy link
Member

Choose a reason for hiding this comment

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

remove the "." if they are in the start of end ?

@fabiand
Copy link
Contributor

fabiand commented Jan 23, 2025

@mnecas is this something we can close before 2.8.0?

@fabiand
Copy link
Contributor

fabiand commented Jan 23, 2025

Does kube permit dots in object names?

@yaacov
Copy link
Member

yaacov commented Jan 23, 2025

Does kube permit dots in object names?

contain only lowercase alphanumeric characters, '-' or '.'
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names

It's label with dots
const dns1123SubdomainFmt string = dns1123LabelFmt + "(\\." + dns1123LabelFmt + ")*"
https://github.com/kubernetes/apimachinery/blob/master/pkg/util/validation/validation.go#L206

@fabiand
Copy link
Contributor

fabiand commented Jan 23, 2025

Thanks, so what we are saying: Oject names must not contain dots.

Right?

@yaacov
Copy link
Member

yaacov commented Jan 23, 2025

Oject names must not contain dots ?

labels must not contain dots, names can contain dots but not at the begining or end, for example:

yzamir@fedora:~$ kubectl create configmap my-config --from-literal=env=production --from-literal=version=1.0
configmap/my-config created

yzamir@fedora:~$ kubectl create configmap my.config --from-literal=env=production --from-literal=version=1.0
configmap/my.config created

yzamir@fedora:~$ kubectl create configmap .my.config --from-literal=env=production --from-literal=version=1.0
error: failed to create configmap: ConfigMap ".my.config" is invalid: metadata.name: Invalid value: ".my.config": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')

@fabiand
Copy link
Contributor

fabiand commented Jan 29, 2025

The name of a Pod must be a valid DNS subdomain value, but this can produce unexpected results for the Pod hostname. For best compatibility, the name should follow the more restrictive rules for a DNS label.

From https://kubernetes.io/docs/concepts/workloads/pods/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants