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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/controller/plan/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ func (r *Migration) execute(vm *plan.VMStatus) (err error) {
err = nil
break
}
if errs := k8svalidation.IsDNS1123Label(vm.Name); len(errs) > 0 {
if errs := k8svalidation.IsDNS1123Subdomain(vm.Name); len(errs) > 0 {
vm.NewName, err = r.kubevirt.changeVmNameDNS1123(vm.Name, r.Plan.Spec.TargetNamespace)
if err != nil {
r.Log.Error(err, "Failed to update the VM name to meet DNS1123 protocol requirements.")
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/plan/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (r *Reconciler) validateTargetNamespace(plan *api.Plan) (err error) {
plan.Status.SetCondition(newCnd)
return
}
if len(k8svalidation.IsDNS1123Label(plan.Spec.TargetNamespace)) > 0 {
if len(k8svalidation.IsDNS1123Subdomain(plan.Spec.TargetNamespace)) > 0 {
newCnd.Reason = NotValid
plan.Status.SetCondition(newCnd)
}
Expand Down Expand Up @@ -491,7 +491,7 @@ func (r *Reconciler) validateVM(plan *api.Plan) error {
}
return liberr.Wrap(pErr)
}
if len(k8svalidation.IsDNS1123Label(ref.Name)) > 0 {
if len(k8svalidation.IsDNS1123Subdomain(ref.Name)) > 0 {
nameNotValid.Items = append(nameNotValid.Items, ref.String())
}
if _, found := setOf[ref.ID]; found {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/plan/vm_name_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?

var nameExcludeChars = regexp.MustCompile("[^a-z0-9-]")

newName := strings.ToLower(currName)
Expand Down
Loading