Skip to content

Commit

Permalink
Merge pull request #1026 from dcantah/ncproxy-dns
Browse files Browse the repository at this point in the history
Add DnsSettings to ncproxy CreateEndpointRequest
  • Loading branch information
dcantah committed Jun 7, 2021
2 parents 0de8ce7 + c793ff4 commit 106fa2a
Show file tree
Hide file tree
Showing 4 changed files with 563 additions and 129 deletions.
9 changes: 5 additions & 4 deletions cmd/ncproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,22 @@ func main() {

// If there's a node network service in the config, assign this to our global client.
if conf.NodeNetSvcAddr != "" {
log.G(ctx).Debugf("connecting to NodeNetworkService at address %s", conf.NodeNetSvcAddr)
log.G(ctx).Infof("connecting to NodeNetworkService at address %s", conf.NodeNetSvcAddr)

dialCtx := ctx
opts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{})}
if conf.Timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, time.Duration(conf.Timeout)*time.Second)
dialCtx, cancel = context.WithTimeout(ctx, time.Duration(conf.Timeout)*time.Second)
defer cancel()
opts = append(opts, grpc.WithBlock())
}
client, err := grpc.DialContext(ctx, conf.NodeNetSvcAddr, opts...)
client, err := grpc.DialContext(dialCtx, conf.NodeNetSvcAddr, opts...)
if err != nil {
log.G(ctx).Fatalf("failed to connect to NodeNetworkService at address %s", conf.NodeNetSvcAddr)
}

log.G(ctx).Debugf("successfully connected to NodeNetworkService at address %s", conf.NodeNetSvcAddr)
log.G(ctx).Infof("successfully connected to NodeNetworkService at address %s", conf.NodeNetSvcAddr)

netSvcClient := nodenetsvc.NewNodeNetworkServiceClient(client)
nodeNetSvcClient = &nodeNetSvcConn{
Expand Down
25 changes: 23 additions & 2 deletions cmd/ncproxy/ncproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"strconv"
"sync"
"time"

"github.com/Microsoft/go-winio"
"github.com/Microsoft/hcsshim/cmd/ncproxy/ncproxygrpc"
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 Down Expand Up @@ -456,6 +465,11 @@ 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
}

Expand All @@ -476,6 +490,11 @@ func (s *grpcService) GetEndpoints(ctx context.Context, req *ncproxygrpc.GetEndp
Name: endpoint.Name,
Network: endpoint.HostComputeNetwork,
Namespace: endpoint.HostComputeNamespace,
DnsSetting: &ncproxygrpc.DnsSetting{
ServerIpAddrs: endpoint.Dns.ServerList,
Domain: endpoint.Dns.Domain,
Search: endpoint.Dns.Search,
},
}
endpoints[i] = resp
}
Expand Down Expand Up @@ -595,6 +614,8 @@ func (s *ttrpcService) ConfigureNetworking(ctx context.Context, req *ncproxyttrp
RequestType: nodenetsvc.RequestType(req.RequestType),
}

ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
defer cancel()
if _, err := nodeNetSvcClient.client.ConfigureNetworking(ctx, netsvcReq); err != nil {
return nil, err
}
Expand Down

0 comments on commit 106fa2a

Please sign in to comment.