-
Notifications
You must be signed in to change notification settings - Fork 157
Enable API-versioning and allow for both v3 and v4 versions. #7802
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Add `/v4/` API to Pulp. | ||
|
|
||
| This adds a `/v4/` API path to Pulp, in parallel to the existing `/v3/` path. The two | ||
| are currently (nearly) identical APIs - see the `/pulp/api/v4/status/` ouput for the | ||
| only (current) end-user-visible impact. | ||
|
|
||
| This change is primarily setting the stage to allow for future API changes and growth. | ||
| It is in TECH PREVIEW, and is likely to have significant changes happening to it as we | ||
| continue integrating into the rest of the Pulp architecture. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,16 @@ | |
| from contextvars import ContextVar | ||
|
|
||
| from asgiref.sync import sync_to_async | ||
| from django.conf import settings | ||
| from django_guid import clear_guid, get_guid, set_guid | ||
|
|
||
| _current_task = ContextVar("current_task", default=None) | ||
| _current_user_func = ContextVar("current_user", default=lambda: None) | ||
| _current_domain = ContextVar("current_domain", default=None) | ||
| x_task_diagnostics_var = ContextVar("x_profile_task") | ||
| _current_pulp_version = ContextVar( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment: Is this really how we want to "know" what pulp-version we are operating under? Author, please review! (also - even if we keep this, name needs to be _current_pulp_api_version)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That I kind ow liked. It's non-invasive, yet omnipresent inside the task code. |
||
| "current_pulp_version", default=settings.REST_FRAMEWORK.get("DEFAULT_VERSION", "v3") | ||
| ) | ||
|
|
||
|
|
||
| @contextmanager | ||
|
|
@@ -45,6 +49,13 @@ def with_domain(domain): | |
| def with_task_context(task): | ||
| with with_domain(task.pulp_domain), with_guid(task.logging_cid), with_user(task.user): | ||
| task_token = _current_task.set(task) | ||
| if not task.api_version: | ||
| vers_token = _current_pulp_version.set( | ||
| settings.REST_FRAMEWORK.get("DEFAULT_VERSION", "v3") | ||
| ) | ||
| else: | ||
| vers_token = _current_pulp_version.set(task.api_version) | ||
|
|
||
| # If this task is being spawned by another task, we should inherit the profile options | ||
| # from the current task. | ||
| diagnostics_token = x_task_diagnostics_var.set(task.profile_options) | ||
|
|
@@ -53,6 +64,7 @@ def with_task_context(task): | |
| finally: | ||
| x_task_diagnostics_var.reset(diagnostics_token) | ||
| _current_task.reset(task_token) | ||
| _current_pulp_version.reset(vers_token) | ||
|
|
||
|
|
||
| @asynccontextmanager | ||
|
|
@@ -64,6 +76,12 @@ def _fetch(task): | |
| domain, user = await _fetch(task) | ||
| with with_domain(domain), with_guid(task.logging_cid), with_user(user): | ||
| task_token = _current_task.set(task) | ||
| if not task.api_version: | ||
| vers_token = _current_pulp_version.set( | ||
| settings.REST_FRAMEWORK.get("DEFAULT_VERSION", "v3") | ||
| ) | ||
| else: | ||
| vers_token = _current_pulp_version.set(task.api_version) | ||
| # If this task is being spawned by another task, we should inherit the profile options | ||
| # from the current task. | ||
| diagnostics_token = x_task_diagnostics_var.set(task.profile_options) | ||
|
|
@@ -72,3 +90,4 @@ def _fetch(task): | |
| finally: | ||
| x_task_diagnostics_var.reset(diagnostics_token) | ||
| _current_task.reset(task_token) | ||
| _current_pulp_version.reset(vers_token) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by Django 5.2.14 on 2026-07-10 23:34 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('core', '0153_taskschedule_pulp_domain_alter_taskschedule_name_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='task', | ||
| name='api_version', | ||
| field=models.TextField(default='v3'), | ||
| ), | ||
| ] |
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.
Apart from
version, what arguments can end up being passed here? And what is the likelihood that any would overlap with task arguments?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.
Especially provided this applies across basically all tasks, so there are a wide variety of inputs that could potentially overlap.
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 address this, changed to be specific about version - and also responded to @mdellweg 's "can this be api_version" comment, because that will also reduce collision-chance.