Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Apply namespace selector to namespace instead of route #119

Merged
merged 7 commits into from
Mar 9, 2022

Conversation

nathancoleman
Copy link
Member

@nathancoleman nathancoleman commented Mar 8, 2022

Fixes #117

Changes proposed in this PR:

  • When a namespace selector is used for allowedRoutes, apply selector to route's Namespace instead of route itself

How I've tested this PR:
$ kubectl apply -f these resources.

With this change in the controller, the HTTPRoute will successfully attach to the Gateway. Without this change, it will not and you will see the log from #117 in the controller pod.

How I expect reviewers to test this PR:

Checklist:

  • Tests added
  • CHANGELOG entry added

    HashiCorp engineers only, community PRs should not add a changelog entry.
    Entries should use present tense (e.g. Add support for...)

Comment on lines 100 to 117
ns, err := metav1.LabelSelectorAsSelector(namespaceSelector.Selector)
namespaceSelector, err := metav1.LabelSelectorAsSelector(namespaceSelector.Selector)
if err != nil {
return false, fmt.Errorf("error parsing label selector: %w", err)
}

// retrieve the route's namespace and determine whether selector matches
namespace, err := c.GetNamespace(context.TODO(), types.NamespacedName{Name: route.GetNamespace()})
if err != nil {
return false, fmt.Errorf("error parsing label selector: %v", err)
return false, fmt.Errorf("error retrieving namespace for route: %w", err)
}

return ns.Matches(toNamespaceSet(route.GetNamespace(), route.GetLabels())), nil
return namespaceSelector.Matches(toNamespaceSet(namespace.GetName(), namespace.GetLabels())), nil
Copy link
Member Author

@nathancoleman nathancoleman Mar 8, 2022

Choose a reason for hiding this comment

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

This is the meat of the PR. Everything else is just plumbing and test updates to accommodate this.

Instead of attempting to apply namespace selector to route itself, retrieve the route's namespace and apply namespace selector to it.

@nathancoleman nathancoleman marked this pull request as ready for review March 8, 2022 22:22
Copy link
Contributor

@mikemorris mikemorris left a comment

Choose a reason for hiding this comment

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

Two minor cleanup notes but overall LGTM!

internal/k8s/reconciler/utils.go Outdated Show resolved Hide resolved
internal/k8s/reconciler/utils_test.go Outdated Show resolved Hide resolved
@nathancoleman nathancoleman merged commit d6bade5 into main Mar 9, 2022
@nathancoleman nathancoleman deleted the nc-route-namespace-selector branch March 9, 2022 19:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Namespace selector for allowedRoutes is applied to route instead of namespace
2 participants