enable nonamedreturns linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
3a04eb00bb
commit
709e775b13
@ -5,6 +5,7 @@ linters:
|
|||||||
- gofumpt
|
- gofumpt
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- misspell
|
- misspell
|
||||||
|
- nonamedreturns
|
||||||
- staticcheck
|
- staticcheck
|
||||||
disable:
|
disable:
|
||||||
- errcheck
|
- errcheck
|
||||||
|
@ -67,38 +67,37 @@ func peerExists(name string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeVeth(name, vethPeerName string, mtu int, mac string, hostNS ns.NetNS) (peerName string, veth netlink.Link, err error) {
|
func makeVeth(name, vethPeerName string, mtu int, mac string, hostNS ns.NetNS) (string, netlink.Link, error) {
|
||||||
|
var peerName string
|
||||||
|
var veth netlink.Link
|
||||||
|
var err error
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
if vethPeerName != "" {
|
if vethPeerName != "" {
|
||||||
peerName = vethPeerName
|
peerName = vethPeerName
|
||||||
} else {
|
} else {
|
||||||
peerName, err = RandomVethName()
|
peerName, err = RandomVethName()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return peerName, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
veth, err = makeVethPair(name, peerName, mtu, mac, hostNS)
|
veth, err = makeVethPair(name, peerName, mtu, mac, hostNS)
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return
|
return peerName, veth, err
|
||||||
|
|
||||||
case os.IsExist(err):
|
case os.IsExist(err):
|
||||||
if peerExists(peerName) && vethPeerName == "" {
|
if peerExists(peerName) && vethPeerName == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err = fmt.Errorf("container veth name provided (%v) already exists", name)
|
return peerName, veth, fmt.Errorf("container veth name provided (%v) already exists", name)
|
||||||
return
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("failed to make veth pair: %v", err)
|
return peerName, veth, fmt.Errorf("failed to make veth pair: %v", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// should really never be hit
|
// should really never be hit
|
||||||
err = fmt.Errorf("failed to find a unique veth name")
|
return peerName, nil, fmt.Errorf("failed to find a unique veth name")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RandomVethName returns string "veth" with random prefix (hashed from entropy)
|
// RandomVethName returns string "veth" with random prefix (hashed from entropy)
|
||||||
|
@ -84,8 +84,11 @@ var requestOptionsDefault = map[dhcp4.OptionCode]bool{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func prepareOptions(cniArgs string, ProvideOptions []ProvideOption, RequestOptions []RequestOption) (
|
func prepareOptions(cniArgs string, ProvideOptions []ProvideOption, RequestOptions []RequestOption) (
|
||||||
optsRequesting map[dhcp4.OptionCode]bool, optsProviding map[dhcp4.OptionCode][]byte, err error,
|
map[dhcp4.OptionCode]bool, map[dhcp4.OptionCode][]byte, error,
|
||||||
) {
|
) {
|
||||||
|
var optsRequesting map[dhcp4.OptionCode]bool
|
||||||
|
var optsProviding map[dhcp4.OptionCode][]byte
|
||||||
|
var err error
|
||||||
// parse CNI args
|
// parse CNI args
|
||||||
cniArgsParsed := map[string]string{}
|
cniArgsParsed := map[string]string{}
|
||||||
for _, argPair := range strings.Split(cniArgs, ";") {
|
for _, argPair := range strings.Split(cniArgs, ";") {
|
||||||
@ -101,20 +104,17 @@ func prepareOptions(cniArgs string, ProvideOptions []ProvideOption, RequestOptio
|
|||||||
for _, opt := range ProvideOptions {
|
for _, opt := range ProvideOptions {
|
||||||
optParsed, err = parseOptionName(string(opt.Option))
|
optParsed, err = parseOptionName(string(opt.Option))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Can not parse option %q: %w", opt.Option, err)
|
return nil, nil, fmt.Errorf("Can not parse option %q: %w", opt.Option, err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if len(opt.Value) > 0 {
|
if len(opt.Value) > 0 {
|
||||||
if len(opt.Value) > 255 {
|
if len(opt.Value) > 255 {
|
||||||
err = fmt.Errorf("value too long for option %q: %q", opt.Option, opt.Value)
|
return nil, nil, fmt.Errorf("value too long for option %q: %q", opt.Option, opt.Value)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
optsProviding[optParsed] = []byte(opt.Value)
|
optsProviding[optParsed] = []byte(opt.Value)
|
||||||
}
|
}
|
||||||
if value, ok := cniArgsParsed[opt.ValueFromCNIArg]; ok {
|
if value, ok := cniArgsParsed[opt.ValueFromCNIArg]; ok {
|
||||||
if len(value) > 255 {
|
if len(value) > 255 {
|
||||||
err = fmt.Errorf("value too long for option %q from CNI_ARGS %q: %q", opt.Option, opt.ValueFromCNIArg, opt.Value)
|
return nil, nil, fmt.Errorf("value too long for option %q from CNI_ARGS %q: %q", opt.Option, opt.ValueFromCNIArg, opt.Value)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
optsProviding[optParsed] = []byte(value)
|
optsProviding[optParsed] = []byte(value)
|
||||||
}
|
}
|
||||||
@ -129,8 +129,7 @@ func prepareOptions(cniArgs string, ProvideOptions []ProvideOption, RequestOptio
|
|||||||
}
|
}
|
||||||
optParsed, err = parseOptionName(string(opt.Option))
|
optParsed, err = parseOptionName(string(opt.Option))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Can not parse option %q: %w", opt.Option, err)
|
return nil, nil, fmt.Errorf("Can not parse option %q: %w", opt.Option, err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
optsRequesting[optParsed] = true
|
optsRequesting[optParsed] = true
|
||||||
}
|
}
|
||||||
@ -140,7 +139,7 @@ func prepareOptions(cniArgs string, ProvideOptions []ProvideOption, RequestOptio
|
|||||||
optsRequesting[k] = v
|
optsRequesting[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return optsRequesting, optsProviding, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcquireLease gets an DHCP lease and then maintains it in the background
|
// AcquireLease gets an DHCP lease and then maintains it in the background
|
||||||
|
Loading…
x
Reference in New Issue
Block a user