Add IP address sync for KubeVirt compute resource#174
Add IP address sync for KubeVirt compute resource#174archanaserver wants to merge 1 commit intotheforeman:masterfrom
Conversation
|
Importing a VM currently throws an error: |
4b95676 to
72a5fb9
Compare
|
|
||
| def provided_attributes | ||
| { :uuid => :name, :mac => :mac } | ||
| { :uuid => :name, :mac => :mac, :ip => :ip_addresses } |
There was a problem hiding this comment.
Slightly off topic: other CRs use super.merge({the: hash}): https://github.com/search?q=org%3Atheforeman%20%22def%20provided_attributes%22&type=code
Should we do the same here?
| def ip_addresses | ||
| [interfaces&.first&.ip_address] | ||
| [ip_address].compact | ||
| end |
There was a problem hiding this comment.
two questions:
- we only need one address, so can't we use the
ip_addressattribute directly? - in my tests (on our internal CNV cluster), the attribute returned an IPv6 address, does foreman cope with that?
There was a problem hiding this comment.
2: nope, I got a
2026-01-20T10:20:39 [I|app|b34e2035] Backtrace for 'Rolling back due to exception during save' error (ActiveRecord::ValueTooLong): PG::StringDataRightTruncation: ERROR: value too long for type character varying(15)
There was a problem hiding this comment.
With :ip6 => :ip_address it worked (but I guess we should rather have some methods that return the address only of the right type), but then the VM deployment was blocked until I manually booted the VM in CNV as in https://github.com/theforeman/foreman/blob/47772af31368013686e28b9f626aca26af241895/app/models/concerns/orchestration/compute.rb#L63-L84 the "acquire ip" step happens before the "power on" step, but it seems a VM in CNV doesn't have an IP before it wasn't powered on?
There was a problem hiding this comment.
def ip
Net::Validations.validate_ip(ip_address) ? ip_address : nil
end
def ip6
Net::Validations.validate_ip6(ip_address) ? ip_address : nil
endand then in provided_attributes: :ip => :ip, :ip6 => :ip6
There was a problem hiding this comment.
With
:ip6 => :ip_addressit worked (but I guess we should rather have some methods that return the address only of the right type), but then the VM deployment was blocked until I manually booted the VM in CNV as in https://github.com/theforeman/foreman/blob/47772af31368013686e28b9f626aca26af241895/app/models/concerns/orchestration/compute.rb#L63-L84 the "acquire ip" step happens before the "power on" step, but it seems a VM in CNV doesn't have an IP before it wasn't powered on?
Ah so the timing issue you mentioned (IP acquisition before power on) is seems interesting to me. In my testing with pod network specifically, VM started automatically (I set "start" => "1" in create_vm), so it had an IP by the time orchestration checked.
But you're right that if the VM isn't auto-started, orchestration might try to get IP before the VM is running. Thisi believe seems like a broader orchestration issue for KubeVirt (not specific to this PR), but worth noting.
There was a problem hiding this comment.
Yup, I see we inherently can't use the provided_attributes since Kubevirt does not give an IP address before the machine boots.
Maybe we should change the task execution order, or add another step in the orchestration. But the current solution won't really work.
I propose closing this PR, and getting back to the drawing board to understand how and when we should get an IP address from the compute resource.
CC @ekohl
There was a problem hiding this comment.
Foreman's compute orchestration: https://github.com/theforeman/foreman/blob/3ec941eff26ef521ecf1bd2b63cc364a13bd79a9/app/models/concerns/orchestration/compute.rb#L63-L84
The bit that receives the IP address (https://github.com/theforeman/foreman/blob/3ec941eff26ef521ecf1bd2b63cc364a13bd79a9/app/models/concerns/orchestration/compute.rb#L70-L73) is before the machine is actually turned on (https://github.com/theforeman/foreman/blob/3ec941eff26ef521ecf1bd2b63cc364a13bd79a9/app/models/concerns/orchestration/compute.rb#L80-L83). Note priority 4 vs priority 1000. It can even be guarded by :start to not even start the VM up.
What you can do is introduce new provided attributes like :late_ip & :late_ip6 and queue a task after the VM is started:
if compute_attributes && compute_attributes[:start] == '1'
queue.create(:name => _("Power up compute instance %s") % self, :priority => 1000,
:action => [self, :setComputePowerUp])
if compute_provides?(:late_ip) || compute_provides?(:late_ip6)
queue.create(:name => _("Acquire IP addresses for %s") % self, :priority => 1001,
:action => [self, :setLateComputeIP])
end
endI'm not sure if 1001 is the right priority, just some thoughts.
There was a problem hiding this comment.
@evgeni asked what value this brings and that was an excellent point. Having priority 1001 means it can't be used to create DNS records, which has priority 10 (https://github.com/theforeman/foreman/blob/3ec941eff26ef521ecf1bd2b63cc364a13bd79a9/app/models/concerns/orchestration/dns.rb#L63-L71).
Realistically, I don't think KubeVirt can provide the IP address and we can instead rely on fact reporting like Puppet, subman, or Ansible already.
72a5fb9 to
f714762
Compare
f714762 to
146ea6d
Compare
|
Because of #174 (comment) I don't think KubeVirt can provide the attribute at all and I'm closing this as something we can't do. |
added
:ip => :ip_addressesto provided_attributes to enableforeman's orchestration to sync IPs from VMs.
also, this fix works in conjunction with network name sanitization (PR #172 )