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

Change resource name to store if duplicate found #2230

Merged
merged 5 commits into from
Jan 24, 2020

Conversation

concaf
Copy link
Contributor

@concaf concaf commented Jan 23, 2020

Change resource name to store if duplicate found

Currently, resources stored in Ambassador are stored as
{resource_name: resource object, ...} treating resource name as
a unique identifier to look up resources of a given kind. However,
this causes issues becuase this does not allow different resources
in different namespace to have the same name, hence resulting in
errors or ignoring these resources completely.

In this commit, if two (or more) resources have the same name (in
different namespaces), then the duplicate resources are stored
as {name.namespace: resource} instead of just {name: resource}.

An ideal solution would be to idenitfy all resources with
{
  name: resource_name,
  namespace: resource_namespace
}
instead of flat strings, but that comes later.

Fix #2226 #2198

@concaf concaf force-pushed the concaf/fix/mappings-same-name branch from 68b5810 to 966d59a Compare January 24, 2020 08:38
Currently, resources stored in Ambassador are stored as
{resource_name: resource object, ...} treating resource name as
a unique identifier to look up resources of a given kind. However,
this causes issues becuase this does not allow different resources
in different namespace to have the same name, hence resulting in
errors or ignoring these resources completely.

In this commit, if two (or more) resources have the same name (in
different namespaces), then the duplicate resources are stored
as {name.namespace: resource} instead of just {name: resource}.

An ideal solution would be to idenitfy all resources with
{
  name: resource_name,
  namespace: resource_namespace
}
instead of flat strings, but that comes later.
@concaf concaf force-pushed the concaf/fix/mappings-same-name branch from 7f4d41c to 8e4aee3 Compare January 24, 2020 12:53
@concaf concaf changed the title [WIP] Change storage name for resources Change resource name to store if duplicate found Jan 24, 2020
@concaf concaf requested a review from kflynn January 24, 2020 12:54
@concaf concaf force-pushed the concaf/fix/mappings-same-name branch from 8e4aee3 to 8fad8d3 Compare January 24, 2020 13:37
@concaf
Copy link
Contributor Author

concaf commented Jan 24, 2020

This PR now also fixes updating multiple Ingress' status if they happen to have the same same in different namespaces.

@concaf concaf requested a review from alexgervais January 24, 2020 14:01
@concaf
Copy link
Contributor Author

concaf commented Jan 24, 2020

Fixes #2226

# namespaces. Our current data structure to store resources is a flat string. Till we move to
# identifying resources with both, name and namespace, we change names of any subsequent resources with
# the same name here.
resource.name = f'{resource.name}.{resource.namespace}'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why changing the resource name done in an else block? It currently feels like we handle an edge-case, yet I'm pretty sure all resource.name could include the namespace from the moment they are handled.
Following the logic here, it seems given resources: {name: something, namespace: a} and {name: something, namespace: b}, we would end up with 2 resources named: something and something.b where we don't associate the namespace to the first resource we put in storage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're correct. This is what I tried to explain at #2230 (comment) that we need to identify all resources with both name and namespace, and that's what I tried to do in the first go - but it turned out to be a much more intrusive change for the following reasons -

  • there were test failures everywhere
  • there are parts of code that rely on the resource name coming from aconf.config instead of aconf.config['name'], so that approach broke it

So, yes, this is more or less handling of an edge case without breaking the status quo.

Copy link
Member

Choose a reason for hiding this comment

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

We'll definitely need to handle the larger case, but, yeah, got it.

@concaf concaf requested a review from alexgervais January 24, 2020 14:21
@alexgervais
Copy link
Contributor

@concaf tests LGTM:

~ k get ingress -A
NAMESPACE     NAME   HOSTS                                                                                              ADDRESS          PORTS     AGE
scs-cffa046   scs    scs-cffa046.dev.mydomain.com,admin.scs-cffa046.dev.mydomain.com,api.scs-cffa046.dev.mydomain.com   104.198.45.191   80, 443   9m34s
scs-pr-6044   scs    scs-pr-6044.dev.mydomain.com,admin.scs-pr-6044.dev.mydomain.com,api.scs-pr-6044.dev.mydomain.com   104.198.45.191   80, 443   9m33s
scs-pr-6056   scs    scs-pr-6056.dev.mydomain.com,admin-scs-pr-6056.dev.mydomain.com,api-scs-pr-6056.dev.mydomain.com   104.198.45.191   80, 443   9m33s

Screen Shot 2020-01-24 at 09 54 35

Copy link
Member

@kflynn kflynn left a comment

Choose a reason for hiding this comment

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

Looks good from here, let's do it.

# namespaces. Our current data structure to store resources is a flat string. Till we move to
# identifying resources with both, name and namespace, we change names of any subsequent resources with
# the same name here.
resource.name = f'{resource.name}.{resource.namespace}'
Copy link
Member

Choose a reason for hiding this comment

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

We'll definitely need to handle the larger case, but, yeah, got it.

@kflynn kflynn merged commit 0cc3c05 into emissary-ingress:master Jan 24, 2020
esmet pushed a commit that referenced this pull request Jan 22, 2021
* update director.proto

* run `make generate`

* move the snapshot stuff around

* agent should use raw snapshot

* lint fixup

* oops actually replace the secret

* small proto change and tests for Snapshot.Sanitize

* lots o tests

* MOAR COMMENTS
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.

Cannot create mappings with same name in different namespaces
3 participants