Skip to content

Commit

Permalink
Add DnsSettings to CreateEndpointRequest
Browse files Browse the repository at this point in the history
To be able to set DNS configurations on the endpoint add a new DnsSettings message to
be used on the hcn endpoint.

This PR also fixes up a spelling mistake in subnet_ipadress_prefix -> subnet_ipaddress_prefix,
changes any empty messages to use google.protobuf.empty and a couple casing changes on the proto file.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
  • Loading branch information
dcantah committed May 13, 2021
1 parent 18de184 commit 2d086b2
Show file tree
Hide file tree
Showing 3 changed files with 705 additions and 1,383 deletions.
46 changes: 30 additions & 16 deletions cmd/ncproxy/ncproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/Microsoft/hcsshim/internal/uvm"
"github.com/Microsoft/hcsshim/pkg/octtrpc"
"github.com/containerd/ttrpc"
ptypes "github.com/gogo/protobuf/types"
"github.com/pkg/errors"
"go.opencensus.io/trace"
"google.golang.org/grpc/codes"
Expand All @@ -28,7 +29,7 @@ type grpcService struct{}

var _ ncproxygrpc.NetworkConfigProxyServer = &grpcService{}

func (s *grpcService) AddNIC(ctx context.Context, req *ncproxygrpc.AddNICRequest) (_ *ncproxygrpc.AddNICResponse, err error) {
func (s *grpcService) AddNIC(ctx context.Context, req *ncproxygrpc.AddNICRequest) (_ *ptypes.Empty, err error) {
ctx, span := trace.StartSpan(ctx, "AddNIC")
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
Expand All @@ -50,12 +51,12 @@ func (s *grpcService) AddNIC(ctx context.Context, req *ncproxygrpc.AddNICRequest
if _, err := client.AddNIC(ctx, caReq); err != nil {
return nil, err
}
return &ncproxygrpc.AddNICResponse{}, nil
return &ptypes.Empty{}, nil
}
return nil, status.Errorf(codes.FailedPrecondition, "No shim registered for namespace `%s`", req.ContainerID)
}

func (s *grpcService) ModifyNIC(ctx context.Context, req *ncproxygrpc.ModifyNICRequest) (_ *ncproxygrpc.ModifyNICResponse, err error) {
func (s *grpcService) ModifyNIC(ctx context.Context, req *ncproxygrpc.ModifyNICRequest) (_ *ptypes.Empty, err error) {
ctx, span := trace.StartSpan(ctx, "ModifyNIC")
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
Expand Down Expand Up @@ -129,12 +130,12 @@ func (s *grpcService) ModifyNIC(ctx context.Context, req *ncproxygrpc.ModifyNICR
}
}

return &ncproxygrpc.ModifyNICResponse{}, nil
return &ptypes.Empty{}, nil
}
return nil, status.Errorf(codes.FailedPrecondition, "No shim registered for containerID `%s`", req.ContainerID)
}

func (s *grpcService) DeleteNIC(ctx context.Context, req *ncproxygrpc.DeleteNICRequest) (_ *ncproxygrpc.DeleteNICResponse, err error) {
func (s *grpcService) DeleteNIC(ctx context.Context, req *ncproxygrpc.DeleteNICRequest) (_ *ptypes.Empty, err error) {
ctx, span := trace.StartSpan(ctx, "DeleteNIC")
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
Expand All @@ -159,7 +160,7 @@ func (s *grpcService) DeleteNIC(ctx context.Context, req *ncproxygrpc.DeleteNICR
}
return nil, err
}
return &ncproxygrpc.DeleteNICResponse{}, nil
return &ptypes.Empty{}, nil
}
return nil, status.Errorf(codes.FailedPrecondition, "No shim registered for namespace `%s`", req.ContainerID)
}
Expand Down Expand Up @@ -214,8 +215,8 @@ func (s *grpcService) CreateNetwork(ctx context.Context, req *ncproxygrpc.Create
Settings: data,
}

