Merge pull request #46554 from thaJeztah/remove_intermediates
remove some intermediate vars, and small refactor for error-handling
This commit is contained in:
commit
2c0ad62b24
4 changed files with 22 additions and 28 deletions
|
@ -324,16 +324,14 @@ func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSand
|
|||
continue // workaround for HNS reporting unsupported networks
|
||||
}
|
||||
var n *libnetwork.Network
|
||||
s := func(current *libnetwork.Network) bool {
|
||||
daemon.netController.WalkNetworks(func(current *libnetwork.Network) bool {
|
||||
hnsid := current.DriverOptions()[winlibnetwork.HNSID]
|
||||
if hnsid == v.Id {
|
||||
n = current
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
daemon.netController.WalkNetworks(s)
|
||||
})
|
||||
|
||||
drvOptions := make(map[string]string)
|
||||
nid := ""
|
||||
|
|
|
@ -246,12 +246,12 @@ func (daemon *Daemon) releaseIngress(id string) {
|
|||
|
||||
// SetNetworkBootstrapKeys sets the bootstrap keys.
|
||||
func (daemon *Daemon) SetNetworkBootstrapKeys(keys []*networktypes.EncryptionKey) error {
|
||||
err := daemon.netController.SetKeys(keys)
|
||||
if err == nil {
|
||||
// Upon successful key setting dispatch the keys available event
|
||||
daemon.cluster.SendClusterEvent(lncluster.EventNetworkKeysAvailable)
|
||||
if err := daemon.netController.SetKeys(keys); err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
// Upon successful key setting dispatch the keys available event
|
||||
daemon.cluster.SendClusterEvent(lncluster.EventNetworkKeysAvailable)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateAttachment notifies the attacher about the attachment config.
|
||||
|
|
|
@ -348,14 +348,13 @@ func (c *Controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, d
|
|||
go c.handleTableEvents(ch, c.handleEpTableEvent)
|
||||
go c.handleTableEvents(nodeCh, c.handleNodeTableEvent)
|
||||
|
||||
drvEnc := discoverapi.DriverEncryptionConfig{}
|
||||
keys, tags := c.getKeys(subsysIPSec)
|
||||
drvEnc.Keys = keys
|
||||
drvEnc.Tags = tags
|
||||
|
||||
c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
|
||||
if dr, ok := driver.(discoverapi.Discover); ok {
|
||||
if err := dr.DiscoverNew(discoverapi.EncryptionKeysConfig, drvEnc); err != nil {
|
||||
if err := dr.DiscoverNew(discoverapi.EncryptionKeysConfig, discoverapi.DriverEncryptionConfig{
|
||||
Keys: keys,
|
||||
Tags: tags,
|
||||
}); err != nil {
|
||||
log.G(context.TODO()).Warnf("Failed to set datapath keys in driver %s: %v", name, err)
|
||||
}
|
||||
}
|
||||
|
@ -389,12 +388,11 @@ func (c *Controller) agentDriverNotify(d discoverapi.Discover) {
|
|||
log.G(context.TODO()).Warnf("Failed the node discovery in driver: %v", err)
|
||||
}
|
||||
|
||||
drvEnc := discoverapi.DriverEncryptionConfig{}
|
||||
keys, tags := c.getKeys(subsysIPSec)
|
||||
drvEnc.Keys = keys
|
||||
drvEnc.Tags = tags
|
||||
|
||||
if err := d.DiscoverNew(discoverapi.EncryptionKeysConfig, drvEnc); err != nil {
|
||||
if err := d.DiscoverNew(discoverapi.EncryptionKeysConfig, discoverapi.DriverEncryptionConfig{
|
||||
Keys: keys,
|
||||
Tags: tags,
|
||||
}); err != nil {
|
||||
log.G(context.TODO()).Warnf("Failed to set datapath keys in driver: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -290,10 +290,9 @@ func (ds *Store) List(key string, kvObject KVObject) ([]KVObject, error) {
|
|||
}
|
||||
|
||||
var kvol []KVObject
|
||||
cb := func(key string, val KVObject) {
|
||||
err := ds.iterateKVPairsFromStore(key, kvObject, func(key string, val KVObject) {
|
||||
kvol = append(kvol, val)
|
||||
}
|
||||
err := ds.iterateKVPairsFromStore(key, kvObject, cb)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -341,16 +340,15 @@ func (ds *Store) Map(key string, kvObject KVObject) (map[string]KVObject, error)
|
|||
ds.mu.Lock()
|
||||
defer ds.mu.Unlock()
|
||||
|
||||
kvol := make(map[string]KVObject)
|
||||
cb := func(key string, val KVObject) {
|
||||
results := map[string]KVObject{}
|
||||
err := ds.iterateKVPairsFromStore(key, kvObject, func(key string, val KVObject) {
|
||||
// Trim the leading & trailing "/" to make it consistent across all stores
|
||||
kvol[strings.Trim(key, "/")] = val
|
||||
}
|
||||
err := ds.iterateKVPairsFromStore(key, kvObject, cb)
|
||||
results[strings.Trim(key, "/")] = val
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return kvol, nil
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// DeleteObjectAtomic performs atomic delete on a record.
|
||||
|
|
Loading…
Reference in a new issue