-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NET-7414] Reconcile PST for mesh gateway workloads on change to Comp…
…utedExportedServices (#20271) * Reconcile ProxyStateTemplate on change to ComputedExportedServices * gofmt changeset --------- Co-authored-by: NiniOak <[email protected]>
- Loading branch information
1 parent
57bad0d
commit 45d6454
Showing
4 changed files
with
71 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
internal/mesh/internal/controllers/gatewayproxy/mapper/meshgatewayworkloads.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package mapper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/consul/internal/controller" | ||
"github.com/hashicorp/consul/internal/mesh/internal/controllers/gatewayproxy/fetcher" | ||
"github.com/hashicorp/consul/internal/resource" | ||
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v2beta1" | ||
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1" | ||
"github.com/hashicorp/consul/proto-public/pbresource" | ||
) | ||
|
||
// AllMeshGatewayWorkloadsInPartition returns one controller.Request for each Workload | ||
// selected by a MeshGateway in the partition of the Resource. | ||
var AllMeshGatewayWorkloadsInPartition = func(ctx context.Context, rt controller.Runtime, res *pbresource.Resource) ([]controller.Request, error) { | ||
fetcher := fetcher.New(rt.Client, nil) | ||
|
||
gateways, err := fetcher.FetchMeshGateways(ctx, &pbresource.Tenancy{ | ||
Partition: res.Id.Tenancy.Partition, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var requests []controller.Request | ||
|
||
for _, gateway := range gateways { | ||
endpointsID := resource.ReplaceType(pbcatalog.ServiceEndpointsType, gateway.Id) | ||
|
||
endpoints, err := fetcher.FetchServiceEndpoints(ctx, endpointsID) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
if endpoints == nil || endpoints.Data == nil { | ||
continue | ||
} | ||
|
||
for _, endpoint := range endpoints.Data.Endpoints { | ||
requests = append(requests, controller.Request{ | ||
ID: resource.ReplaceType(pbmesh.ProxyStateTemplateType, endpoint.TargetRef), | ||
}) | ||
} | ||
} | ||
|
||
return requests, nil | ||
} |