Skip to content

Commit

Permalink
Merge pull request #46554 from thaJeztah/remove_intermediates
Browse files Browse the repository at this point in the history
remove some intermediate vars, and small refactor for error-handling
  • Loading branch information
thaJeztah authored Sep 27, 2023
2 parents 605c8fb + 3197160 commit 2c0ad62
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
6 changes: 2 additions & 4 deletions daemon/daemon_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand Down
10 changes: 5 additions & 5 deletions daemon/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 8 additions & 10 deletions libnetwork/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
16 changes: 7 additions & 9 deletions libnetwork/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2c0ad62

Please sign in to comment.