Skip to content

Commit 4994c59

Browse files
author
Flavio Crisciani
committed
Fixed code issues
Fixed issues highlighted by the new checks Signed-off-by: Flavio Crisciani <[email protected]>
1 parent 956e2be commit 4994c59

File tree

21 files changed

+52
-32
lines changed

21 files changed

+52
-32
lines changed

agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
165165
a.networkDB.SetKey(added)
166166
}
167167

168-
key, tag, err := c.getPrimaryKeyTag(subsysGossip)
168+
key, _, err := c.getPrimaryKeyTag(subsysGossip)
169169
if err != nil {
170170
return err
171171
}
172172
a.networkDB.SetPrimaryKey(key)
173173

174-
key, tag, err = c.getPrimaryKeyTag(subsysIPSec)
174+
key, tag, err := c.getPrimaryKeyTag(subsysIPSec)
175175
if err != nil {
176176
return err
177177
}

api/api_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,9 @@ func TestAttachDetachBackend(t *testing.T) {
914914

915915
cid := "abcdefghi"
916916
sbox, err := c.NewSandbox(cid)
917+
if err != nil {
918+
t.Fatal(err)
919+
}
917920
sid := sbox.ID()
918921
defer sbox.Delete()
919922

@@ -1280,6 +1283,9 @@ func TestJoinLeave(t *testing.T) {
12801283

12811284
cid := "abcdefghi"
12821285
sb, err := c.NewSandbox(cid)
1286+
if err != nil {
1287+
t.Fatal(err)
1288+
}
12831289
defer sb.Delete()
12841290

12851291
jl := endpointJoin{SandboxID: sb.ID()}

client/mflag/example/example.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var (
1313
)
1414

1515
func init() {
16-
flag.Bool([]string{"#hp", "#-halp"}, false, "display the halp")
16+
flag.Bool([]string{"#hp", "#-help"}, false, "display the help")
1717
flag.BoolVar(&b, []string{"b", "#bal", "#bol", "-bal"}, false, "a simple bool")
1818
flag.BoolVar(&b, []string{"g", "#gil"}, false, "a simple bool")
1919
flag.BoolVar(&b2, []string{"#-bool"}, false, "a simple bool")

common/setmatrix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type SetMatrix interface {
2222
// returns true if the mapping was deleted, false otherwise
2323
// returns also the number of endpoints associated to the IP
2424
Remove(key string, value interface{}) (bool, int)
25-
// Cardinality returns the number of elements in the set of a specfic key
25+
// Cardinality returns the number of elements in the set of a specific key
2626
// returns false if the key is not in the map
2727
Cardinality(key string) (int, bool)
2828
// String returns the string version of the set, empty otherwise

controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ func (c *controller) NetworkByID(id string) (Network, error) {
10141014
}
10151015

10161016
// NewSandbox creates a new sandbox for the passed container id
1017-
func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (sBox Sandbox, err error) {
1017+
func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error) {
10181018
if containerID == "" {
10191019
return nil, types.BadRequestErrorf("invalid container ID")
10201020
}
@@ -1054,7 +1054,6 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (s
10541054
extDNS: []extDNSEntry{},
10551055
}
10561056
}
1057-
sBox = sb
10581057

10591058
heap.Init(&sb.endpoints)
10601059

@@ -1073,6 +1072,8 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (s
10731072
sb.id = "ingress_sbox"
10741073
}
10751074
c.Unlock()
1075+
1076+
var err error
10761077
defer func() {
10771078
if err != nil {
10781079
c.Lock()

datastore/datastore_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ func TestAtomicKVObjectFlatKey(t *testing.T) {
101101
// Get the Object using GetObject, then set again.
102102
newObj := dummyObject{}
103103
err = store.GetObject(Key(expected.Key()...), &newObj)
104+
if err != nil {
105+
t.Fatal(err)
106+
}
104107
assert.True(t, newObj.Exists())
105108
err = store.PutObjectAtomic(&n)
106109
if err != nil {

drivers/overlay/ov_network.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ func (n *network) initSandbox(restore bool) error {
670670
// In the restore case network sandbox already exist; but we don't know
671671
// what epoch number it was created with. It has to be retrieved by
672672
// searching the net namespaces.
673-
key := ""
673+
var key string
674674
if restore {
675675
key = osl.GenerateKey("-" + n.id)
676676
} else {
@@ -872,15 +872,10 @@ func (n *network) Value() []byte {
872872
netJSON = append(netJSON, sj)
873873
}
874874

875-
b, err := json.Marshal(netJSON)
876-
if err != nil {
877-
return []byte{}
878-
}
879-
880875
m["secure"] = n.secure
881876
m["subnets"] = netJSON
882877
m["mtu"] = n.mtu
883-
b, err = json.Marshal(m)
878+
b, err := json.Marshal(m)
884879
if err != nil {
885880
return []byte{}
886881
}

drivers/solaris/overlay/ov_network.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func (n *network) initSandbox(restore bool) error {
457457
// In the restore case network sandbox already exist; but we don't know
458458
// what epoch number it was created with. It has to be retrieved by
459459
// searching the net namespaces.
460-
key := ""
460+
var key string
461461
if restore {
462462
key = osl.GenerateKey("-" + n.id)
463463
} else {
@@ -570,15 +570,10 @@ func (n *network) Value() []byte {
570570
netJSON = append(netJSON, sj)
571571
}
572572

573-
b, err := json.Marshal(netJSON)
574-
if err != nil {
575-
return []byte{}
576-
}
577-
578573
m["secure"] = n.secure
579574
m["subnets"] = netJSON
580575
m["mtu"] = n.mtu
581-
b, err = json.Marshal(m)
576+
b, err := json.Marshal(m)
582577
if err != nil {
583578
return []byte{}
584579
}

drivers/windows/windows.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
324324
}
325325

326326
n, err := d.getNetwork(id)
327+
if err != nil {
328+
return err
329+
}
327330
n.created = true
328331
return d.storeUpdate(config)
329332
}
@@ -530,7 +533,13 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
530533
}
531534

532535
epOption, err := parseEndpointOptions(epOptions)
536+
if err != nil {
537+
return err
538+
}
533539
epConnectivity, err := parseEndpointConnectivity(epOptions)
540+
if err != nil {
541+
return err
542+
}
534543

535544
macAddress := ifInfo.MacAddress()
536545
// Use the macaddress if it was provided

ipam/allocator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[s
448448
c := p
449449
for c.Range != nil {
450450
k = c.ParentKey
451-
c, ok = aSpace.subnets[k]
451+
c = aSpace.subnets[k]
452452
}
453453
aSpace.Unlock()
454454

0 commit comments

Comments
 (0)