Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(destination): set parent and profile references #13292

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions controller/api/destination/destination_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ func FuzzProfileTranslatorUpdate(data []byte) int {
return 0
}
t := &testing.T{}
mockGetProfileServer := &mockDestinationGetProfileServer{profilesReceived: make(chan *pb.DestinationProfile, 50)}

translator := newProfileTranslator(mockGetProfileServer, logging.WithField("test", t.Name()), "foo.bar.svc.cluster.local", 80, nil)
id := watcher.ServiceID{Namespace: "bar", Name: "foo"}
server := &mockDestinationGetProfileServer{profilesReceived: make(chan *pb.DestinationProfile, 50)}
translator := newProfileTranslator(id, server, logging.WithField("test", t.Name()), "foo.bar.svc.cluster.local", 80, nil)
translator.Start()
defer translator.Stop()
translator.Update(profile)
Expand Down
33 changes: 32 additions & 1 deletion controller/api/destination/profile_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"github.com/golang/protobuf/ptypes/duration"
pb "github.com/linkerd/linkerd2-proxy-api/go/destination"
meta "github.com/linkerd/linkerd2-proxy-api/go/meta"
"github.com/linkerd/linkerd2/controller/api/destination/watcher"
sp "github.com/linkerd/linkerd2/controller/gen/apis/serviceprofile/v1alpha2"
"github.com/linkerd/linkerd2/pkg/profiles"
"github.com/linkerd/linkerd2/pkg/util"
Expand All @@ -22,6 +24,7 @@ const millisPerDecimilli = 10
type profileTranslator struct {
fullyQualifiedName string
port uint32
parentRef *meta.Metadata

stream pb.Destination_GetProfileServer
endStream chan struct{}
Expand All @@ -43,10 +46,23 @@ var profileUpdatesQueueOverflowCounter = promauto.NewCounterVec(
},
)

func newProfileTranslator(stream pb.Destination_GetProfileServer, log *logging.Entry, fqn string, port uint32, endStream chan struct{}) *profileTranslator {
func newProfileTranslator(serviceID watcher.ServiceID, stream pb.Destination_GetProfileServer, log *logging.Entry, fqn string, port uint32, endStream chan struct{}) *profileTranslator {
parentRef := &meta.Metadata{
Kind: &meta.Metadata_Resource{
Resource: &meta.Resource{
Group: "core",
Kind: "Service",
Name: serviceID.Name,
Namespace: serviceID.Namespace,
Port: port,
},
},
}

return &profileTranslator{
fullyQualifiedName: fqn,
port: port,
parentRef: parentRef,

stream: stream,
endStream: endStream,
Expand Down Expand Up @@ -154,6 +170,19 @@ func toDuration(d time.Duration) *duration.Duration {
// createDestinationProfile returns a Proxy API DestinationProfile, given a
// ServiceProfile.
func (pt *profileTranslator) createDestinationProfile(profile *sp.ServiceProfile) (*pb.DestinationProfile, error) {
var profileRef *meta.Metadata
if profile != nil {
profileRef = &meta.Metadata{
Kind: &meta.Metadata_Resource{
Resource: &meta.Resource{
Group: sp.SchemeGroupVersion.Group,
Kind: profile.Kind,
Name: profile.Name,
Namespace: profile.Namespace,
},
},
}
}
routes := make([]*pb.Route, 0)
for _, route := range profile.Spec.Routes {
pbRoute, err := toRoute(profile, route)
Expand All @@ -177,6 +206,8 @@ func (pt *profileTranslator) createDestinationProfile(profile *sp.ServiceProfile
_, opaqueProtocol = profile.Spec.OpaquePorts[pt.port]
}
return &pb.DestinationProfile{
ParentRef: pt.parentRef,
ProfileRef: profileRef,
Routes: routes,
RetryBudget: budget,
DstOverrides: toDstOverrides(profile.Spec.DstOverrides, pt.port),
Expand Down
Loading
Loading