Skip to content

Commit c6b708f

Browse files
committed
Added DNS info and ContainerID to endpoint
1 parent 278ce75 commit c6b708f

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

cni/network/network.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ func (plugin *netPlugin) Stop() {
8282
log.Printf("[cni-net] Plugin stopped.")
8383
}
8484

85+
// GetEndpointID returns a unique endpoint ID based on the CNI args.
86+
func (plugin *netPlugin) getEndpointID(args *cniSkel.CmdArgs) string {
87+
return args.ContainerID + "-" + args.IfName
88+
}
89+
8590
//
8691
// CNI implementation
8792
// https://github.com/containernetworking/cni/blob/master/SPEC.md
@@ -104,7 +109,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
104109
var result cniTypes.Result
105110
var resultImpl *cniTypesImpl.Result
106111
networkId := nwCfg.Name
107-
endpointId := args.ContainerID
112+
endpointId := plugin.getEndpointID(args)
108113

109114
// Check whether the network already exists.
110115
nwInfo, err := plugin.nm.GetNetworkInfo(networkId)
@@ -164,9 +169,10 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
164169

165170
// Initialize endpoint info.
166171
epInfo := &network.EndpointInfo{
167-
Id: endpointId,
168-
IfName: args.IfName,
169-
NetNsPath: args.Netns,
172+
Id: endpointId,
173+
ContainerID: args.ContainerID,
174+
NetNsPath: args.Netns,
175+
IfName: args.IfName,
170176
}
171177

172178
// Populate addresses and routes.
@@ -178,6 +184,10 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
178184
}
179185
}
180186

187+
// Populate DNS info.
188+
epInfo.DNSSuffix = resultImpl.DNS.Domain
189+
epInfo.DNSServers = resultImpl.DNS.Nameservers
190+
181191
// Create the endpoint.
182192
log.Printf("[cni-net] Creating endpoint %+v", epInfo)
183193
err = plugin.nm.CreateEndpoint(networkId, epInfo)
@@ -214,7 +224,7 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error {
214224

215225
// Initialize values from network config.
216226
networkId := nwCfg.Name
217-
endpointId := args.ContainerID
227+
endpointId := plugin.getEndpointID(args)
218228

219229
// Query the network.
220230
nwInfo, err := plugin.nm.GetNetworkInfo(networkId)

network/endpoint.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ type endpoint struct {
2424
// EndpointInfo contains read-only information about an endpoint.
2525
type EndpointInfo struct {
2626
Id string
27-
IfName string
27+
ContainerID string
2828
NetNsPath string
29+
IfName string
2930
IPAddresses []net.IPNet
3031
Routes []RouteInfo
32+
DNSSuffix string
33+
DNSServers []string
3134
}
3235

3336
// RouteInfo contains information about an IP route.
@@ -121,7 +124,7 @@ func (ep *endpoint) getInfo() *EndpointInfo {
121124
}
122125

123126
// Attach attaches an endpoint to a sandbox.
124-
func (ep *endpoint) attach(sandboxKey string, options map[string]interface{}) error {
127+
func (ep *endpoint) attach(sandboxKey string) error {
125128
if ep.SandboxKey != "" {
126129
return errEndpointInUse
127130
}

network/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func (nm *networkManager) AttachEndpoint(networkId string, endpointId string, sa
288288
return nil, err
289289
}
290290

291-
err = ep.attach(sandboxKey, nil)
291+
err = ep.attach(sandboxKey)
292292
if err != nil {
293293
return nil, err
294294
}

0 commit comments

Comments
 (0)