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

Add namespace to distributions #158

Merged
merged 2 commits into from Nov 4, 2020
Merged

Add namespace to distributions #158

merged 2 commits into from Nov 4, 2020

Conversation

mdellweg
Copy link
Member

@mdellweg mdellweg commented Sep 24, 2020

fixes #7089
https://pulp.plan.io/issues/7089

This is the first version to pass ci. Still missing are at least:

  • a data migration
    - [ ] validation of namespaces to be collision free with non namespaced distribution - The new design handles this on the database table level.

@pulpbot
Copy link
Member

pulpbot commented Sep 24, 2020

Attached issue: https://pulp.plan.io/issues/7089

@mdellweg
Copy link
Member Author

I just realized, that if paths without a "/" still had a namespace (in that case with the same name), the uniqueness would be trivially given by the database.

@mdellweg mdellweg force-pushed the namespaces branch 2 times, most recently from 8091149 to d2db1fc Compare September 28, 2020 11:10
base_path = validated_data["base_path"]

if "namespace" in validated_data:
if not base_path.startswith(validated_data["namespace"].name + "/"):
Copy link
Member

Choose a reason for hiding this comment

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

🌮 👍

@ipanova
Copy link
Member

ipanova commented Sep 29, 2020

i know this change is not really related to the PR but can you please update and remove the publication reference https://github.com/pulp/pulp_container/pull/158/files#diff-90a314d7b2d5ddb20d360be02a4ec146R344

@mdellweg mdellweg force-pushed the namespaces branch 3 times, most recently from 2cc876b to 8d56ba8 Compare September 30, 2020 14:37
@mdellweg mdellweg changed the title WIP: Add namespace to distributions Add namespace to distributions Oct 1, 2020
ViewSet for ContainerNamespaces.
"""

endpoint_name = "pulp_container/namespaces"
Copy link
Member

Choose a reason for hiding this comment

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

the changes look good to me, @dkliban do you want to take a look? do you have a different suggestion on the endpoint or we leave this one as is?

Copy link
Member

Choose a reason for hiding this comment

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

i looked at 'django-admin show_urls' and i would not be opposed also having /namespaces/container/ as another option to consider

namespace_serializer.is_valid(raise_exception=True)
validated_data["namespace"] = namespace_serializer.create(
namespace_serializer.validated_data
)

Choose a reason for hiding this comment

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

there's room here for a race condition, if two repos are being created with a new namespace at the same time it could result in one of the 'creates' to fail when the other task created it. Not sure how often ya'll deal with that within pulp, but we see it all the time within katello

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds like we really need a sophisticated get_or_create on the serializer model.
I think we do that in >=3 places.

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 added another except block to recognize a lost race.

@mdellweg mdellweg force-pushed the namespaces branch 3 times, most recently from 589931d to b1bdaf9 Compare October 20, 2020 12:25
@mdellweg mdellweg marked this pull request as ready for review October 20, 2020 12:27
@ipanova
Copy link
Member

ipanova commented Oct 26, 2020

HTTP/1.1 200 OK
Allow: GET, POST, HEAD, OPTIONS
Connection: close
Content-Length: 112
Content-Type: application/json
Date: Mon, 26 Oct 2020 13:48:14 GMT
Server: gunicorn/20.0.4
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

{
    "count": 4,
    "next": null,
    "previous": null,
    "results": [

        {
            "name": "bar"
        },
        {
            "name": "foo"
        }
    ]
}

I suggest adding pulp_href pulp_created and maybe list of distributions

result = cls.Meta.model.objects.get(**natural_key)
except ObjectDoesNotExist:
data = {}
if default_values is not None:
Copy link
Member

Choose a reason for hiding this comment

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

if default_values:

"""

TYPE = "container"

namespace = models.ForeignKey(
ContainerNamespace,
on_delete=models.CASCADE,
Copy link
Member

Choose a reason for hiding this comment

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

👍

data = {}
if default_values is not None:
data.update(default_values)
data.update(natural_key)
Copy link
Member

Choose a reason for hiding this comment

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

data seems to be unused

Copy link
Member Author

Choose a reason for hiding this comment

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

But it should be... Changing that.

"""

class Meta:
fields = ModelSerializer.Meta.fields + ["name"]
Copy link
Member

Choose a reason for hiding this comment

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

we should use a tuple here instead of list

@mdellweg
Copy link
Member Author

I suggest adding pulp_href pulp_created and maybe list of distributions

As the list of distributions can get very large, i think it would be better to make the distribution filterable by namespace.

@ipanova
Copy link
Member

ipanova commented Oct 26, 2020

I suggest adding pulp_href pulp_created and maybe list of distributions

As the list of distributions can get very large, i think it would be better to make the distribution filterable by namespace.

That's a fine idea, for that we would need to add NamespaceFilter to the DistributionViewset.
Right now we are not serializing the namespace on the distribution, should we, given that ^ change?

@ipanova
Copy link
Member

ipanova commented Nov 2, 2020

while i can filter the distributions by the name of the namespace i get 500 on the namespace endpoint

$ http GET :24817/pulp/api/v3/distributions/container/container/?namespace__name=my-repo1
HTTP/1.1 200 OK
Allow: GET, POST, HEAD, OPTIONS
Connection: close
Content-Length: 637
Content-Type: application/json
Date: Mon, 02 Nov 2020 17:32:35 GMT
Server: gunicorn/20.0.4
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "base_path": "my-repo1",
            "content_guard": "/pulp/api/v3/contentguards/container/content_redirect/acbae288-e7cf-471f-bbd7-e88bb27300a6/",
            "name": "my-repo1",
            "namespace": "/pulp/api/v3/pulp_container/namespaces/4e565f62-aec7-48bb-8746-80cd412a69b5/",
            "pulp_created": "2020-11-02T17:27:59.566894Z",
            "pulp_href": "/pulp/api/v3/distributions/container/container/7252915c-53f6-4ba4-bcec-caff34c25d64/",
            "registry_path": "pulp3-source-fedora32.fluffy.example.com/my-repo1",
            "repository": "/pulp/api/v3/repositories/container/container-push/ade7c212-edee-4253-af06-738c6449862c/",
            "repository_version": null
        }
    ]
}

(pulp) [vagrant@pulp3-source-fedora32 _scripts]$ http GET :24817/pulp/api/v3/pulp_container/namespaces/4e565f62-aec7-48bb-8746-80cd412a69b5/
HTTP/1.1 500 Internal Server Error
Connection: close
Content-Length: 27
Content-Type: text/html
Date: Mon, 02 Nov 2020 17:32:41 GMT
Server: gunicorn/20.0.4
Vary: Cookie
X-Frame-Options: SAMEORIGIN

<h1>Server Error (500)</h1>

@mdellweg
Copy link
Member Author

mdellweg commented Nov 4, 2020

Somehow the IdentityField derives the view as "containernamespace-detail", while it is "pulp_container/namespaces-detail". This needs more investigation.

@mdellweg mdellweg force-pushed the namespaces branch 2 times, most recently from 47e9faf to ba009c8 Compare November 4, 2020 10:09
Serializer for ContainerNamespaces.
"""

pulp_href = IdentityField(view_name="pulp_container/namespaces-detail")
Copy link
Member Author

Choose a reason for hiding this comment

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

@ipanova this should fix it.

@mdellweg mdellweg merged commit 749d509 into pulp:master Nov 4, 2020
@mdellweg mdellweg deleted the namespaces branch November 4, 2020 12:36
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.

None yet

4 participants