Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
initial makefile (#7)
Browse files Browse the repository at this point in the history
* adds initial makefile

Signed-off-by: Mike Brown <[email protected]>

* clean up lint

Signed-off-by: Mike Brown <[email protected]>

* presume path is set to contain gomealinter

Signed-off-by: Mike Brown <[email protected]>

* addresses requested improvements

Signed-off-by: Mike Brown <[email protected]>
  • Loading branch information
mikebrow authored Apr 19, 2017
1 parent b573437 commit 11ba1cb
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_output/*
81 changes: 81 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 <target>"
@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
5 changes: 5 additions & 0 deletions cmd/cri-containerd/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type CRIContainerdOptions struct {
ContainerdConnectionTimeout time.Duration
}

// NewCRIContainerdOptions returns a reference to CRIContainerdOptions
func NewCRIContainerdOptions() *CRIContainerdOptions {
return &CRIContainerdOptions{}
}
Expand All @@ -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()
Expand Down
33 changes: 33 additions & 0 deletions hack/lint.sh
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions pkg/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{}
Expand Down

0 comments on commit 11ba1cb

Please sign in to comment.