diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..eaaf8de64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +_output/* diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..60bff994a --- /dev/null +++ b/Makefile @@ -0,0 +1,81 @@ +GO ?= go +EPOCH_TEST_COMMIT ?= f2925f58acc259c4b894353f5fc404bdeb40028e +PROJECT := github.com/kubernetes-incubator/cri-containerd +BINDIR ?= ${DESTDIR}/usr/local/bin +BUILD_DIR ?= _output + +all: binaries + +default: help + +help: + @echo "Usage: make " + @echo + @echo " * 'install' - Install binaries to system locations" + @echo " * 'binaries' - Build cri-containerd" + @echo " * 'clean' - Clean artifacts" + @echo " * 'verify' - Execute the source code verification tools" + @echo " * 'install.tools' - Installs tools used by verify" + @echo " * 'uninstall' - Remove installed binaries from system locations" + +.PHONY: check-gopath + +check-gopath: +ifndef GOPATH + $(error GOPATH is not set) +endif + +verify: lint gofmt + +lint: check-gopath + @echo "checking lint" + @./hack/lint.sh + +gofmt: + @echo "checking gofmt" + @./hack/verify-gofmt.sh + +cri-containerd: check-gopath + $(GO) build -o $(BUILD_DIR)/$@ \ + $(PROJECT)/cmd/cri-containerd + +clean: + rm -f $(BUILD_DIR)/cri-containerd + +binaries: cri-containerd + +install: check-gopath + install -D -m 755 $(BUILD_DIR)/cri-containerd $(BINDIR)/cri-containerd + +uninstall: + rm -f $(BINDIR)/cri-containerd + +.PHONY: .gitvalidation +# When this is running in travis, it will only check the travis commit range +.gitvalidation: check-gopath +ifeq ($(TRAVIS),true) + git-validation -q -run DCO,short-subject +else + git-validation -v -run DCO,short-subject -range $(EPOCH_TEST_COMMIT)..HEAD +endif + +.PHONY: install.tools .install.gitvalidation .install.gometalinter + +install.tools: .install.gitvalidation .install.gometalinter + +.install.gitvalidation: + go get -u github.com/vbatts/git-validation + +.install.gometalinter: + go get -u github.com/alecthomas/gometalinter + gometalinter --install + +.PHONY: \ + binaries \ + clean \ + default \ + gofmt \ + help \ + install \ + lint \ + uninstall diff --git a/cmd/cri-containerd/options/options.go b/cmd/cri-containerd/options/options.go index b21ca4bc8..7838f118e 100644 --- a/cmd/cri-containerd/options/options.go +++ b/cmd/cri-containerd/options/options.go @@ -33,6 +33,7 @@ type CRIContainerdOptions struct { ContainerdConnectionTimeout time.Duration } +// NewCRIContainerdOptions returns a reference to CRIContainerdOptions func NewCRIContainerdOptions() *CRIContainerdOptions { return &CRIContainerdOptions{} } @@ -47,6 +48,10 @@ func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) { 2*time.Minute, "Connection timeout for containerd client.") } +// InitFlags must be called after adding all cli options flags are defined and +// before flags are accessed by the program. Ths fuction adds flag.CommandLine +// (the default set of command-line flags, parsed from os.Args) and then calls +// pflag.Parse(). func InitFlags() { pflag.CommandLine.AddGoFlagSet(flag.CommandLine) pflag.Parse() diff --git a/hack/lint.sh b/hack/lint.sh new file mode 100755 index 000000000..9b10f6883 --- /dev/null +++ b/hack/lint.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +for d in $(find . -type d -a \( -iwholename './pkg*' -o -iwholename './cmd*' \)); do + echo for directory ${d} ... + gometalinter \ + --exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \ + --exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \ + --exclude='duplicate of.*_test.go.*\(dupl\)$' \ + --disable=aligncheck \ + --disable=gotype \ + --disable=gas \ + --cyclo-over=60 \ + --dupl-threshold=100 \ + --tests \ + --deadline=30s "${d}" +done diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh new file mode 100755 index 000000000..1f09fd2b1 --- /dev/null +++ b/hack/verify-gofmt.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +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 diff --git a/pkg/server/service.go b/pkg/server/service.go index 18ac41474..90cf0a732 100644 --- a/pkg/server/service.go +++ b/pkg/server/service.go @@ -21,6 +21,9 @@ import ( "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" + // TODO remove the underscores from the following imports as the services are + // implemented. "_" is being used to hold the reference to keep autocomplete + // from deleting them until referenced below. _ "github.com/containerd/containerd/api/services/content" _ "github.com/containerd/containerd/api/services/execution" _ "github.com/containerd/containerd/api/services/images" @@ -41,6 +44,7 @@ type CRIContainerdService interface { // criContainerdService implements CRIContainerdService. type criContainerdService struct{} +// NewCRIContainerdService returns a new instance of CRIContainerdService func NewCRIContainerdService(conn *grpc.ClientConn) CRIContainerdService { // TODO: Initialize different containerd clients. return &criContainerdService{}