Skip to content

Commit

Permalink
Merge pull request #256 from nasark/vm_events
Browse files Browse the repository at this point in the history
KubeVirt Events Capture
  • Loading branch information
agrare committed Nov 15, 2024
2 parents 4125212 + 82e947b commit 6bee2e6
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ManageIQ::Providers::Kubevirt::InfraManager::EventCatcher < ManageIQ::Providers::BaseManager::EventCatcher
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class ManageIQ::Providers::Kubevirt::InfraManager::EventCatcher::Runner < ManageIQ::Providers::BaseManager::EventCatcher::Runner
include ManageIQ::Providers::Kubernetes::ContainerManager::EventCatcherMixin

ENABLED_EVENTS = {
'VirtualMachine' => %w(Created Started Migrated SuccessfulCreate SuccessfulDelete ShuttingDown),
'VirtualMachineInstance' => %w(Created Started Migrated SuccessfulCreate SuccessfulDelete ShuttingDown)
}

def event_monitor_handle
@event_monitor_handle ||= ManageIQ::Providers::Kubevirt::InfraManager::KubernetesEventMonitor.new(@ems)
end

def queue_event(event)
event_hash = @ems.class::EventParser.event_to_hash(event, @cfg[:ems_id], @ems.emstype.upcase)

if event_hash[:timestamp].nil?
_log.info("#{log_prefix} Skipping invalid event [#{event_hash[:event_type]}]")
return
end

_log.info("#{log_prefix} Queuing event [#{event_hash}]")

EmsEvent.add_queue('add', @cfg[:ems_id], event_hash)
end

def filtered?(event)
kind = event.object.involvedObject.kind
reason = event.object.reason
event_type = "#{kind.upcase}_#{reason.upcase}"

supported_reasons = ENABLED_EVENTS[kind] || []
supported_reasons.exclude?(reason) || filtered_events.include?(event_type)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class ManageIQ::Providers::Kubevirt::InfraManager::EventParser
def self.event_to_hash(event, ems_id = nil, source)
_log.debug("ems_id: [#{ems_id}] event: [#{event.inspect}]")

kind = event.object.involvedObject.kind
event_hash = {
:event_type => "#{kind.upcase}_#{event.object.reason.upcase}",
:source => source,
:timestamp => event.object.lastTimestamp,
:message => event.object.message,
:container_namespace => event.object.involvedObject.namespace,
:full_data => event.to_h,
:ems_id => ems_id,
:ems_ref => event.object.metadata.uid,
}

if ["VirtualMachine", "VirtualMachineInstance"].include?(kind)
event_hash[:vm_name] = event.object.involvedObject.name
event_hash[:vm_ems_ref] = event.object.involvedObject.uid
end

event_hash
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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)
end
end
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
:event_groups:
:workers:
:worker_base:
:event_catcher:
:event_catcher_kubevirt:
:poll: 1.seconds
:queue_worker_base:
:ems_refresh_worker:
:ems_refresh_worker_kubevirt: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Unit]
PartOf=manageiq.target
13 changes: 13 additions & 0 deletions systemd/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
PartOf=manageiq-providers-kubevirt_infra_manager_event_catcher.target
[Install]
WantedBy=manageiq-providers-kubevirt_infra_manager_event_catcher.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb ManageIQ::Providers::Kubevirt::InfraManager::EventCatcher --heartbeat --guid=%i
User=manageiq
Restart=no
Type=notify
Slice=manageiq-providers-kubevirt_infra_manager_event_catcher.slice

0 comments on commit 6bee2e6

Please sign in to comment.