Skip to content

Commit 5cbe45c

Browse files
authored
feat(destination): set parent and profile references (#13292)
In order for proxies to properly reflect the resources used to drive policy decisions, the proxy API has been updated to include resource metadata on ServiceProfile responses. This change updates the profile translator to include ParentRef and ProfileRef metadata when it is configured. This change does not set backend or endpoint references.
1 parent 95852d9 commit 5cbe45c

File tree

4 files changed

+136
-54
lines changed

4 files changed

+136
-54
lines changed

controller/api/destination/destination_fuzzer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ func FuzzProfileTranslatorUpdate(data []byte) int {
9191
return 0
9292
}
9393
t := &testing.T{}
94-
mockGetProfileServer := &mockDestinationGetProfileServer{profilesReceived: make(chan *pb.DestinationProfile, 50)}
9594

96-
translator := newProfileTranslator(mockGetProfileServer, logging.WithField("test", t.Name()), "foo.bar.svc.cluster.local", 80, nil)
95+
id := watcher.ServiceID{Namespace: "bar", Name: "foo"}
96+
server := &mockDestinationGetProfileServer{profilesReceived: make(chan *pb.DestinationProfile, 50)}
97+
translator := newProfileTranslator(id, server, logging.WithField("test", t.Name()), "foo.bar.svc.cluster.local", 80, nil)
9798
translator.Start()
9899
defer translator.Stop()
99100
translator.Update(profile)

controller/api/destination/profile_translator.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
"github.com/golang/protobuf/ptypes/duration"
1010
pb "github.com/linkerd/linkerd2-proxy-api/go/destination"
11+
meta "github.com/linkerd/linkerd2-proxy-api/go/meta"
12+
"github.com/linkerd/linkerd2/controller/api/destination/watcher"
1113
sp "github.com/linkerd/linkerd2/controller/gen/apis/serviceprofile/v1alpha2"
1214
"github.com/linkerd/linkerd2/pkg/profiles"
1315
"github.com/linkerd/linkerd2/pkg/util"
@@ -22,6 +24,7 @@ const millisPerDecimilli = 10
2224
type profileTranslator struct {
2325
fullyQualifiedName string
2426
port uint32
27+
parentRef *meta.Metadata
2528

2629
stream pb.Destination_GetProfileServer
2730
endStream chan struct{}
@@ -43,10 +46,23 @@ var profileUpdatesQueueOverflowCounter = promauto.NewCounterVec(
4346
},
4447
)
4548

46-
func newProfileTranslator(stream pb.Destination_GetProfileServer, log *logging.Entry, fqn string, port uint32, endStream chan struct{}) *profileTranslator {
49+
func newProfileTranslator(serviceID watcher.ServiceID, stream pb.Destination_GetProfileServer, log *logging.Entry, fqn string, port uint32, endStream chan struct{}) *profileTranslator {
50+
parentRef := &meta.Metadata{
51+
Kind: &meta.Metadata_Resource{
52+
Resource: &meta.Resource{
53+
Group: "core",
54+
Kind: "Service",
55+
Name: serviceID.Name,
56+
Namespace: serviceID.Namespace,
57+
Port: port,
58+
},
59+
},
60+
}
61+
4762
return &profileTranslator{
4863
fullyQualifiedName: fqn,
4964
port: port,
65+
parentRef: parentRef,
5066

5167
stream: stream,
5268
endStream: endStream,
@@ -154,6 +170,19 @@ func toDuration(d time.Duration) *duration.Duration {
154170
// createDestinationProfile returns a Proxy API DestinationProfile, given a
155171
// ServiceProfile.
156172
func (pt *profileTranslator) createDestinationProfile(profile *sp.ServiceProfile) (*pb.DestinationProfile, error) {
173+
var profileRef *meta.Metadata
174+
if profile != nil {
175+
profileRef = &meta.Metadata{
176+
Kind: &meta.Metadata_Resource{
177+
Resource: &meta.Resource{
178+
Group: sp.SchemeGroupVersion.Group,
179+
Kind: profile.Kind,
180+
Name: profile.Name,
181+
Namespace: profile.Namespace,
182+
},
183+
},
184+
}
185+
}
157186
routes := make([]*pb.Route, 0)
158187
for _, route := range profile.Spec.Routes {
159188
pbRoute, err := toRoute(profile, route)
@@ -177,6 +206,8 @@ func (pt *profileTranslator) createDestinationProfile(profile *sp.ServiceProfile
177206
_, opaqueProtocol = profile.Spec.OpaquePorts[pt.port]
178207
}
179208
return &pb.DestinationProfile{
209+
ParentRef: pt.parentRef,
210+
ProfileRef: profileRef,
180211
Routes: routes,
181212
RetryBudget: budget,
182213
DstOverrides: toDstOverrides(profile.Spec.DstOverrides, pt.port),

0 commit comments

Comments
 (0)