mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-07-10 14:13:08 +00:00
Add 'go fmt', golint and 'go vet' in CI
This change introduces go fmt/golint/go vet in CI pipeline to check the code for each commit. In addition, this change changes code to pass these checks.
This commit is contained in:
parent
1d2b6a1aee
commit
393d5f47e5
13
.travis.yml
13
.travis.yml
@ -7,13 +7,14 @@ dist: trusty
|
|||||||
before_install:
|
before_install:
|
||||||
- sudo apt-get update -qq
|
- sudo apt-get update -qq
|
||||||
|
|
||||||
#install:
|
install:
|
||||||
# - go get .
|
- go get github.com/golang/lint/golint
|
||||||
# - go get github.com/golang/lint/golint
|
|
||||||
|
|
||||||
#before_script:
|
before_script:
|
||||||
# - go vet .
|
- golint ./multus/... | grep -v ALL_CAPS | xargs -r false
|
||||||
# - golint . | xargs -r false
|
- go fmt ./multus/...
|
||||||
|
- go vet ./multus/...
|
||||||
|
# - gocyclo -over 15 ./multus
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- ./build
|
- ./build
|
||||||
|
@ -43,6 +43,7 @@ const defaultCNIDir = "/var/lib/cni/multus"
|
|||||||
var masterpluginEnabled bool
|
var masterpluginEnabled bool
|
||||||
var defaultcninetwork bool
|
var defaultcninetwork bool
|
||||||
|
|
||||||
|
// NetConf for cni config file written in json
|
||||||
type NetConf struct {
|
type NetConf struct {
|
||||||
types.NetConf
|
types.NetConf
|
||||||
CNIDir string `json:"cniDir"`
|
CNIDir string `json:"cniDir"`
|
||||||
@ -50,10 +51,6 @@ type NetConf struct {
|
|||||||
Kubeconfig string `json:"kubeconfig"`
|
Kubeconfig string `json:"kubeconfig"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PodNet struct {
|
|
||||||
Networkname string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type netplugin struct {
|
type netplugin struct {
|
||||||
metav1.TypeMeta `json:",inline"`
|
metav1.TypeMeta `json:",inline"`
|
||||||
metav1.ObjectMeta `json:"metadata,omitempty" description:"standard object metadata"`
|
metav1.ObjectMeta `json:"metadata,omitempty" description:"standard object metadata"`
|
||||||
@ -316,7 +313,7 @@ func parsePodNetworkObject(podnetwork string) ([]map[string]interface{}, error)
|
|||||||
if len(atItems) == 2 {
|
if len(atItems) == 2 {
|
||||||
m["interfaceRequest"] = atItems[1]
|
m["interfaceRequest"] = atItems[1]
|
||||||
}
|
}
|
||||||
podNet = append(podNet,m)
|
podNet = append(podNet, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,8 +321,8 @@ func parsePodNetworkObject(podnetwork string) ([]map[string]interface{}, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isJSON(str string) bool {
|
func isJSON(str string) bool {
|
||||||
var js json.RawMessage
|
var js json.RawMessage
|
||||||
return json.Unmarshal([]byte(str), &js) == nil
|
return json.Unmarshal([]byte(str), &js) == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getpluginargs(name string, args string, primary bool, ifname string) (string, error) {
|
func getpluginargs(name string, args string, primary bool, ifname string) (string, error) {
|
||||||
@ -345,7 +342,7 @@ func getpluginargs(name string, args string, primary bool, ifname string) (strin
|
|||||||
if ifname != "" {
|
if ifname != "" {
|
||||||
tmpargs = append(tmpargs, fmt.Sprintf(`"ifnameRequest": "%s",`, ifname))
|
tmpargs = append(tmpargs, fmt.Sprintf(`"ifnameRequest": "%s",`, ifname))
|
||||||
}
|
}
|
||||||
tmpargs = append(tmpargs, args[strings.Index(args, "\"") : len(args)-1])
|
tmpargs = append(tmpargs, args[strings.Index(args, "\""):len(args)-1])
|
||||||
|
|
||||||
var str bytes.Buffer
|
var str bytes.Buffer
|
||||||
|
|
||||||
@ -439,8 +436,10 @@ func getMultusDelegates(delegate string) ([]map[string]interface{}, error) {
|
|||||||
return tmpNetconf.Delegates, nil
|
return tmpNetconf.Delegates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NoK8sNetworkError indicates error, no network in kubernetes
|
||||||
type NoK8sNetworkError string
|
type NoK8sNetworkError string
|
||||||
func (e NoK8sNetworkError) Error() string { return string(e) }
|
|
||||||
|
func (e NoK8sNetworkError) Error() string { return string(e) }
|
||||||
|
|
||||||
func getK8sNetwork(args *skel.CmdArgs, kubeconfig string) ([]map[string]interface{}, error) {
|
func getK8sNetwork(args *skel.CmdArgs, kubeconfig string) ([]map[string]interface{}, error) {
|
||||||
k8sArgs := K8sArgs{}
|
k8sArgs := K8sArgs{}
|
||||||
|
Loading…
Reference in New Issue
Block a user