subnets := make([]hcn.Subnet, len(req.SubnetIpadressPrefix))
for i, addrPrefix := range req.SubnetIpadressPrefix {
subnets := make([]hcn.Subnet, len(req.SubnetIpaddressPrefix))
for i, addrPrefix := range req.SubnetIpaddressPrefix {
subnet := hcn.Subnet{
IpAddressPrefix: addrPrefix,
Routes: []hcn.Route{
Expand Down Expand Up @@ -342,6 +343,14 @@ func (s *grpcService) CreateEndpoint(ctx context.Context, req *ncproxygrpc.Creat
},
}

if req.DnsSetting != nil {
endpoint.Dns = hcn.Dns{
ServerList: req.DnsSetting.ServerIpAddrs,
Domain: req.DnsSetting.Domain,
Search: req.DnsSetting.Search,
}
}

endpoint, err = endpoint.Create()
if err != nil {
return nil, errors.Wrap(err, "failed to create HNS endpoint")
Expand All @@ -352,7 +361,7 @@ func (s *grpcService) CreateEndpoint(ctx context.Context, req *ncproxygrpc.Creat
}, nil
}

func (s *grpcService) AddEndpoint(ctx context.Context, req *ncproxygrpc.AddEndpointRequest) (_ *ncproxygrpc.AddEndpointResponse, err error) {
func (s *grpcService) AddEndpoint(ctx context.Context, req *ncproxygrpc.AddEndpointRequest) (_ *ptypes.Empty, err error) {
ctx, span := trace.StartSpan(ctx, "AddEndpoint") //nolint:ineffassign,staticcheck
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
Expand All @@ -376,10 +385,10 @@ func (s *grpcService) AddEndpoint(ctx context.Context, req *ncproxygrpc.AddEndpo
if err := hcn.AddNamespaceEndpoint(req.NamespaceID, ep.Id); err != nil {
return nil, errors.Wrapf(err, "failed to add endpoint with name %q to namespace", req.Name)
}
return &ncproxygrpc.AddEndpointResponse{}, nil
return &ptypes.Empty{}, nil
}

func (s *grpcService) DeleteEndpoint(ctx context.Context, req *ncproxygrpc.DeleteEndpointRequest) (_ *ncproxygrpc.DeleteEndpointResponse, err error) {
func (s *grpcService) DeleteEndpoint(ctx context.Context, req *ncproxygrpc.DeleteEndpointRequest) (_ *ptypes.Empty, err error) {
ctx, span := trace.StartSpan(ctx, "DeleteEndpoint") //nolint:ineffassign,staticcheck
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
Expand All @@ -402,10 +411,10 @@ func (s *grpcService) DeleteEndpoint(ctx context.Context, req *ncproxygrpc.Delet
if err = ep.Delete(); err != nil {
return nil, errors.Wrapf(err, "failed to delete endpoint with name %q", req.Name)
}
return &ncproxygrpc.DeleteEndpointResponse{}, nil
return &ptypes.Empty{}, nil
}

func (s *grpcService) DeleteNetwork(ctx context.Context, req *ncproxygrpc.DeleteNetworkRequest) (_ *ncproxygrpc.DeleteNetworkResponse, err error) {
func (s *grpcService) DeleteNetwork(ctx context.Context, req *ncproxygrpc.DeleteNetworkRequest) (_ *ptypes.Empty, err error) {
ctx, span := trace.StartSpan(ctx, "DeleteNetwork") //nolint:ineffassign,staticcheck
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
Expand All @@ -428,7 +437,7 @@ func (s *grpcService) DeleteNetwork(ctx context.Context, req *ncproxygrpc.Delete
if err = network.Delete(); err != nil {
return nil, errors.Wrapf(err, "failed to delete network with name %q", req.Name)
}
return &ncproxygrpc.DeleteNetworkResponse{}, nil
return &ptypes.Empty{}, nil
}

func (s *grpcService) GetEndpoint(ctx context.Context, req *ncproxygrpc.GetEndpointRequest) (_ *ncproxygrpc.GetEndpointResponse, err error) {
Expand Down Expand Up @@ -456,10 +465,15 @@ func (s *grpcService) GetEndpoint(ctx context.Context, req *ncproxygrpc.GetEndpo
Name: ep.Name,
Network: ep.HostComputeNetwork,
Namespace: ep.HostComputeNamespace,
DnsSetting: &ncproxygrpc.DnsSetting{
ServerIpAddrs: ep.Dns.ServerList,
Domain: ep.Dns.Domain,
Search: ep.Dns.Search,
},
}, nil
}

func (s *grpcService) GetEndpoints(ctx context.Context, req *ncproxygrpc.GetEndpointsRequest) (_ *ncproxygrpc.GetEndpointsResponse, err error) {
func (s *grpcService) GetEndpoints(ctx context.Context, req *ptypes.Empty) (_ *ncproxygrpc.GetEndpointsResponse, err error) {
ctx, span := trace.StartSpan(ctx, "GetEndpoints") //nolint:ineffassign,staticcheck
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
Expand Down Expand Up @@ -510,7 +524,7 @@ func (s *grpcService) GetNetwork(ctx context.Context, req *ncproxygrpc.GetNetwor
}, nil
}

func (s *grpcService) GetNetworks(ctx context.Context, req *ncproxygrpc.GetNetworksRequest) (_ *ncproxygrpc.GetNetworksResponse, err error) {
func (s *grpcService) GetNetworks(ctx context.Context, req *ptypes.Empty) (_ *ncproxygrpc.GetNetworksResponse, err error) {
ctx, span := trace.StartSpan(ctx, "GetNetworks") //nolint:ineffassign,staticcheck
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
Expand Down

0 comments on commit 2d086b2

Please sign in to comment.