-
Notifications
You must be signed in to change notification settings - Fork 898
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
Adding ContainerImage subclasses #15386
Adding ContainerImage subclasses #15386
Conversation
39a30e4
to
8a917b6
Compare
d290442
to
dac108a
Compare
def change | ||
add_column :container_images, :type, :string | ||
ContainerImage.update_all(:type => "OpenshiftContainerImage") | ||
ContainerImage.where(:command => nil).update_all(:type => "BasicContainerImage") |
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.
- These 2 data migration bits cannot be in a
change
method as they are not reversible. Please split this into an up and a down. - Please wrap data migrations in a say_with_time like the other data migrations
- Data migrations must have a migration spec
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.
👍
add_column :container_images, :type, :string | ||
ContainerImage.update_all(:type => "OpenshiftContainerImage") | ||
ContainerImage.where(:command => nil).update_all(:type => "BasicContainerImage") | ||
add_column :container_images, :ems_ref, :string |
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.
Why is this here twice?
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.
First column adds type
and here it adds ems_ref
. they are different.
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.
Ah thank you...totally misread. Can you just point those two add_columns together up above?
@@ -0,0 +1,13 @@ | |||
class OpenshiftContainerImage < ContainerImage |
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 seems openshift specific and probably should go into the openshift provider gem itself.
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.
👍
app/models/miq_action.rb
Outdated
@@ -742,7 +742,7 @@ def action_container_image_annotate_deny_execution(action, rec, inputs) | |||
return | |||
end | |||
|
|||
unless rec.digest.present? | |||
unless rec.kind_of?(OpenshiftContainerImage) |
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.
Since the original code is OpenShift specific already, maybe we can let this go, but it would be preferable if we could avoid provider-specifics. @simon3z Thoughts?
@@ -308,6 +308,7 @@ def save_container_images_inventory(ems, hashes, target = nil) | |||
|
|||
hashes.each do |h| | |||
h[:container_image_registry_id] = h[:container_image_registry][:id] unless h[:container_image_registry].nil? | |||
h[:type] = h[:ems_ref] ? 'OpenshiftContainerImage' : 'BasicContainerImage' |
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 cannot have provider specifics here.
This can possibly be done differently by setting the :type in the parser itself. Then here do h[:type] ||= 'BasicContainerImage'
. Maybe? I'm not exactly sure what a BasicContainerImage even is and whether or not it belongs in core or in the OpenShift specific provider code.
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.
Ok, will do. BasicContainerImage
is not an Openshift related class.
app/models/container_image.rb
Outdated
@@ -11,6 +11,7 @@ class ContainerImage < ApplicationRecord | |||
DOCKER_PULLABLE_PREFIX = "docker-pullable://".freeze | |||
DOCKER_PREFIXES = [DOCKER_IMAGE_PREFIX, DOCKER_PULLABLE_PREFIX].freeze | |||
|
|||
belongs_to :parent, :polymorphic => 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.
To me it sounds like what you are trying to get is genealogy, in which case, containers should use the genealogy aspects that we already have for VMs (i.e. we have a relationship tree that show which instance came from which image, and then which image came from another image all the way back) @simon3z I'm not sure if this is already being done elsewhere in the containers code, but if so, we should make it consistent.
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 didn't mean to create a genealogy structure here, Just to have all container image types inherit from the same base so that they can be addressed the same and share code.
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 so, then parent
might be a bad name choice as it conflicts with the Relationship code, should that be used in the future.
app/models/basic_container_image.rb
Outdated
@@ -0,0 +1,4 @@ | |||
class BasicContainerImage < ContainerImage |
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.
What is a BasicContainerImage exactly?
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.
It is a class to represent a container image not from a specific provider. This is so that it will be easy to know what is the source of the image.
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.
@enoodle why do we need BasicContainerImage
in addition to ContainerImage
?
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.
It will make it easy to address all the container images that don't have an entity in Openshift/OtherContainerProvider managing them. It will hopefully be handy with the UI.
edb5ec7
to
c7b2160
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.
@enoodle we need something similar to:
https://github.com/manageiq/manageiq-providers-kubernetes/blob/7a0136a5696f270dc50d992594dd392db72106dd/app/models/manageiq/providers/kubernetes/container_manager/container_node.rb
(but in the openshift repository)
Add type to ContainerImage, and have a ContainerImage
under the Openshift Namespace
c7b2160
to
3235f7b
Compare
@moolitayer done. PTAL at ManageIQ/manageiq-providers-openshift#23 too |
app/models/container_image.rb
Outdated
@@ -11,6 +11,7 @@ class ContainerImage < ApplicationRecord | |||
DOCKER_PULLABLE_PREFIX = "docker-pullable://".freeze | |||
DOCKER_PREFIXES = [DOCKER_IMAGE_PREFIX, DOCKER_PULLABLE_PREFIX].freeze | |||
|
|||
belongs_to :container_image, :polymorphic => 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.
?
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 though we needed this line, but now I dont think so anymore. I will remove this.
3235f7b
to
8383f02
Compare
@enoodle after investigation I think we will be better of with only two classes, so that image.type is always |
ef84739
to
c0998e5
Compare
add_column :container_images, :type, :string | ||
ContainerImage.update_all(:type => "ManageIQ::Providers::Openshift::ContainerManager::ContainerImage") | ||
ContainerImage.where(:author => nil).update_all(:type => "ContainerImage") | ||
add_column :container_images, :ems_ref, :string |
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.
Do we have a value to update for the Openshift::ContainerManager::ContainerImage ?
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 only available during refresh, please make sure it will be populated in the next refresh
@@ -13,6 +13,7 @@ class ContainerManager < BaseManager | |||
has_many :container_limits, :foreign_key => :ems_id, :dependent => :destroy | |||
has_many :container_image_registries, :foreign_key => :ems_id, :dependent => :destroy | |||
has_many :container_images, :foreign_key => :ems_id, :dependent => :destroy | |||
has_many :basic_container_images, :foreign_key => :ems_id, :dependent => :destroy |
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 this any longer right?
Thanks @enoodle |
app/models/miq_action.rb
Outdated
@@ -742,7 +742,7 @@ def action_container_image_annotate_deny_execution(action, rec, inputs) | |||
return | |||
end | |||
|
|||
unless rec.digest.present? | |||
unless red.respond_to?(:annotate_deny_execution) |
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 red
a typo? If so are there no tests that would pick this up?
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 added a test for that.
end | ||
|
||
def up | ||
say_with_time("Adding type and ems_ref columns to ContainerImage and setting type") 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.
The say_with_time should only be around the data migration but...not the add_columns (otherwise you are hiding the logging of the add_column calls).
end | ||
|
||
def down | ||
say_with_time("Removing type and ems_ref columns from ContainerImage") 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.
No say_with_time needed on the down since you don't have a data migration.
expect(container_image_stub.find(container_image.id)).not_to respond_to(:type) | ||
expect(container_image_stub.find(openshift_container_image.id)).not_to respond_to(:type) | ||
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.
No need for a down migration test, since there is no data migration. Otherwise this test is just testing Rails itself, which isn't necessary.
ed32267
to
744de99
Compare
This pull request is not mergeable. Please rebase and repush. |
Database migrations have now been moved to the https://github.com/ManageIQ/manageiq-schema repo. Please see http://talk.manageiq.org/t/new-split-repo-manageiq-schema/2478 for instructions on how to transfer your database migrations. If this PR contains only migrations, I will leave it open for a short time during the transition, after which I will close this if it has not been moved over. |
Adds type and ems_ref columns to ContainerImage and enables STI. allow annotating only OpenshiftContainerImages and remove annotation function from container_image
744de99
to
a01680a
Compare
Checked commit enoodle@a01680a with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Merged ManageIQ/manageiq-schema#21. Please see my note about possible record thrashing, which may require another data migration for the ems_ref: ManageIQ/manageiq-schema#21 (comment) |
|
This will add
ContainerImage
subclasses:BasicContainerImage
andOpenshiftContainerImage
. This will allow to treat container images from different sources differently.Openshift provider complementing PR: ManageIQ/manageiq-providers-openshift#23