-
Notifications
You must be signed in to change notification settings - Fork 153
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by Django 5.2.14 on 2026-06-01 23:34 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('core', '0152_alter_repositoryversion_content_ids'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='task', | ||
| name='version', | ||
| field=models.TextField(default='v3'), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| from pulpcore.app.models.fields import EncryptedJSONField | ||
| from pulpcore.app.models.status import AppStatus | ||
| from pulpcore.app.role_util import get_users_with_perms | ||
| from pulpcore.app.settings import REST_FRAMEWORK | ||
| from pulpcore.app.util import get_domain_pk | ||
| from pulpcore.constants import TASK_CHOICES, TASK_INCOMPLETE_STATES, TASK_STATES | ||
| from pulpcore.exceptions import exception_to_dict | ||
|
|
@@ -143,6 +144,8 @@ class Task(BaseModel, AutoAddObjPermsMixin): | |
|
|
||
| result = models.JSONField(default=None, null=True, encoder=DjangoJSONEncoder) | ||
|
|
||
| version = models.TextField(default=REST_FRAMEWORK.get("DEFAULT_VERSION", "v3")) | ||
|
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. Can we call this
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. "version" as an attribute is "magic" at the DRF level - it's what gets filled in by the content of the
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. I was just abit afraid that we could be confusing here. And changing a database column name later is a pain. (Pulp is in the domain for versioning on all levels. Pulp-version, pulp-api-version, repository-version, deb-version, rpm-version, ansible-collection-version, ...) |
||
|
|
||
| @property | ||
| def user(self): | ||
| # These queries were specifically constructed and ordered this way to ensure we have the | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |||
| TaskGroupStatusCountField, | ||||
| fields, | ||||
| ) | ||||
| from pulpcore.app.settings import REST_FRAMEWORK | ||||
| from pulpcore.app.util import get_prn, reverse | ||||
| from pulpcore.constants import TASK_STATES | ||||
|
|
||||
|
|
@@ -118,6 +119,11 @@ class TaskSerializer(ModelSerializer): | |||
| help_text=_("The result of this task."), | ||||
| ) | ||||
|
|
||||
| version = serializers.CharField( | ||||
| help_text=_("The API-version that was invoked when creating the task."), | ||||
| default=REST_FRAMEWORK.get("DEFAULT_VERSION", "v3"), | ||||
|
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.
Suggested change
I don't think we need this, tasks will never be created via this serializer.
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. Possibly so, will dig a bit.
Contributor
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.
You would think, but I remember there being some surprising ways and places in which the serializers were getting initialized. |
||||
| ) | ||||
|
|
||||
| def get_worker(self, obj) -> t.Optional[OpenApiTypes.URI]: | ||||
| return None | ||||
|
|
||||
|
|
@@ -149,13 +155,15 @@ class Meta: | |||
| "created_resource_prns", | ||||
| "reserved_resources_record", | ||||
| "result", | ||||
| "version", | ||||
| ) | ||||
|
|
||||
|
|
||||
| class MinimalTaskSerializer(TaskSerializer): | ||||
| class Meta: | ||||
| model = models.Task | ||||
| fields = ModelSerializer.Meta.fields + ( | ||||
| "version", | ||||
| "name", | ||||
| "state", | ||||
| "unblocked_at", | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.
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.
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)
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.
That I kind ow liked. It's non-invasive, yet omnipresent inside the task code.