-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1023 from sthaha/fix-kc-build-manifest
fix(build): support newer version of kubectl
- Loading branch information
Showing
4 changed files
with
287 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,23 +121,11 @@ ifndef GOBIN | |
GOBIN := $(GOPATH)/bin | ||
endif | ||
|
||
KUSTOMIZE = $(shell pwd)/bin/kustomize | ||
|
||
# go-get-tool will 'go get' any package $2 and install it to $1. | ||
# NOTE: project related tools get installed to tmp dir which is ignored by | ||
PROJECT_DIR := $(shell dirname $(abspath $(firstword $(MAKEFILE_LIST)))) | ||
define go-get-tool | ||
@[ -f $(1) ] || { \ | ||
set -e ;\ | ||
TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
echo "Downloading $(2)" ;\ | ||
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ | ||
ls $$TMP_DIR;\ | ||
echo $(PROJECT_DIR);\ | ||
rm -rf $$TMP_DIR ;\ | ||
} | ||
endef | ||
TOOLS_DIR=$(PROJECT_DIR)/tmp/bin | ||
KUSTOMIZE = $(TOOLS_DIR)/kustomize | ||
GOVULNCHECK = $(TOOLS_DIR)/govulncheck | ||
|
||
base_dir := $(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST))))) | ||
|
||
|
@@ -294,10 +282,10 @@ escapes_detect: tidy-vendor | |
@$(GOENV) go build -tags $(GO_BUILD_TAGS) -gcflags="-m -l" ./... 2>&1 | grep "escapes to heap" || true | ||
|
||
set_govulncheck: | ||
@go install golang.org/x/vuln/cmd/govulncheck@latest | ||
./hack/tools.sh govulncheck | ||
|
||
govulncheck: set_govulncheck tidy-vendor | ||
@govulncheck -v ./... || true | ||
@$(GOVULNCHECK) ./... || true | ||
|
||
format: | ||
./automation/presubmit-tests/gofmt.sh | ||
|
@@ -318,10 +306,14 @@ genbpfassets: | |
|
||
genlibbpf: kepler.bpf.o | ||
|
||
|
||
tools: | ||
hack/tools.sh | ||
.PHONY: tools | ||
|
||
### k8s ### | ||
kustomize: ## Download kustomize locally if necessary. | ||
mkdir -p bin | ||
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected]) | ||
hack/tools.sh kustomize | ||
|
||
build-manifest: kustomize | ||
./hack/build-manifest.sh "${OPTS}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# This file is part of the Kepler project | ||
# | ||
# 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. | ||
# | ||
# Copyright 2023 The Kepler Contributors | ||
# | ||
|
||
set -eu -o pipefail | ||
|
||
# constants | ||
PROJECT_ROOT="$(git rev-parse --show-toplevel)" | ||
GOOS="$(go env GOOS)" | ||
GOARCH="$(go env GOARCH)" | ||
|
||
declare -r PROJECT_ROOT GOOS GOARCH | ||
declare -r LOCAL_BIN="$PROJECT_ROOT/tmp/bin" | ||
|
||
# tools | ||
declare -r KUSTOMIZE_VERSION=${KUSTOMIZE_VERSION:-v4.5.2} | ||
declare -r KUSTOMIZE_INSTALL_SCRIPT="https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | ||
|
||
declare -r JQ_VERSION=${JQ_VERSION:-1.7} | ||
declare -r JQ_INSTALL_URL="https://github.com/jqlang/jq/releases/download/jq-$JQ_VERSION/jq-$GOOS-$GOARCH" | ||
|
||
source "$PROJECT_ROOT/hack/utils.bash" | ||
|
||
validate_version() { | ||
local cmd="$1" | ||
local version_arg="$2" | ||
local version_regex="$3" | ||
shift 3 | ||
|
||
command -v "$cmd" >/dev/null 2>&1 || return 1 | ||
[[ $(eval "$cmd $version_arg" | grep -o "$version_regex") =~ $version_regex ]] || { | ||
return 1 | ||
} | ||
|
||
ok "$cmd installed successfully" | ||
} | ||
|
||
install_kustomize() { | ||
command -v kustomize >/dev/null 2>&1 && | ||
[[ $(kustomize version --short | grep -o 'v[0-9].[0-9].[0-9]') == "$KUSTOMIZE_VERSION" ]] && { | ||
ok "kustomize $KUSTOMIZE_VERSION is already installed" | ||
return 0 | ||
} | ||
|
||
info "installing kustomize version: $KUSTOMIZE_VERSION" | ||
( | ||
# NOTE: this handles softlinks properly | ||
cd "$LOCAL_BIN" | ||
curl -Ss $KUSTOMIZE_INSTALL_SCRIPT | bash -s -- "${KUSTOMIZE_VERSION:1}" . | ||
) || { | ||
fail "failed to install kustomize" | ||
return 1 | ||
} | ||
ok "kustomize was installed successfully" | ||
} | ||
|
||
go_install() { | ||
local pkg="$1" | ||
local version="$2" | ||
shift 2 | ||
|
||
info "installing $pkg version: $version" | ||
|
||
GOBIN=$LOCAL_BIN \ | ||
go install "$pkg@$version" || { | ||
fail "failed to install $pkg - $version" | ||
return 1 | ||
} | ||
ok "$pkg - $version was installed successfully" | ||
|
||
} | ||
|
||
curl_install() { | ||
local binary="$1" | ||
local url="$2" | ||
shift 2 | ||
|
||
info "installing $binary" | ||
curl -sSLo "$LOCAL_BIN/$binary" "$url" || { | ||
fail "failed to install $binary" | ||
return 1 | ||
} | ||
|
||
chmod +x "$LOCAL_BIN/$binary" | ||
ok "$binary was installed successfully" | ||
} | ||
|
||
install_jq() { | ||
validate_version jq --version "$JQ_VERSION" && { | ||
return 0 | ||
} | ||
curl_install jq "$JQ_INSTALL_URL" | ||
} | ||
|
||
install_govulncheck() { | ||
go_install golang.org/x/vuln/cmd/govulncheck latest | ||
} | ||
|
||
install_all() { | ||
info "installing all tools ..." | ||
local ret=0 | ||
for tool in $(declare -F | cut -f3 -d ' ' | grep install_ | grep -v 'install_all'); do | ||
"$tool" || ret=1 | ||
done | ||
return $ret | ||
} | ||
|
||
main() { | ||
local op="${1:-all}" | ||
shift || true | ||
|
||
mkdir -p "$LOCAL_BIN" | ||
export PATH="$LOCAL_BIN:$PATH" | ||
install_"$op" | ||
} | ||
|
||
main "$@" |
Oops, something went wrong.