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

Allow selecting enabled plugins #5083

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

mdellweg
Copy link
Member

@mdellweg mdellweg commented Feb 27, 2024

fixes #5235

Comment on lines -387 to +440
PRELOAD_FOR_DYNACONF=[
"{}.app.settings".format(plugin_name) for plugin_name in INSTALLED_PULP_PLUGINS
],
ENVVAR_FOR_DYNACONF="PULP_SETTINGS",
post_hooks=(load_plugin_config_hook,),
Copy link
Member

@rochacbruno rochacbruno Feb 27, 2024

Choose a reason for hiding this comment

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

Where does ENABLED_PLUGINS comes from? an environment variable?

I see 2 simpler ways for doing it without requiring a hook

  1. read the env directly
PRELOAD_FOR_DYNACONF=[
    "{}.app.settings".format(plugin_name) 
     for plugin_name in INSTALLED_PULP_PLUGINS 
     if plugin_name in os.getenv("PULP_ENABLED_PLUGINS", [])
],

The downside of above strategy is that variable will need to come from envvar, not set on a settings.py file.

  1. Post load plugin data without the hook
settings = DjangoDynaconf(....)
# then imediatelly after
for plugin_name in INSTALLED_PULP_PLUGINS:
    if plugin_name not in settings.get("enabled_plugins", []):
        continue
    settings.load_file("{}.app.settings".format(plugin_name))

Copy link
Member

Choose a reason for hiding this comment

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

this will also require a late validation, so replace

validators= [...]

with

settings = DjangoDynaconf(...)
for plugin_name in INSTALLED_PULP_PLUGINS:
    ....

# invoke validators
settings.validators.register(**list_of_validators)
settings.validators.validade()

Copy link
Member Author

Choose a reason for hiding this comment

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

It can come from any outside of pulp code base config source. e.g. /etc/pulp/settings.py or PULP_ENABLED_PLUGINS var.

Does this method ensure that the chainloaded plugin settings (like pulp_containers TOKEN_SERVER) have lower precedence than external config sources?
My impression from reading the docs is that they would overwrite local settings.

Copy link
Member

Choose a reason for hiding this comment

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

You are right, my suggestion would put plugin loading at the end of the process and then override local settings.

That is why in the current implementation we are using PRELOAD to ensure plugins settings loads before other settings sources.

Looks like we needed to have support for pre hooks, but right now we only support post loading hooks.

One idea is to write a custom loader to bring plugin_settings and then change the order of loaders putting the plugin_loader before everything else.

ideas @pedro-psb ?

Copy link
Member

Choose a reason for hiding this comment

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

If taking approach 2, I believe an explicit load of the settings files should ensure the external file precedence:

settings = DjangoDynaconf(...)
# (plugins load)
settings.load_file(settings.get("PULP_SETTINGS"))
# (validators)

But this original hook solution seems to do the trick, is there a particular reason not to use it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The thing is that we need to keep the order, because "everything else" is what may provide the ENABLED_PLUGINS.

@@ -380,14 +373,36 @@
)


def load_plugin_config_hook(settings):
# Enumerate the installed Pulp plugins during the loading process for use in the status API
ENABLED_PLUGINS = getattr(settings, "ENABLED_PLUGINS", None)
Copy link
Member

Choose a reason for hiding this comment

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

does it make sense to add validatiion to the setting so that at least one plugin needs to be enabled?

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically pulp would start just fine without it. So Maybe?

@mdellweg mdellweg force-pushed the select_plugins branch 2 times, most recently from 861c490 to ec73801 Compare February 28, 2024 11:08
@mdellweg
Copy link
Member Author

Something weird is going on here. _bypass_evaluation should not be in the final settings object...

In [4]: settings.TEMPLATES.to_list()
Out[4]: 
[{'BACKEND': 'django.template.backends.django.DjangoTemplates',
  'DIRS': [PosixPath('/src/pulpcore/pulpcore/app/templates')],
  'APP_DIRS': True,
  'OPTIONS': {'context_processors': ['django.template.context_processors.debug',
    'django.template.context_processors.request',
    'django.contrib.auth.context_processors.auth',
    'django.contrib.messages.context_processors.messages']},
  '_bypass_evaluation': True}]

@pedro-psb
Copy link
Member

We added some fixes related to this in 3.2.2.
If you are using >=3.2.2 already, I can work on a fix (that looks easy) and do a release on friday.
Wdyt @rochacbruno?

@mdellweg
Copy link
Member Author

We added some fixes related to this in 3.2.2. If you are using >=3.2.2 already, I can work on a fix (that looks easy) and do a release on friday. Wdyt @rochacbruno?

Using 3.2.4.

@mdellweg mdellweg force-pushed the select_plugins branch 4 times, most recently from 3b507df to 866e726 Compare April 3, 2024 21:13
@mdellweg mdellweg marked this pull request as ready for review April 4, 2024 00:37
@mdellweg mdellweg enabled auto-merge (rebase) April 4, 2024 07:21
@mdellweg mdellweg marked this pull request as draft April 9, 2024 14:26
auto-merge was automatically disabled April 9, 2024 14:26

Pull request was converted to draft

@mdellweg
Copy link
Member Author

mdellweg commented Apr 9, 2024

Looks like there are still some issues around dynaconf deeper merge strategies.

e.g. pulp_ansible needs to inject reusable ap conditions. It does not work this way.

@pedro-psb
Copy link
Member

pedro-psb commented Apr 9, 2024

Does this satisfy the deeper merge strategies requirements? We'll merge it in 3.3.0 (probably next release). dynaconf/dynaconf#1001

If not, can you open an issue at dynaconf?

Copy link

stale bot commented Jul 8, 2024

This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!

@stale stale bot added the stale label Jul 8, 2024
@mdellweg mdellweg removed the stale label Jul 9, 2024
Copy link

stale bot commented Oct 12, 2024

This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!

@stale stale bot added the stale label Oct 12, 2024
@mdellweg mdellweg removed the stale label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

As a user I want to select the active pulp plugins
4 participants