-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from nasark/vm_events
KubeVirt Events Capture
- Loading branch information
Showing
7 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
app/models/manageiq/providers/kubevirt/infra_manager/event_catcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
34 changes: 34 additions & 0 deletions
34
app/models/manageiq/providers/kubevirt/infra_manager/event_catcher/runner.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
app/models/manageiq/providers/kubevirt/infra_manager/event_parser.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
6 changes: 6 additions & 0 deletions
6
app/models/manageiq/providers/kubevirt/infra_manager/kubernetes_event_monitor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
systemd/manageiq-providers-kubevirt_infra_manager_event_catcher.target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Unit] | ||
PartOf=manageiq.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |