Merge pull request #274 from Crazykev/gofmt-check

Enable Gofmt check in CI
This commit is contained in:
Mrunal Patel 2016-12-15 16:57:16 -08:00 committed by GitHub
commit 5a769f72ca
6 changed files with 37 additions and 10 deletions

View file

@ -17,6 +17,7 @@ before_script:
script: script:
- make .gitvalidation - make .gitvalidation
- make gofmt
- make lint - make lint
- make integration - make integration
- make docs - make docs

View file

@ -30,6 +30,7 @@ help:
@echo " * 'integration' - Execute integration tests" @echo " * 'integration' - Execute integration tests"
@echo " * 'clean' - Clean artifacts" @echo " * 'clean' - Clean artifacts"
@echo " * 'lint' - Execute the source code linter" @echo " * 'lint' - Execute the source code linter"
@echo " * 'gofmt' - Verify the source code gofmt"
lint: ${OCID_LINK} lint: ${OCID_LINK}
@which gometalinter > /dev/null 2>/dev/null || (echo "ERROR: gometalinter not found. Consider 'make install.tools' target" && false) @which gometalinter > /dev/null 2>/dev/null || (echo "ERROR: gometalinter not found. Consider 'make install.tools' target" && false)
@ -40,6 +41,9 @@ ${OCID_LINK}:
mkdir -p ${OCID_LINK_DIR} mkdir -p ${OCID_LINK_DIR}
ln -sfn ${CURDIR} ${OCID_LINK} ln -sfn ${CURDIR} ${OCID_LINK}
gofmt:
@./hack/verify-gofmt.sh
conmon: conmon:
make -C $@ make -C $@
@ -164,6 +168,7 @@ install.tools: .install.gitvalidation .install.gometalinter .install.md2man
conmon \ conmon \
default \ default \
docs \ docs \
gofmt \
help \ help \
install \ install \
lint \ lint \

21
hack/verify-gofmt.sh Executable file
View file

@ -0,0 +1,21 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
find_files() {
find . -not \( \
\( \
-wholename '*/vendor/*' \
\) -prune \
\) -name '*.go'
}
GOFMT="gofmt -s"
bad_files=$(find_files | xargs $GOFMT -l)
if [[ -n "${bad_files}" ]]; then
echo "!!! '$GOFMT' needs to be run on the following files: "
echo "${bad_files}"
exit 1
fi

View file

@ -25,11 +25,11 @@ func (s *Server) Status(ctx context.Context, req *pb.StatusRequest) (*pb.StatusR
resp := &pb.StatusResponse{ resp := &pb.StatusResponse{
Status: &pb.RuntimeStatus{ Status: &pb.RuntimeStatus{
Conditions: []*pb.RuntimeCondition{ Conditions: []*pb.RuntimeCondition{
&pb.RuntimeCondition{ {
Type: &runtimeReadyConditionString, Type: &runtimeReadyConditionString,
Status: &runtimeReady, Status: &runtimeReady,
}, },
&pb.RuntimeCondition{ {
Type: &networkReadyConditionString, Type: &networkReadyConditionString,
Status: &networkReady, Status: &networkReady,
}, },

View file

@ -9,20 +9,20 @@ import (
"sync" "sync"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/containernetworking/cni/pkg/ns"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/kubernetes-incubator/cri-o/oci" "github.com/kubernetes-incubator/cri-o/oci"
"github.com/containernetworking/cni/pkg/ns" "golang.org/x/sys/unix"
"k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/fields"
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
"golang.org/x/sys/unix"
) )
type sandboxNetNs struct { type sandboxNetNs struct {
sync.Mutex sync.Mutex
ns ns.NetNS ns ns.NetNS
symlink *os.File symlink *os.File
closed bool closed bool
restored bool restored bool
} }
func (ns *sandboxNetNs) symlinkCreate(name string) error { func (ns *sandboxNetNs) symlinkCreate(name string) error {
@ -190,7 +190,7 @@ func (s *sandbox) netNsCreate() error {
} }
s.netns = &sandboxNetNs{ s.netns = &sandboxNetNs{
ns: netNS, ns: netNS,
closed: false, closed: false,
} }

View file

@ -273,7 +273,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
if netnsErr := sb.netNsRemove(); netnsErr != nil { if netnsErr := sb.netNsRemove(); netnsErr != nil {
logrus.Warnf("Failed to remove networking namespace: %v", netnsErr) logrus.Warnf("Failed to remove networking namespace: %v", netnsErr)
} }
} () }()
// Pass the created namespace path to the runtime // Pass the created namespace path to the runtime
err = g.AddOrReplaceLinuxNamespace("network", sb.netNsPath()) err = g.AddOrReplaceLinuxNamespace("network", sb.netNsPath())