Move main package to cmd subdir

This commit is contained in:
Jordan Liggitt 2020-03-20 20:59:26 +00:00
parent 649c1bb863
commit add591d77c
6 changed files with 31 additions and 10 deletions

View File

@ -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"

View File

@ -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

View File

@ -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, ",")

View File

@ -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,
{},

15
doc.go Normal file
View File

@ -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