-
Notifications
You must be signed in to change notification settings - Fork 52
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
Subclass Kubevirt InfraManager to separate Openshift Virtualization provider #264
Conversation
@agrare WIP - need to test with an Openshift Virtualization provider and clean up specs. Feel free to review what is here though |
@@ -3,6 +3,13 @@ | |||
class ManageIQ::Providers::Openshift::ContainerManager < ManageIQ::Providers::Kubernetes::ContainerManager | |||
DEFAULT_EXTERNAL_LOGGING_ROUTE_NAME = "logging-kibana-ops".freeze | |||
|
|||
has_one :infra_manager, |
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.
Does it makes sense for this to just live in the base class, or is this intentionally overriding the class name?
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.
This is here because we have to override the class_name to be Openshift::InfraManager so the correct class gets created
supports :provisioning | ||
|
||
def self.ems_type | ||
@ems_type ||= "openshift".freeze |
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.
I think this has to be different than the container manager, so maybe something like openshift_virt
or openshift_infra
?
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.
👍 openshift_infra would be good (OpenStack undercloud/InfraManager is openstack_infra)
# @return [ManageIQ::Providers::Kubevirt::InfraManager] The manager. | ||
# | ||
def manager | ||
@manager ||= ManageIQ::Providers::Openshift::InfraManager.find(@cfg[:ems_id]) |
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.
I'm surprised so much of this overriding is necessary. Makes me wonder if there's a better way, such as providing a method like manageiq_class
, which returns ManageIQ::Providers::Openshift::InfraManager
, and then the actual logic would be something like
@manager ||= manager_class.find(@cfg[:ems_id])
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.
This is the simple example of course - the same comment really applies to all of the methods in this file.
Very cool! I like that we didn't need a new repository, and it's just included in the openshift repo. |
One other thing I think we need is the form for adding a provider needs to change so you can only select OpenShift Virtualization under the Virtualization tab. |
class ManageIQ::Providers::OpenShift::InfraManager < ManageIQ::Providers::Kubevirt::InfraManager | ||
belongs_to :parent_manager, | ||
:foreign_key => :parent_ems_id, | ||
:class_name => "ManageIQ::Providers::ContainerManager" |
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.
This should be ManageIQ::Providers::Openshift::ContainerManager
, then you can add an invere_of :infra_manager
delegate :authentication_check, | ||
:authentication_for_summary, | ||
:authentication_token, | ||
:authentications, | ||
:endpoints, | ||
:default_endpoint, | ||
:zone, | ||
:to => :parent_manager, | ||
:allow_nil => true |
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.
I think all of these can be inherited from the base class
end | ||
|
||
def authentication_for_providers | ||
authentications.where(:authtype => :openshift) |
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 necessarily for this PR but if most of these overrides are for :authtype => :openshift
we could use e.g. a DEFAULT_AUTH_TYPE constant and switch to that in the base Kubevirt class
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.
e.g.
def connect(opts = {})
# Get the authentication token:
token = opts[:token] || authentication_token(:kubevirt)
If we changed that to authentication_token(default_authentication_type)
# | ||
def connect(opts = {}) | ||
# Get the authentication token: | ||
token = opts[:token] || authentication_token(:openshift) |
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.
This is a good example, this whole method is probably copy&paste except for this :openshift
here
def virtualization_endpoint | ||
connection_configurations.kubevirt.try(:endpoint) | ||
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.
This looks identical to the base class
supports :provisioning do | ||
if ext_management_system | ||
ext_management_system.unsupported_reason(:provisioning) | ||
else | ||
_('not connected to ems') | ||
end | ||
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.
Is this different from the base class?
Not sure if you want to do this in another PR but we should make the "virtualization" endpoint dropdown option (https://github.com/ManageIQ/manageiq-providers-kubernetes/blob/master/app/models/manageiq/providers/kubernetes/container_manager.rb#L331-L342) in the Openshift::ContainerManager subclass only show "Openshift Virtualization" |
I think we should get some VCR specs in here, kubevirt has some weird mocking that they do for their refresher specs I'm not sure I want to copy what they do but a "simple" refresher spec doing a full refresh should be sufficient. |
a7ad2c4
to
6918d9e
Compare
@@ -21,6 +28,20 @@ def self.event_monitor_class | |||
ManageIQ::Providers::Openshift::ContainerManager::EventCatcher | |||
end | |||
|
|||
def virtualization_options |
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.
def virtualization_options | |
def self.virtualization_options |
edce97e
to
7236e7c
Compare
@@ -0,0 +1,2 @@ | |||
class ManageIQ::Providers::Openshift::InfraManager::RefreshWorker < ManageIQ::Providers::Kubevirt::InfraManager::RefreshWorker |
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.
We don't need to inherit anything from the Kubevirt RefreshWorker, and doing this nests the settings under kubevirt so we typically don't do this for simple workers (e.g. see Openshift::ContainerManager::RefreshWorker it doesn't < Kubernetes)
class ManageIQ::Providers::Openshift::InfraManager::RefreshWorker < ManageIQ::Providers::Kubevirt::InfraManager::RefreshWorker | |
class ManageIQ::Providers::Openshift::InfraManager::RefreshWorker < ManageIQ::Providers::BaseManager::RefreshWorker |
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.
You also need to add a settings section for this new worker to config/settings.yml
diff --git a/config/settings.yml b/config/settings.yml
index dc097791..448ed39b 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -33,3 +33,4 @@
:ems_metrics_collector_worker_openshift: {}
:ems_refresh_worker:
:ems_refresh_worker_openshift: {}
+ :ems_refresh_worker_openshift_infra: {}
Without this when running the full evmserverd it'll fail to start up:
adam@workstation:~/src/manageiq/manageiq$ ruby lib/workers/bin/evm_server.rb
** ManageIQ master, codename: Spassky
/home/grare/adam/src/manageiq/manageiq/app/models/miq_worker.rb:224:in `block in fetch_worker_settings_from_options_hash': Missing config section ems_refresh_worker_openshift_infra (RuntimeError)
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.
NOTE we'll also need to add .service and .target files for the new openshift-infra-refresh worker in the systemd/ directory here (specs will catch this but just want to head it off now)
When running the full worker I see the following error:
When using |
7236e7c
to
42365f0
Compare
From Pull Request: ManageIQ/manageiq-providers-openshift#264
0b05389
to
3cbdac2
Compare
3cbdac2
to
1a61429
Compare
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.
Should this live in manageiq-decorators? I prefer it in the plugin class, but wasn't sure if it was required over there.
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.
On that note, in manageiq-decorators we use symlinks when there are multiple images that point to the same thing, so this could just be a symlink over there.
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.
1a61429
to
994682d
Compare
Checked commit nasark@994682d with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint |
From Pull Request: ManageIQ/manageiq-providers-openshift#264
@agrare @Fryguy cross repo tests are green ManageIQ/manageiq-cross_repo-tests#911 |
parser_type = if target_is_vm?(target) | ||
"PartialTargetRefresh" | ||
else | ||
"FullRefresh" | ||
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.
Really minor for a follow-up but something this simple taking up 5 lines could be a ternary operator instead on one line
parser_type = if target_is_vm?(target) | |
"PartialTargetRefresh" | |
else | |
"FullRefresh" | |
end | |
parser_type = target_is_vm?(target) ? "PartialTargetRefresh" : "FullRefresh" |
I'm not usually a "hey you can turn this big multi-step thing into one looong line" guy but this is pretty straightforward
if !ems.kind_of?(EmsInfra) | ||
super | ||
else |
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.
We could also return super unless ems.kind_of?(EmsInfra)
so the entire method isn't just one if/else block.
if !ems.kind_of?(EmsInfra) | ||
super | ||
else |
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.
Same here,
if !ems.kind_of?(EmsInfra) | |
super | |
else | |
return super unless ems.kind_of?(EmsInfra) |
collector = if target_is_vm?(target) | ||
collector_class.new(ems, target) | ||
else | ||
collector_class.new(ems, ems) | ||
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.
If this is the same collector class I wonder if we could handle this in the initialize there, e.g. target = ems unless target.kind_of?(Vm) or something like that
end | ||
end | ||
|
||
it 'works correctly with one node' do |
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.
This looks a little out of place, something like "Performs a full refresh" would probably be better.
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.
On that note, a targeted refresh spec would be a good addition in the future
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 good some minor things that can be follow-ups
Backported to
|
Subclass Kubevirt InfraManager to separate Openshift Virtualization provider (cherry picked from commit 2d66f57)
We can subclass
Kubevirt::InfraManager
to create a separate provider for Openshift VirtualizationDepends on:
@miq-bot assign @agrare
@miq-bot add_label enhancement, radjabov/yes?
@miq-bot add_reviewer @agrare