From add591d77c12fc71a218549fd1259eaa11de3c9c Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Fri, 20 Mar 2020 20:59:26 +0000 Subject: [PATCH] Move main package to cmd subdir --- Makefile | 6 +++++- build/build.sh | 9 ++++++--- cadvisor.go => cmd/cadvisor.go | 6 +++--- cadvisor_test.go => cmd/cadvisor_test.go | 5 ++--- storagedriver.go => cmd/storagedriver.go | 0 doc.go | 15 +++++++++++++++ 6 files changed, 31 insertions(+), 10 deletions(-) rename cadvisor.go => cmd/cadvisor.go (98%) rename cadvisor_test.go => cmd/cadvisor_test.go (98%) rename storagedriver.go => cmd/storagedriver.go (100%) create mode 100644 doc.go diff --git a/Makefile b/Makefile index ed1e0aea..8a608bdb 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ # limitations under the License. GO := go -pkgs = $(shell $(GO) list ./... | grep -v vendor) +pkgs = $(shell $(GO) list ./... | grep -v vendor) +cmd_pkgs = $(shell cd cmd && $(GO) list ./... | grep -v vendor) arch ?= $(shell go env GOARCH) ifeq ($(arch), amd64) @@ -28,6 +29,7 @@ all: presubmit build test test: @echo ">> running tests" @$(GO) test -short -race $(pkgs) + @cd cmd && $(GO) test -short -race $(cmd_pkgs) test-integration: GO_FLAGS="-race" ./build/build.sh @@ -41,10 +43,12 @@ test-runner: format: @echo ">> formatting code" @$(GO) fmt $(pkgs) + @cd cmd && $(GO) fmt $(cmd_pkgs) vet: @echo ">> vetting code" @$(GO) vet $(pkgs) + @cd cmd && $(GO) vet $(cmd_pkgs) build: assets @echo ">> building binaries" diff --git a/build/build.sh b/build/build.sh index 1b9b04fe..b8cae39b 100755 --- a/build/build.sh +++ b/build/build.sh @@ -50,12 +50,15 @@ if [ -n "$VERBOSE" ]; then echo "Building with -ldflags $ldflags" fi - +# Since github.com/google/cadvisor/cmd is a submodule, we must build from inside that directory +output_file="$PWD/cadvisor" +pushd cmd > /dev/null if [ -z "$GOARCH" ] then - GOBIN=$PWD go build ${GO_FLAGS} -ldflags "${ldflags}" "${repo_path}" + go build ${GO_FLAGS} -ldflags "${ldflags}" -o "${output_file}" "${repo_path}/cmd" else - GOBIN=$PWD env GOOS=linux GOARCH=$GOARCH go build ${GO_FLAGS} -ldflags "${ldflags}" "${repo_path}" + env GOOS=linux GOARCH=$GOARCH go build ${GO_FLAGS} -ldflags "${ldflags}" -o "${output_file}" "${repo_path}/cmd" fi +popd > /dev/null exit 0 diff --git a/cadvisor.go b/cmd/cadvisor.go similarity index 98% rename from cadvisor.go rename to cmd/cadvisor.go index 60b7cbcd..c4a6ff78 100644 --- a/cadvisor.go +++ b/cmd/cadvisor.go @@ -82,7 +82,7 @@ var ( container.NetworkAdvancedTcpUsageMetrics: struct{}{}, container.ProcessSchedulerMetrics: struct{}{}, container.ProcessMetrics: struct{}{}, - container.HugetlbUsageMetrics: struct{}{}, + container.HugetlbUsageMetrics: struct{}{}, }} // List of metrics that can be ignored. @@ -96,7 +96,7 @@ var ( container.PerCpuUsageMetrics: struct{}{}, container.ProcessSchedulerMetrics: struct{}{}, container.ProcessMetrics: struct{}{}, - container.HugetlbUsageMetrics: struct{}{}, + container.HugetlbUsageMetrics: struct{}{}, } ) @@ -106,7 +106,7 @@ type metricSetValue struct { func (ml *metricSetValue) String() string { var values []string - for metric, _ := range ml.MetricSet { + for metric := range ml.MetricSet { values = append(values, string(metric)) } return strings.Join(values, ",") diff --git a/cadvisor_test.go b/cmd/cadvisor_test.go similarity index 98% rename from cadvisor_test.go rename to cmd/cadvisor_test.go index c0feb87a..35f953ed 100644 --- a/cadvisor_test.go +++ b/cmd/cadvisor_test.go @@ -65,8 +65,7 @@ func TestToIncludedMetrics(t *testing.T) { { container.CpuUsageMetrics: struct{}{}, }, - { - }, + {}, container.AllMetrics, } @@ -85,7 +84,7 @@ func TestToIncludedMetrics(t *testing.T) { container.NetworkUdpUsageMetrics: struct{}{}, container.ProcessMetrics: struct{}{}, container.AppMetrics: struct{}{}, - container.HugetlbUsageMetrics: struct{}{}, + container.HugetlbUsageMetrics: struct{}{}, }, container.AllMetrics, {}, diff --git a/storagedriver.go b/cmd/storagedriver.go similarity index 100% rename from storagedriver.go rename to cmd/storagedriver.go diff --git a/doc.go b/doc.go new file mode 100644 index 00000000..a662525f --- /dev/null +++ b/doc.go @@ -0,0 +1,15 @@ +// Copyright 2020 Google Inc. All Rights Reserved. +// +// 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. + +package cadvisor