Fix route subscription when using namespaces (#16677)
* Fix route subscription when using namespaces * Update changelog * Fix changelog entry to reference that the bug was enterprise only
This commit is contained in:
parent
fa1b6e7450
commit
2e07180662
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
gateway: **(Enterprise only)** Fix bug where routes defined in a different namespace than a gateway would fail to register. [[GH-16677](https://github.com/hashicorp/consul/pull/16677)].
|
||||||
|
```
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/acl"
|
||||||
cachetype "github.com/hashicorp/consul/agent/cache-types"
|
cachetype "github.com/hashicorp/consul/agent/cache-types"
|
||||||
"github.com/hashicorp/consul/agent/proxycfg/internal/watch"
|
"github.com/hashicorp/consul/agent/proxycfg/internal/watch"
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
|
@ -45,13 +46,13 @@ func (h *handlerAPIGateway) initialize(ctx context.Context) (ConfigSnapshot, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch the api-gateway's config entry
|
// Watch the api-gateway's config entry
|
||||||
err = h.subscribeToConfigEntry(ctx, structs.APIGateway, h.service, gatewayConfigWatchID)
|
err = h.subscribeToConfigEntry(ctx, structs.APIGateway, h.service, h.proxyID.EnterpriseMeta, gatewayConfigWatchID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return snap, err
|
return snap, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch the bound-api-gateway's config entry
|
// Watch the bound-api-gateway's config entry
|
||||||
err = h.subscribeToConfigEntry(ctx, structs.BoundAPIGateway, h.service, gatewayConfigWatchID)
|
err = h.subscribeToConfigEntry(ctx, structs.BoundAPIGateway, h.service, h.proxyID.EnterpriseMeta, gatewayConfigWatchID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return snap, err
|
return snap, err
|
||||||
}
|
}
|
||||||
|
@ -80,13 +81,13 @@ func (h *handlerAPIGateway) initialize(ctx context.Context) (ConfigSnapshot, err
|
||||||
return snap, nil
|
return snap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handlerAPIGateway) subscribeToConfigEntry(ctx context.Context, kind, name, watchID string) error {
|
func (h *handlerAPIGateway) subscribeToConfigEntry(ctx context.Context, kind, name string, entMeta acl.EnterpriseMeta, watchID string) error {
|
||||||
return h.dataSources.ConfigEntry.Notify(ctx, &structs.ConfigEntryQuery{
|
return h.dataSources.ConfigEntry.Notify(ctx, &structs.ConfigEntryQuery{
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
Name: name,
|
Name: name,
|
||||||
Datacenter: h.source.Datacenter,
|
Datacenter: h.source.Datacenter,
|
||||||
QueryOptions: structs.QueryOptions{Token: h.token},
|
QueryOptions: structs.QueryOptions{Token: h.token},
|
||||||
EnterpriseMeta: h.proxyID.EnterpriseMeta,
|
EnterpriseMeta: entMeta,
|
||||||
}, watchID, h.ch)
|
}, watchID, h.ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +173,7 @@ func (h *handlerAPIGateway) handleGatewayConfigUpdate(ctx context.Context, u Upd
|
||||||
return fmt.Errorf("unexpected route kind on gateway: %s", ref.Kind)
|
return fmt.Errorf("unexpected route kind on gateway: %s", ref.Kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := h.subscribeToConfigEntry(ctx, ref.Kind, ref.Name, routeConfigWatchID)
|
err := h.subscribeToConfigEntry(ctx, ref.Kind, ref.Name, ref.EnterpriseMeta, routeConfigWatchID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO May want to continue
|
// TODO May want to continue
|
||||||
return err
|
return err
|
||||||
|
@ -185,7 +186,7 @@ func (h *handlerAPIGateway) handleGatewayConfigUpdate(ctx context.Context, u Upd
|
||||||
seenRefs[ref] = struct{}{}
|
seenRefs[ref] = struct{}{}
|
||||||
snap.APIGateway.Certificates.InitWatch(ref, cancel)
|
snap.APIGateway.Certificates.InitWatch(ref, cancel)
|
||||||
|
|
||||||
err := h.subscribeToConfigEntry(ctx, ref.Kind, ref.Name, inlineCertificateConfigWatchID)
|
err := h.subscribeToConfigEntry(ctx, ref.Kind, ref.Name, ref.EnterpriseMeta, inlineCertificateConfigWatchID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO May want to continue
|
// TODO May want to continue
|
||||||
return err
|
return err
|
||||||
|
@ -391,7 +392,7 @@ func (h *handlerAPIGateway) handleRouteConfigUpdate(ctx context.Context, u Updat
|
||||||
snap.APIGateway.Upstreams.set(ref, listener, set)
|
snap.APIGateway.Upstreams.set(ref, listener, set)
|
||||||
}
|
}
|
||||||
snap.APIGateway.UpstreamsSet.set(ref, seenUpstreamIDs)
|
snap.APIGateway.UpstreamsSet.set(ref, seenUpstreamIDs)
|
||||||
//snap.APIGateway.Hosts = TODO
|
// snap.APIGateway.Hosts = TODO
|
||||||
snap.APIGateway.AreHostsSet = true
|
snap.APIGateway.AreHostsSet = true
|
||||||
|
|
||||||
// Stop watching any upstreams and discovery chains that have become irrelevant
|
// Stop watching any upstreams and discovery chains that have become irrelevant
|
||||||
|
|
Loading…
Reference in New Issue