Skip to content

Commit

Permalink
Re-enable golangci-lint (projectcalico#777)
Browse files Browse the repository at this point in the history
Re-enable golangci-lint
  • Loading branch information
Rafael Vanoni authored Sep 5, 2019
1 parent 2b2325b commit e64b975
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 42 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,8 @@ $(BIN)/flannel $(BIN)/loopback $(BIN)/host-local $(BIN)/portmap $(BIN)/tuning $(
###############################################################################
.PHONY: static-checks
## Perform static checks on the code.

# TODO: re-enable these linters !
LINT_ARGS := --disable ineffassign,staticcheck,errcheck,gosimple,govet

static-checks:
$(DOCKER_RUN) $(CALICO_BUILD) golangci-lint run --deadline 5m $(LINT_ARGS)
$(DOCKER_RUN) $(CALICO_BUILD) golangci-lint run --deadline 5m

.PHONY: fix
## Fix static checks
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require (
github.com/projectcalico/go-json v0.0.0-20161128004156-6219dc7339ba
github.com/projectcalico/go-yaml v0.0.0-20161201183616-955bc3e451ef
github.com/projectcalico/go-yaml-wrapper v0.0.0-20161127220527-598e54215bee
github.com/projectcalico/libcalico-go v3.9.0-0.dev.0.20190813183411-9f88ebd570c5+incompatible // indirect
github.com/projectcalico/libcalico-go v3.9.0-0.dev.0.20190813183411-9f88ebd570c5+incompatible
github.com/prometheus/client_golang v0.0.0-20171005112915-5cec1d0429b0
github.com/prometheus/client_model v0.0.0-20170216185247-6f3806018612
github.com/prometheus/common v0.0.0-20171104095907-e3fb1a1acd76
Expand Down
22 changes: 9 additions & 13 deletions internal/pkg/testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ func CreateContainer(netconf, podName, podNamespace, ip string) (containerID str
}

// Create container with the giving containerId when containerId is not empty
//
// Deprecated: Please call CreateContainerNamespace and then RunCNIPluginWithID directly.
func CreateContainerWithId(netconf, podName, podNamespace, ip, overrideContainerID string) (containerID string, result *current.Result, contVeth netlink.Link, contAddr []netlink.Addr, contRoutes []netlink.Route, targetNs ns.NetNS, err error) {
targetNs, containerID, err = CreateContainerNamespace()
if err != nil {
Expand Down Expand Up @@ -512,13 +510,13 @@ func Cmd(cmd string) string {
_, _ = ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("Running command [%s]\n", cmd)))
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
_, err = ginkgo.GinkgoWriter.Write(out)
if err != nil {
panic(err)
_, writeErr := ginkgo.GinkgoWriter.Write(out)
if writeErr != nil {
panic(writeErr)
}
_, err = ginkgo.GinkgoWriter.Write(err.(*exec.ExitError).Stderr)
if err != nil {
panic(err)
_, writeErr = ginkgo.GinkgoWriter.Write(err.(*exec.ExitError).Stderr)
if writeErr != nil {
panic(writeErr)
}
ginkgo.Fail("Command failed")
}
Expand Down Expand Up @@ -555,7 +553,6 @@ func CheckSysctlValue(sysctlPath, value string) error {

func AddNode(c client.Interface, kc *kubernetes.Clientset, host string) error {
var err error
err = nil
if os.Getenv("DATASTORE_TYPE") == "kubernetes" {
// create the node in Kubernetes.
n := corev1.Node{
Expand Down Expand Up @@ -584,12 +581,11 @@ func AddNode(c client.Interface, kc *kubernetes.Clientset, host string) error {
}

func DeleteNode(c client.Interface, kc *kubernetes.Clientset, host string) error {
var err error
err = nil
var err error = nil
if os.Getenv("DATASTORE_TYPE") == "kubernetes" {
// delete the node in Kubernetes.
err := kc.CoreV1().Nodes().Delete(host, &metav1.DeleteOptions{})
log.WithError(err).Info("node deleted")
deleteErr := kc.CoreV1().Nodes().Delete(host, &metav1.DeleteOptions{})
log.WithError(deleteErr).Info("node deleted")
} else {
// Otherwise, delete it in Calico.
n := api.NewNode()
Expand Down
13 changes: 8 additions & 5 deletions k8s-install/scripts/install_cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os"
"os/exec"
"strings"

log "github.com/sirupsen/logrus"
)

var secretFile = "tmp/serviceaccount/token"
Expand Down Expand Up @@ -45,12 +47,13 @@ func runCniContainer(extraArgs ...string) error {
"-v", cwd + "/tmp/serviceaccount:/var/run/secrets/kubernetes.io/serviceaccount",
}
args = append(args, extraArgs...)
image := fmt.Sprintf("%s", os.Getenv("CONTAINER_NAME"))
args = append(args, image, "/install-cni.sh")
args = append(args, os.Getenv("CONTAINER_NAME"), "/install-cni.sh")

out, err = exec.Command("docker", args...).CombinedOutput()
GinkgoWriter.Write(out)

_, writeErr := GinkgoWriter.Write(out)
if writeErr != nil {
log.WithField("out", out).WithError(writeErr).Warn("GinkgoWriter failed to write output from command.")
}
return err
}

Expand All @@ -71,7 +74,7 @@ func cleanup() {
"-v", cwd + "/tmp/bin:/host/opt/cni/bin",
"-v", cwd + "/tmp/net.d:/host/etc/cni/net.d",
"-v", cwd + "/tmp/serviceaccount:/var/run/secrets/kubernetes.io/serviceaccount",
fmt.Sprintf("%s", os.Getenv("CONTAINER_NAME")),
os.Getenv("CONTAINER_NAME"),
"sh", "-c", "rm -rf /host/opt/cni/bin/* /host/etc/cni/net.d/*",
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ func CmdAddK8s(ctx context.Context, args *skel.CmdArgs, conf types.NetConf, epID

labels := make(map[string]string)
annot := make(map[string]string)
annotNS := make(map[string]string)

var ports []api.EndpointPort
var profiles []string
Expand All @@ -169,9 +168,7 @@ func CmdAddK8s(ctx context.Context, args *skel.CmdArgs, conf types.NetConf, epID
// run the plugin under Kubernetes without needing it to access the
// Kubernetes API
if conf.Policy.PolicyType == "k8s" {
var err error

annotNS, err = getK8sNSInfo(client, epIDs.Namespace)
annotNS, err := getK8sNSInfo(client, epIDs.Namespace)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func cmdAdd(args *skel.CmdArgs) error {
if err != nil {
return fmt.Errorf("error getting ClusterInformation: %v", err)
}
if *ci.Spec.DatastoreReady != true {
if !*ci.Spec.DatastoreReady {
logrus.Info("Upgrade may be in progress, ready flag is not set")
return fmt.Errorf("Calico is currently not ready to process requests")
}
Expand Down Expand Up @@ -423,7 +423,7 @@ func cmdDel(args *skel.CmdArgs) error {
if err != nil {
return fmt.Errorf("error getting ClusterInformation: %v", err)
}
if *ci.Spec.DatastoreReady != true {
if !*ci.Spec.DatastoreReady {
logrus.Info("Upgrade may be in progress, ready flag is not set")
return fmt.Errorf("Calico is currently not ready to process requests")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/upgrade/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func Migrate(ctxt context.Context, c client.Interface, nodename string) error {
node.Spec.BGP = &v3.NodeBGPSpec{}
}
node.Spec.BGP.IPv4IPIPTunnelAddr = tunIp.String()
if node, err = c.Nodes().Update(ctxt, node, options.SetOptions{}); err != nil {
if _, err = c.Nodes().Update(ctxt, node, options.SetOptions{}); err != nil {
if _, ok := err.(errors.ErrorResourceUpdateConflict); ok {
log.Info("Encountered update conflict, retrying...")
time.Sleep(1 * time.Second)
Expand Down
4 changes: 2 additions & 2 deletions tests/calico_cni_ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/projectcalico/libcalico-go/lib/names"
cnet "github.com/projectcalico/libcalico-go/lib/net"
"github.com/projectcalico/libcalico-go/lib/options"
"github.com/satori/go.uuid"
uuid "github.com/satori/go.uuid"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
Expand Down Expand Up @@ -335,7 +335,7 @@ var _ = Describe("Calico IPAM Tests", func() {
result, _, _ := testutils.RunIPAMPlugin(netconf, "ADD", "IP=192.168.123.123", cid, cniVersion)
Expect(len(result.IPs)).Should(Equal(1))
Expect(result.IPs[0].Address.String()).Should(Equal("192.168.123.123/32"))
result, _, exitCode := testutils.RunIPAMPlugin(netconf, "ADD", "IP=192.168.123.123", cid, cniVersion)
_, _, exitCode := testutils.RunIPAMPlugin(netconf, "ADD", "IP=192.168.123.123", cid, cniVersion)
Expect(exitCode).Should(BeNumerically(">", 0))
})
})
Expand Down
15 changes: 8 additions & 7 deletions tests/calico_cni_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,8 @@ var _ = Describe("Kubernetes CNI tests", func() {
}
],
[
{
"subnet": "10.100.0.0/24"
{
"subnet": "10.100.0.0/24"
}
],
[
Expand Down Expand Up @@ -735,8 +735,8 @@ var _ = Describe("Kubernetes CNI tests", func() {
}
],
[
{
"subnet": "10.100.0.0/24"
{
"subnet": "10.100.0.0/24"
}
],
[
Expand Down Expand Up @@ -851,7 +851,7 @@ var _ = Describe("Kubernetes CNI tests", func() {
log.Infof("All container IPs: %v", contAddresses)
Expect(pod2IP).Should(Equal(expectedIP))

contNs.Do(func(_ ns.NetNS) error {
err = contNs.Do(func(_ ns.NetNS) error {
defer GinkgoRecover()
out, err := exec.Command("ip", "route", "show").Output()
Expect(err).NotTo(HaveOccurred())
Expand All @@ -878,6 +878,7 @@ var _ = Describe("Kubernetes CNI tests", func() {

return nil
})
Expect(err).ShouldNot(HaveOccurred())

_, err = testutils.DeleteContainer(netconfHostLocalIPAM, contNs.Path(), name2, testutils.K8S_TEST_NS)
Expect(err).ShouldNot(HaveOccurred())
Expand Down Expand Up @@ -1970,7 +1971,7 @@ var _ = Describe("Kubernetes CNI tests", func() {
// - CNI DEL using containerIDY (should actually delete the container)
It("should handle deletes for stale container IDs", func() {
// ADD the container with passing a CNI_CONTAINERID of "X".
_, result, _, _, _, contNs, err := testutils.CreateContainerWithId(netconf, name, testutils.K8S_TEST_NS, "", cniContainerIDX)
_, result, _, _, _, _, err := testutils.CreateContainerWithId(netconf, name, testutils.K8S_TEST_NS, "", cniContainerIDX)
Expect(err).ShouldNot(HaveOccurred())
log.Printf("Unmarshaled result: %v\n", result)

Expand Down Expand Up @@ -1999,7 +2000,7 @@ var _ = Describe("Kubernetes CNI tests", func() {
}

// ADD the container with passing a CNI_CONTAINERID of "Y"
_, result, _, _, _, contNs, err = testutils.CreateContainerWithId(netconf, name, testutils.K8S_TEST_NS, "", cniContainerIDY)
_, result, _, _, _, contNs, err := testutils.CreateContainerWithId(netconf, name, testutils.K8S_TEST_NS, "", cniContainerIDY)
Expect(err).ShouldNot(HaveOccurred())
log.Printf("Unmarshaled result: %v\n", result)

Expand Down
4 changes: 2 additions & 2 deletions tests/calico_cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ var _ = Describe("CalicoCni", func() {
Expect(err).ShouldNot(HaveOccurred())
r := false
ci.Spec.DatastoreReady = &r
ci, err = calicoClient.ClusterInformation().Update(ctx, ci, options.SetOptions{})
_, err = calicoClient.ClusterInformation().Update(ctx, ci, options.SetOptions{})
Expect(err).ShouldNot(HaveOccurred())
_, _, _, _, _, _, err = testutils.CreateContainer(netconf, "", testutils.TEST_DEFAULT_NS, "")
Expect(err).Should(HaveOccurred())
Expand All @@ -241,7 +241,7 @@ var _ = Describe("CalicoCni", func() {
Expect(err).ShouldNot(HaveOccurred())
r := false
ci.Spec.DatastoreReady = &r
ci, err = calicoClient.ClusterInformation().Update(ctx, ci, options.SetOptions{})
_, err = calicoClient.ClusterInformation().Update(ctx, ci, options.SetOptions{})
Expect(err).ShouldNot(HaveOccurred())

exitCode, err := testutils.DeleteContainer(netconf, contNs.Path(), "", testutils.TEST_DEFAULT_NS)
Expand Down

0 comments on commit e64b975

Please sign in to comment.