Skip to content

Commit 7bf056f

Browse files
committed
Volume name should respect restrictions
In foreman, the VM name may contain also the domain name. When setting this name as the volume name, running the VM fails with the following error: Warning FailedCreate 21s virtualmachine-controller Error creating pod: Pod "virt-launcher-vmi-multus-lqcwz" is invalid: spec.containers[0].name: Invalid value: "volumevmi-multus.example.com": a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?') Therefore the dots from FQDN VM name cannot be part of the volume name. The patch assumes the name without the domain should be sufficient.
1 parent 35f69aa commit 7bf056f

File tree

1 file changed

+5
-5
lines changed
  • lib/fog/compute/kubevirt/models

1 file changed

+5
-5
lines changed

lib/fog/compute/kubevirt/models/vms.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ def create(args = {})
5050
if image.nil? && pvc.nil?
5151
raise ::Fog::Kubevirt::Errors::ValidationError
5252
end
53-
54-
volumes = []
5553

54+
volumes = []
55+
volume_name = vm_name.gsub(/[._]+/,'-') + "disk-01"
5656
if !image.nil?
57-
volumes.push(:name => vm_name, :registryDisk => {:image => image})
57+
volumes.push(:name => volume_name, :registryDisk => {:image => image})
5858
else
59-
volumes.push(:name => vm_name, :persistentVolumeClaim => {:claimName => pvc})
59+
volumes.push(:name => volume_name, :persistentVolumeClaim => {:claimName => pvc})
6060
end
6161

6262
unless init.empty?
@@ -90,7 +90,7 @@ def create(args = {})
9090
:bus => "virtio"
9191
},
9292
:name => vm_name,
93-
:volumeName => vm_name
93+
:volumeName => volume_name
9494
}
9595
]
9696
},

0 commit comments

Comments
 (0)