Skip to content

Commit

Permalink
Merge pull request #505 from BenTheElder/use-more-modules
Browse files Browse the repository at this point in the history
use modules, remove vendor
  • Loading branch information
k8s-ci-robot authored May 8, 2019
2 parents 981ec1d + 7613bf5 commit d9f8b03
Show file tree
Hide file tree
Showing 1,267 changed files with 167 additions and 594,245 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/_output
/_artifacts

# used for the code generators
/vendor

# macOS
.DS_Store

Expand Down
26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
# Only requires docker on the host

# settings
REPO_ROOT=$(PWD)
REPO_ROOT:=${CURDIR}
# autodetect host GOOS and GOARCH by default, even if go is not installed
GOOS=$(shell hack/goos.sh)
GOARCH=$(shell hack/goarch.sh)
GOOS=$(shell hack/util/goos.sh)
GOARCH=$(shell hack/util/goarch.sh)
INSTALL_DIR=$(shell hack/util/goinstalldir.sh)
# use the official module proxy by default
GOPROXY=https://proxy.golang.org
# default build image
Expand All @@ -31,6 +32,7 @@ CACHE_VOLUME=kind-build-cache
# variables for consistent logic, don't override these
CONTAINER_REPO_DIR=/src/kind
CONTAINER_OUT_DIR=$(CONTAINER_REPO_DIR)/_output/bin
HOST_OUT_DIR=$(REPO_ROOT)/_output/bin

# standard "make" target -> builds
all: build
Expand All @@ -43,8 +45,16 @@ make-cache:
clean-cache:
docker volume rm $(CACHE_VOLUME)

# creates the output directory
out-dir:
mkdir -p $(REPO_ROOT)/_output/bin

# cleans the output directory
clean-output:
rm -rf $(REPO_ROOT)/_output

# builds kind in a container, outputs to $(REPO_ROOT)/_output/bin
kind: make-cache
kind: make-cache out-dir
docker run \
--rm \
-v $(CACHE_VOLUME):/go \
Expand All @@ -62,7 +72,11 @@ kind: make-cache
# alias for building kind
build: kind

# use: make install INSTALL_DIR=/usr/local/bin
install: build
cp $(HOST_OUT_DIR)/kind $(INSTALL_DIR)/kind

# standard cleanup target
clean: clean-cache
clean: clean-cache clean-output

.PHONY: make-cache clean-cache kind build all clean
.PHONY: all make-cache clean-cache out-dir clean-output kind build install clean
16 changes: 3 additions & 13 deletions hack/build/push-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,9 @@ set -o pipefail
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"

# place to stick temp binaries
BINDIR="${REPO_ROOT}/_output/bin"

# install kind from the repo into $BINDIR
get_kind() {
# build kind from the repo and use that ...
GOBIN="${BINDIR}" go install .
echo "${BINDIR}/kind"
}

# select kind binary to use
KIND="${KIND:-$(get_kind)}"
# ensure we have up to date kind
make build
KIND="${REPO_ROOT}/_output/bin/kind"

# generate tag
DATE="$(date +v%Y%m%d)"
Expand All @@ -44,4 +35,3 @@ IMAGE="kindest/base:${TAG}"

# push
docker push "${IMAGE}"

17 changes: 3 additions & 14 deletions hack/build/push-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,9 @@ set -o pipefail
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"

# place to stick temp binaries
BINDIR="${REPO_ROOT}/_output/bin"

# install kind from the repo into $BINDIR
get_kind() {
# build kind from the repo and use that ...
GOBIN="${BINDIR}" go install .
echo "${BINDIR}/kind"
}

# select kind binary to use
KIND="${KIND:-$(get_kind)}"
# ensure we have up to date kind
make build
KIND="${REPO_ROOT}/_output/bin/kind"

# generate tag
DATE="$(date +v%Y%m%d)"
Expand All @@ -50,5 +41,3 @@ docker tag "${IMG}" "kindest/node:${KUBE_VERSION}"

# push
docker push kindest/node:"${KUBE_VERSION}"


12 changes: 7 additions & 5 deletions hack/ci/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ set -o pipefail
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"

# build kind
set -x
# TODO(bentheelder): find a solution that does not depend on GO111MODULE="off"
# we could use -mod vendor, but only go 1.11+ will understand this
GO111MODULE="off" go install -v .
# enable modules and the proxy cache
export GO111MODULE="on"
GOPROXY="${GOPROXY:-https://proxy.golang.org}"
export GOPROXY

# build
go install -v .
11 changes: 5 additions & 6 deletions hack/ci/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ install_kind() {
TMP_DIR=$(mktemp -d)
# ensure bin dir
mkdir -p "${TMP_DIR}/bin"
# if we have a kind checkout, install that to the tmpdir, otherwise go get it
if [[ $(go list sigs.k8s.io/kind) = "sigs.k8s.io/kind" ]]; then
env "GOBIN=${TMP_DIR}/bin" go install sigs.k8s.io/kind
else
env "GOPATH=${TMP_DIR}" go get -u sigs.k8s.io/kind
fi
# install
local script_dir
script_dir="$(dirname "${BASH_SOURCE[0]}")"
make -C "${script_dir}/../.." install INSTALL_PATH="${TMP_DIR}/bin"
# ensure it is in path
PATH="${TMP_DIR}/bin:${PATH}"
export PATH
}
Expand Down
27 changes: 4 additions & 23 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,9 @@ set -o pipefail
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"

prune-vendor() {
find vendor -type f \
-not -iname "*.c" \
-not -iname "*.go" \
-not -iname "*.h" \
-not -iname "*.proto" \
-not -iname "*.s" \
-not -iname "AUTHORS*" \
-not -iname "CONTRIBUTORS*" \
-not -iname "COPYING*" \
-not -iname "LICENSE*" \
-not -iname "NOTICE*" \
-exec rm '{}' \;
}

# enable modules and the proxy cache
export GO111MODULE="on"
go mod tidy
go mod vendor
prune-vendor
GOPROXY="${GOPROXY:-https://proxy.golang.org}"
export GOPROXY

# TODO(bentheelder): re-enable once (if?) we're using docker client
# docker has a contrib dir with nothing we use in it, dep will retain only the
# licenses, so we manually prune this directory.
# See https://github.com/kubernetes/steering/issues/57
#rm -rf vendor/github.com/docker/docker/contrib
go mod tidy
57 changes: 37 additions & 20 deletions hack/update-generated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,49 @@ set -o errexit
set -o pipefail

REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"

# enable modules and the proxy cache
export GO111MODULE="on"
GOPROXY="${GOPROXY:-https://proxy.golang.org}"
export GOPROXY

# build the generators
BINDIR="${REPO_ROOT}/_output/bin"
go build -o "${BINDIR}/defaulter-gen" k8s.io/code-generator/cmd/defaulter-gen
go build -o "${BINDIR}/deepcopy-gen" k8s.io/code-generator/cmd/deepcopy-gen
go build -o "${BINDIR}/conversion-gen" k8s.io/code-generator/cmd/conversion-gen

# TODO(bentheelder): find a solution that does not depend on GO111MODULE="off"
# turn off module mode before running the generators
# https://github.com/kubernetes/code-generator/issues/69
# we also need to populate vendor
go mod vendor
export GO111MODULE="off"

# install go-bindata from vendor locally
OUTPUT_GOBIN="${REPO_ROOT}/_output/bin"
cd "${REPO_ROOT}"
GOBIN="${OUTPUT_GOBIN}" go install ./vendor/k8s.io/code-generator/cmd/defaulter-gen
GOBIN="${OUTPUT_GOBIN}" go install ./vendor/k8s.io/code-generator/cmd/deepcopy-gen
GOBIN="${OUTPUT_GOBIN}" go install ./vendor/k8s.io/code-generator/cmd/conversion-gen
# fake being in a gopath
FAKE_GOPATH="$(mktemp -d)"
trap 'rm -rf ${FAKE_GOPATH}' EXIT

FAKE_REPOPATH="${FAKE_GOPATH}/src/sigs.k8s.io/kind"
mkdir -p "$(dirname "${FAKE_REPOPATH}")" && ln -s "${REPO_ROOT}" "${FAKE_REPOPATH}"

export GOPATH="${FAKE_GOPATH}"
cd "${FAKE_REPOPATH}"

# go generate (using go-bindata)
# NOTE: go will only take package paths, not absolute directories
export PATH="${OUTPUT_GOBIN}:${PATH}"
go generate ./...
# run the generators
"${BINDIR}/deepcopy-gen" -i ./pkg/cluster/config/ -O zz_generated.deepcopy --go-header-file hack/boilerplate.go.txt
"${BINDIR}/defaulter-gen" -i ./pkg/cluster/config/ -O zz_generated.default --go-header-file hack/boilerplate.go.txt

