Skip to content

Commit

Permalink
Move main package to cmd subdir
Browse files Browse the repository at this point in the history
  • Loading branch information
liggitt committed Mar 21, 2020
1 parent 649c1bb commit add591d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions cadvisor.go → cmd/cadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -96,7 +96,7 @@ var (
container.PerCpuUsageMetrics: struct{}{},
container.ProcessSchedulerMetrics: struct{}{},
container.ProcessMetrics: struct{}{},
container.HugetlbUsageMetrics: struct{}{},
container.HugetlbUsageMetrics: struct{}{},
}
)

Expand All @@ -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, ",")
Expand Down
5 changes: 2 additions & 3 deletions cadvisor_test.go → cmd/cadvisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func TestToIncludedMetrics(t *testing.T) {
{
container.CpuUsageMetrics: struct{}{},
},
{
},
{},
container.AllMetrics,
}

Expand All @@ -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,
{},
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit add591d

Please sign in to comment.