Skip to content

Commit

Permalink
feat: allow to differentiate between multiple grpc-based data sources (
Browse files Browse the repository at this point in the history
…#1776)

Signed-off-by: Milan Lenco <[email protected]>
  • Loading branch information
Milan Lenčo authored Jan 11, 2021
1 parent 27364fa commit a04d009
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 12 additions & 2 deletions plugins/configurator/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ func (svc *configuratorServer) Update(ctx context.Context, req *pb.UpdateRequest
ctx = kvs.WithResync(ctx, kvs.FullResync, true)
}

ctx = contextdecorator.DataSrcContext(ctx, "grpc")
md, hasMeta := metadata.FromIncomingContext(ctx)
if hasMeta && len(md["datasrc"]) == 1 {
ctx = contextdecorator.DataSrcContext(ctx, md["datasrc"][0])
} else {
ctx = contextdecorator.DataSrcContext(ctx, "grpc")
}
results, err := svc.dispatch.PushData(ctx, kvPairs)

header := map[string]string{}
Expand Down Expand Up @@ -182,7 +187,12 @@ func (svc *configuratorServer) Delete(ctx context.Context, req *pb.DeleteRequest
})
}

ctx = contextdecorator.DataSrcContext(ctx, "grpc")
md, hasMeta := metadata.FromIncomingContext(ctx)
if hasMeta && len(md["datasrc"]) == 1 {
ctx = contextdecorator.DataSrcContext(ctx, md["datasrc"][0])
} else {
ctx = contextdecorator.DataSrcContext(ctx, "grpc")
}
results, err := svc.dispatch.PushData(ctx, kvPairs)

header := map[string]string{}
Expand Down
8 changes: 7 additions & 1 deletion plugins/orchestrator/meta_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.ligato.io/vpp-agent/v3/proto/ligato/generic"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoreflect"
Expand Down Expand Up @@ -119,7 +120,12 @@ func (s *genericService) SetConfig(ctx context.Context, req *generic.SetConfigRe
})
}

ctx = contextdecorator.DataSrcContext(ctx, "grpc")
md, hasMeta := metadata.FromIncomingContext(ctx)
if hasMeta && len(md["datasrc"]) == 1 {
ctx = contextdecorator.DataSrcContext(ctx, md["datasrc"][0])
} else {
ctx = contextdecorator.DataSrcContext(ctx, "grpc")
}
if req.OverwriteAll {
ctx = kvs.WithResync(ctx, kvs.FullResync, true)
}
Expand Down

0 comments on commit a04d009

Please sign in to comment.