deepcopy-gen -i ./pkg/cluster/config/ -O zz_generated.deepcopy --go-header-file hack/boilerplate.go.txt
defaulter-gen -i ./pkg/cluster/config/ -O zz_generated.default --go-header-file hack/boilerplate.go.txt
"${BINDIR}/deepcopy-gen" -i ./pkg/cluster/config/v1alpha2 -O zz_generated.deepcopy --go-header-file hack/boilerplate.go.txt
"${BINDIR}/defaulter-gen" -i ./pkg/cluster/config/v1alpha2 -O zz_generated.default --go-header-file hack/boilerplate.go.txt
"${BINDIR}/conversion-gen" -i ./pkg/cluster/config/v1alpha2 -O zz_generated.conversion --go-header-file hack/boilerplate.go.txt

deepcopy-gen -i ./pkg/cluster/config/v1alpha2 -O zz_generated.deepcopy --go-header-file hack/boilerplate.go.txt
defaulter-gen -i ./pkg/cluster/config/v1alpha2 -O zz_generated.default --go-header-file hack/boilerplate.go.txt
conversion-gen -i ./pkg/cluster/config/v1alpha2 -O zz_generated.conversion --go-header-file hack/boilerplate.go.txt
"${BINDIR}/deepcopy-gen" -i ./pkg/cluster/config/v1alpha3 -O zz_generated.deepcopy --go-header-file hack/boilerplate.go.txt
"${BINDIR}/defaulter-gen" -i ./pkg/cluster/config/v1alpha3 -O zz_generated.default --go-header-file hack/boilerplate.go.txt
"${BINDIR}/conversion-gen" -i ./pkg/cluster/config/v1alpha3 -O zz_generated.conversion --go-header-file hack/boilerplate.go.txt

deepcopy-gen -i ./pkg/cluster/config/v1alpha3 -O zz_generated.deepcopy --go-header-file hack/boilerplate.go.txt
defaulter-gen -i ./pkg/cluster/config/v1alpha3 -O zz_generated.default --go-header-file hack/boilerplate.go.txt
conversion-gen -i ./pkg/cluster/config/v1alpha3 -O zz_generated.conversion --go-header-file hack/boilerplate.go.txt
export GO111MODULE="on"
cd $REPO_ROOT

# gofmt the tree
find . -path "./vendor" -prune -o -name "*.go" -type f -print0 | xargs -0 gofmt -s -w
find . -name "*.go" -type f -print0 | xargs -0 gofmt -s -w
2 changes: 1 addition & 1 deletion hack/update-gofmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set -o errexit
set -o nounset
set -o pipefail

find . -name "*.go" | grep -v "\\/vendor\\/" | xargs gofmt -s -w
find . -name "*.go" -type f -print0 | xargs -0 gofmt -s -w
File renamed without changes.
47 changes: 47 additions & 0 deletions hack/util/goinstalldir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh
# Copyright 2019 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.

# this utility prints out the golang install dir even if go is not installed

# if we have go, just ask go!
if which go >/dev/null 2>&1; then
DIR=$(go env GOBIN)
if [ -n "${DIR}" ]; then
echo "${DIR}"
exit 0
fi
DIR=$(go env GOPATH)
if [ -n "${DIR}" ]; then
echo "${DIR}/bin"
exit 0
fi
fi

# mimic go behavior

# check if GOBIN is set anyhow
if [ -n "${GOBIN}" ]; then
echo "GOBIN"
exit 0
fi

# check if GOPATH is set anyhow
if [ -n "${GOPATH}" ]; then
echo "${GOPATH}/bin"
exit 0
fi

# finally use default for no $GOPATH or $GOBIN
echo "${HOME}/go/bin"
File renamed without changes.
6 changes: 0 additions & 6 deletions hack/verify-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ if [[ "${VERIFY_GENERATED:-true}" == "true" ]]; then
cd "${REPO_ROOT}"
fi

if [[ "${VERIFY_DEPS:-true}" == "true" ]]; then
echo "verifying deps ..."
hack/verify-deps.sh || res=1
cd "${REPO_ROOT}"
fi

# exit based on verify scripts
if [[ "${res}" = 0 ]]; then
echo ""
Expand Down
Loading

0 comments on commit d9f8b03

Please sign in to comment.