Skip to content
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

Don't leave trailing hyphen in deployment name #22419

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Mar 17, 2023

  • If the ems_id is nil, empty, or not in the expected format, it can return nil
    causing us to leave the deployment name with a trailing hyphen. Now, we only
    append the hyphen and ems_id if it's present.

  • ems_id cannot be an array, simplifying this logic of ems_id returning nil or an fixnum

ems_id comes from ems_id_from_queue_name which as of [1] can only ever return an
integer or nil from parse_ems_id.

[1] #20345

Related, we need to fix the foreman provider to not return an array from queue_name_for_ems

@@ -113,6 +113,35 @@ def deployment_name_for(name)
expect(klass.constantize.new.worker_deployment_name.length).to be <= 60
end
end

context "ems_id" do
let(:subject) { ManageIQ::Providers::Openshift::ContainerManager::EventCatcher.new }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to be an Openshift::ContainerManager::EventCatcher for the specs? Would prefer not to call out a specific provider if possible. Could you use ManageIQ::Providers::BaseManager::EventCatcher ?

end

it "isn't appended for array queue_name" do
subject.queue_name = %w[ems_1 ems2]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only case I'm not understanding. If we have an "Array" queue_name, then the worker doesn't have an id? what happens if you have 2 separate queue_names like %w[ems_1 ems2] and %w[ems_3 ems4]? Wouldn't those collide?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I questioned that too. An array queue_name isn't supported as it was dropped in #20345.

I could just drop this test as it was just confirmation of how to fix the current problem. This deployment name creation code is so far from the source problem that raising in the code here would be quite unhelpful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so that's telling me that foreman has a bug and needs to be fixed


it "is appended" do
subject.queue_name = "ems_1"
expect(subject.worker_deployment_name[-1]).to eq("1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should include the hyphen so as not to allow any false positives like -21.

Suggested change
expect(subject.worker_deployment_name[-1]).to eq("1")
expect(subject.worker_deployment_name[-2..]).to eq("-1")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, ok

@Fryguy
Copy link
Member

Fryguy commented Mar 20, 2023

Related, we need to fix the foreman provider to not return an array from queue_name_for_ems

Is this the only worker like this? If so, I think it's better to fix that, and then not have the special case.

@agrare
Copy link
Member

agrare commented Mar 20, 2023

Is this the only worker like this? If so, I think it's better to fix that, and then not have the special case.

We should not be returning arrays for ems_id anymore, foreman was just missed because it doesn't follow the typical parent/child manager pattern.

@agrare
Copy link
Member

agrare commented Mar 20, 2023

Opened ManageIQ/manageiq-providers-foreman#113 to fix the issue with foreman queue_name_for_ems returning an Array

@jrafanie jrafanie force-pushed the handle_invalid_ems_id_corrupting_deployment_name branch from f0715d8 to 29dd755 Compare March 21, 2023 16:00
@jrafanie
Copy link
Member Author

Ok, I got back to this and pushed up the suggestions. Thanks.

@miq-bot
Copy link
Member

miq-bot commented Mar 21, 2023

Checked commits jrafanie/manageiq@047680d~...29dd755 with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint
2 files checked, 1 offense detected

app/models/miq_worker/container_common.rb

@@ -108,7 +108,7 @@ def deployment_prefix
def worker_deployment_name
@worker_deployment_name ||= begin
deployment_name = abbreviated_class_name.dup.chomp("Worker").sub("Manager", "").sub(/^Miq/, "")
deployment_name << "-#{Array(ems_id).map { |id| ApplicationRecord.split_id(id).last }.join("-")}" if respond_to?(:ems_id)
deployment_name << "-#{ApplicationRecord.split_id(ems_id).last}" if respond_to?(:ems_id) && ems_id.kind_of?(Fixnum)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrafanie As discussed, let's change the kind_of?(FixNum) to a nil/presence check. Otherwise this LGTM.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done. PTAL

If the ems_id is nil, empty, or not in the expected format, it can return nil,
causing us to leave the deployment name with a trailing hyphen.  Now, we only
append the hyphen and ems_id if it's present.
ems_id comes from ems_id_from_queue_name which as of [1] can only ever return an
integer or nil from parse_ems_id.

[1] ManageIQ#20345
@jrafanie jrafanie force-pushed the handle_invalid_ems_id_corrupting_deployment_name branch from 29dd755 to 0686ffd Compare March 29, 2023 15:41
@Fryguy Fryguy merged commit e845df9 into ManageIQ:master Mar 29, 2023
@Fryguy Fryguy assigned Fryguy and unassigned agrare Mar 29, 2023
@Fryguy
Copy link
Member

Fryguy commented Mar 30, 2023

Backported to petrosian in commit 9b15782.

commit 9b15782a9c5af5443ab46eba5322447456b65807
Author: Jason Frey <[email protected]>
Date:   Wed Mar 29 15:18:29 2023 -0400

    Merge pull request #22419 from jrafanie/handle_invalid_ems_id_corrupting_deployment_name
    
    Don't leave trailing hyphen in deployment name
    
    (cherry picked from commit e845df9b5b7d4936d57488ed5a0ab906250b978f)

Fryguy added a commit that referenced this pull request Mar 30, 2023
…ing_deployment_name

Don't leave trailing hyphen in deployment name

(cherry picked from commit e845df9)
@jrafanie jrafanie deleted the handle_invalid_ems_id_corrupting_deployment_name branch April 3, 2023 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants