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
Fixes #36569 - List only supported Job Templates on upstream #650
Conversation
app/controllers/concerns/foreman/controller/parameters/job_template_extensions.rb
Outdated
Show resolved
Hide resolved
return super if Foreman::Plugin.find('foreman_theme_satellite').present? | ||
|
||
@job_templates = super | ||
@job_templates = @job_templates.where.not(name: JobTemplatesControllerExtensions::UNSUPPORTED_JOB_TEMPLATES) |
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 if instead of this we update the db seed for the Ansible job templates?
JobTemplate.without_auditing do
Dir[File.join("#{ForemanAnsible::Engine.root}/app/views/foreman_ansible/"\
'job_templates/**/*.erb')].each do |template|
sync = !Rails.env.test? && Setting[:remote_execution_sync_templates]
template = JobTemplate.import_raw!(File.read(template),
:default => true,
:lock => true,
:update => sync)
template.organizations = organizations if template.present?
template.locations = locations if template.present?
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 my understanding is correct, this code block is responsible for importing new templates and storing them in the database. However, as the Capsule Upgrade Playbook
already exists in our database, we must create a migration to remove it, in addition to making changes in the code. The same process applies to handling the Smart Proxy Upgrade Playbook
in the reverse scenario for the downstream.
On one hand, this approach ensures that unsupported job templates are not saved in the database, thereby avoiding the need for further code changes in the API. However, on the other hand, it requires the necessary migrations to delete data.
@ShimShtein, would you like to share your thoughts on this matter?
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.
However, as the Capsule Upgrade Playbook already exists in our database, we must create a migration to remove it, in addition to making changes in the code.
Do we need migration? Was it released to production already? In downstream it wasn't, not sure about the upstream.
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.
Removing the template in seeds/migrations seems more clean, but we will need a code that explicitly removes the unwanted template there.
Something like:
unsupported_templates = ['capsule_upgrade.erb']
unsupported_templates = ['smart_proxy_upgrade.erb'] if plugin.exists? 'foreman_theme_satellite'
Dir["templates/*.erb"].except(unsuppored_templates).each do |template|
create_template(template)
end
JobTemplate.where(name: unsupported_template).delete_all
Thank you! This looks much cleaner indeed. |
Update the job_templates seed file to include only supported templates.
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.
🍏 LGTM
Works well for both scenarios (upstream/downstream) and the code looks good too.
@ShimShtein if you don't have any other comments I'm 👍 to merge
LGTM. |
No description provided.