-
Notifications
You must be signed in to change notification settings - Fork 29
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
KubeVirt Events Capture #256
Conversation
WIP need to:
@agrare event catching logic etc works so feel free to review in the meantime |
class ManageIQ::Providers::Kubevirt::InfraManager::KubernetesEventMonitor < ManageIQ::Providers::Kubernetes::ContainerManager::KubernetesEventMonitor | ||
def inventory | ||
# :service is required to handle also the case where @ems is Openshift | ||
@inventory ||= @ems.parent_manager.connect(:service => ManageIQ::Providers::Kubernetes::ContainerManager.ems_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using k8s client since fog-kubevirt
doesn't have an events API to my knowledge
app/models/manageiq/providers/kubevirt/infra_manager/kubernetes_event_monitor.rb
Show resolved
Hide resolved
def extract_event_data(event) | ||
event_data = { | ||
:timestamp => event.object.lastTimestamp, | ||
:kind => event.object.involvedObject.kind, | ||
:name => event.object.involvedObject.name, | ||
:namespace => event.object.involvedObject.namespace, | ||
:reason => event.object.reason, | ||
:message => event.object.message, | ||
:uid => event.object.involvedObject.uid, | ||
:event_uid => event.object.metadata.uid, | ||
} | ||
|
||
unless event.object.involvedObject.fieldPath.nil? | ||
event_data[:fieldpath] = event.object.involvedObject.fieldPath | ||
end | ||
|
||
event_type_prefix = event_data[:kind].upcase | ||
|
||
# Handle event data for specific entities | ||
if event_data[:kind] == "VirtualMachine" || event_data[:kind] == "VirtualMachineKind" | ||
event_data[:vm_name] = event_data[:name] | ||
end | ||
|
||
event_data[:event_type] = "#{event_type_prefix}_#{event_data[:reason].upcase}" | ||
|
||
event_data | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think all of this should live in the EventParser, the purpose of that class is to take the "native" event object and normalize it to our ems_event table
ENABLED_EVENTS = { | ||
'VirtualMachine' => %w(Created Started Migrated SuccessfulCreate SuccessfulDelete ShuttingDown Killing), | ||
'VirtualMachineInstance' => %w(Created Started Migrated SuccessfulCreate SuccessfulDelete ShuttingDown Killing) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR but as a follow-up we'll want to create event handler objects in manageiq-content for these so that customers can hook into these events for policy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:timestamp => event.object.lastTimestamp, | ||
:message => event.object.message, | ||
:container_namespace => event.object.involvedObject.namespace, | ||
:full_data => event.to_h, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing to double check here, event is a RecursiveOpenStruct can you confirm that event.to_h converts the nested values to simple hash also and not ROS objects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it does
(byebug) pp event_hash[:full_data]
{:type=>"MODIFIED",
:object=>
{:kind=>"Event",
:apiVersion=>"v1",
:metadata=>
{:name=>"centos-stream9-scarlet-duck-44.1807437ad1a2db12",
:namespace=>"miq",
:uid=>"cf6dc3a5-3223-4d86-b2cf-531fef74d25e",
:resourceVersion=>"32920483",
:creationTimestamp=>"2024-11-12T15:52:56Z",
:managedFields=>
[{:manager=>"virt-handler",
:operation=>"Update",
:apiVersion=>"v1",
:time=>"2024-11-12T16:16:50Z",
:fieldsType=>"FieldsV1",
:fieldsV1=>{:"f:count"=>{}, :"f:firstTimestamp"=>{}, :"f:involvedObject"=>{}, :"f:lastTimestamp"=>{}, :"f:message"=>{}, :"f:reason"=>{}, :"f:reportingComponent"=>{}, :"f:reportingInstance"=>{}, :"f:source"=>{:"f:component"=>{}, :"f:host"=>{}}, :"f:type"=>{}}}]},
:involvedObject=>{:kind=>"VirtualMachineInstance", :namespace=>"miq", :name=>"centos-stream9-scarlet-duck-44", :uid=>"b80fa3c9-c7c2-4c5c-9201-12ae7b6da1c8", :apiVersion=>"kubevirt.io/v1", :resourceVersion=>"32904613"},
:reason=>"Migrated",
:message=>"EvictionStrategy is set but vmi is not migratable; cannot migrate VMI: PVC centos-stream9-scarlet-duck-44 is not shared, live migration requires that all PVCs must be shared (using ReadWriteMany access mode)",
:source=>{:component=>"virt-handler", :host=>"<worker>"},
:firstTimestamp=>"2024-11-12T15:52:56Z",
:lastTimestamp=>"2024-11-12T16:16:50Z",
:count=>11,
:type=>"Warning",
:eventTime=>nil,
:reportingComponent=>"virt-handler",
:reportingInstance=>"<worker>"}}
@@ -0,0 +1,25 @@ | |||
class ManageIQ::Providers::Kubevirt::InfraManager::EventParser | |||
def self.event_to_hash(event, ems_id = nil, source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added source
as a parameter to differentiate between Kubevirt and OSV. Since OSV will be using this same parser class
end | ||
|
||
def queue_event(event) | ||
event_hash = ManageIQ::Providers::Kubevirt::InfraManager::EventParser.event_to_hash(event, @cfg[:ems_id], @ems.emstype.upcase) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nasark I think we should do @ems.class::EventParser
here so that if we were to make any Openshift specific changes we could do it in an Openshift::InfraManager::EventParser
subclass
@nasark It'd be good to add some spec tests for the EventParser so take an example payload for each of the events and show what they resulting parsed hash looks like |
Events collection for VMs on kubevirt
Needed for:
@miq-bot assign @agrare
@miq-bot add_label enhancement
@miq-bot add_reviewer @Fryguy, @agrare