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

Rewrite Namespace when Fetching Global PackageManifests #513

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/package-server/provider/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func (m *InMemoryProvider) Get(namespace, name string) (*packagev1alpha1.Package

for key, pm := range m.manifests {
if key.packageName == name && (key.catalogSourceNamespace == namespace || key.catalogSourceNamespace == m.globalNamespace) {
pm.SetNamespace(namespace)
Copy link
Member

Choose a reason for hiding this comment

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

The one thing that I think could become a problem in the future is when we have multiple packages of the same name in both the "global" and request namespace. In that situation you would have a 50% chance of getting the "global" package instead of the one you actually requested. Maybe for a get of an individual resource, you should only get the "global" package if no package of the same name exists in the requested namespace.

return &pm, nil
}
}
Expand All @@ -265,6 +266,9 @@ func (m *InMemoryProvider) List(namespace string) (*packagev1alpha1.PackageManif
var matching []packagev1alpha1.PackageManifest
for key, pm := range m.manifests {
if namespace == metav1.NamespaceAll || key.catalogSourceNamespace == namespace || key.catalogSourceNamespace == m.globalNamespace {
if namespace != metav1.NamespaceAll && pm.GetNamespace() != namespace {
pm.SetNamespace(namespace)
}
matching = append(matching, pm)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/package-server/provider/inmem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestList(t *testing.T) {
{
namespace: "default",
storedPackages: []packageValue{{name: "etcd", namespace: "default"}, {name: "prometheus", namespace: "global"}, {name: "vault", namespace: "local"}},
expectedPackages: []packageValue{{name: "etcd", namespace: "default"}, {name: "prometheus", namespace: "global"}},
expectedPackages: []packageValue{{name: "etcd", namespace: "default"}, {name: "prometheus", namespace: "default"}},
description: "FilterNamespaceWithGlobal",
},
{
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestGet(t *testing.T) {
namespace: "default",
packageName: "etcd",
storedPackages: []packageValue{{name: "etcd", namespace: "global"}, {name: "prometheus", namespace: "local"}},
expectedPackage: packageValue{name: "etcd", namespace: "global"},
expectedPackage: packageValue{name: "etcd", namespace: "default"},
description: "MatchesGlobal",
},
{
Expand Down