Skip to content

Commit

Permalink
Introduce virtualization manager
Browse files Browse the repository at this point in the history
In order to support kubevirt as a secondary manager of the
openshift/kubevirt provider, a new mixin is added to represent that
capability.
  • Loading branch information
masayag committed Jan 14, 2018
1 parent 66bad00 commit 893e6bf
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
16 changes: 16 additions & 0 deletions app/models/manageiq/providers/container_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ContainerManager < BaseManager

include AvailabilityMixin
include HasMonitoringManagerMixin
include HasVirtualizationManagerMixin
include SupportsFeatureMixin

has_many :container_nodes, -> { active }, :foreign_key => :ems_id
Expand Down Expand Up @@ -46,6 +47,11 @@ class ContainerManager < BaseManager
has_many :all_container_images, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerImage"
has_many :all_container_nodes, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerNode"

has_one :virtualization_manager,
:foreign_key => :parent_ems_id,
:class_name => "ManageIQ::Providers::Kubevirt::InfraManager",
:autosave => true,
:dependent => :destroy

virtual_column :port_show, :type => :string

Expand Down Expand Up @@ -92,5 +98,15 @@ def validate_authentication_status
def port_show
port.to_s
end

def endpoint_created(role)
monitoring_endpoint_created(role) if respond_to?(:monitoring_endpoint_created)
virtualization_endpoint_created(role) if respond_to?(:virtualization_endpoint_created)
end

def endpoint_destroyed(role)
monitoring_endpoint_destroyed(role) if respond_to?(:monitoring_endpoint_destroyed)
virtualization_endpoint_destroyed(role) if respond_to?(:virtualization_endpoint_destroyed)
end
end
end
4 changes: 2 additions & 2 deletions app/models/mixins/has_monitoring_manager_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module HasMonitoringManagerMixin
extend ActiveSupport::Concern

def endpoint_created(role)
def monitoring_endpoint_created(role)
if role == "prometheus_alerts" && monitoring_manager.nil?
monitoring_manager = ensure_monitoring_manager
monitoring_manager.save
end
end

def endpoint_destroyed(role)
def monitoring_endpoint_destroyed(role)
if role == "prometheus_alerts" && monitoring_manager.present?
# TODO: if someone deletes the alerts endpoint and then quickly readds it they can end up without a manager.
monitoring_manager.destroy_queue
Expand Down
29 changes: 29 additions & 0 deletions app/models/mixins/has_virtualization_manager_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module HasVirtualizationManagerMixin
extend ActiveSupport::Concern

def virtualization_endpoint_created(role)
if role == "kubevirt" && virtualization_manager.nil?
virtualization_manager = ensure_virtualization_manager
virtualization_manager.save
end
end

def virtualization_endpoint_destroyed(role)
if role == "kubevirt" && virtualization_manager.present?
virtualization_manager.destroy_queue
end
end

private

def ensure_virtualization_manager
if virtualization_manager.nil?
build_virtualization_manager(:parent_manager => self,
:name => "#{name} Virtualization Manager",
:zone_id => zone_id,
:provider_region => provider_region)
end

virtualization_manager
end
end

0 comments on commit 893e6bf

Please sign in to comment.