mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 06:16:08 +00:00
c35df12c95
* Introduce a new type `ComputedProxyConfiguration` and add a controller for it. This is needed for two reasons. The first one is that external integrations like kubernetes may need to read the fully computed and sorted proxy configuration per workload. The second reasons is that it makes sidecar-proxy controller logic quite a bit simpler as it no longer needs to do this. * Generalize workload selection mapper and fix a bug where it would delete IDs from the tree if only one is left after a removal is done.
39 lines
879 B
Go
39 lines
879 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package controller
|
|
|
|
import (
|
|
"github.com/hashicorp/consul/internal/resource"
|
|
"github.com/hashicorp/consul/proto-public/pbresource"
|
|
)
|
|
|
|
// MakeRequests accepts a list of pbresource.ID and pbresource.Reference items,
|
|
// and mirrors them into a slice of []controller.Request items where the Type
|
|
// of the items has replaced by 'typ'.
|
|
func MakeRequests[V resource.ReferenceOrID](
|
|
typ *pbresource.Type,
|
|
refs []V,
|
|
) []Request {
|
|
if len(refs) == 0 {
|
|
return nil
|
|
}
|
|
|
|
out := make([]Request, 0, len(refs))
|
|
for _, ref := range refs {
|
|
// if type is not provided, we will use the type in the ID or reference.
|
|
if typ == nil {
|
|
typ = ref.GetType()
|
|
}
|
|
out = append(out, Request{
|
|
ID: &pbresource.ID{
|
|
Type: typ,
|
|
Tenancy: ref.GetTenancy(),
|
|
Name: ref.GetName(),
|
|
},
|
|
})
|
|
}
|
|
|
|
return out
|
|
}
|