Skip to content

Commit c6a4347

Browse files
committed
DROPME: use controller-gen from fork
1 parent 599a20a commit c6a4347

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ CAPD_DIR := $(TEST_DIR)/infrastructure/docker
6666
CAPIM_DIR := $(TEST_DIR)/infrastructure/inmemory
6767
TEST_EXTENSION_DIR := $(TEST_DIR)/extension
6868
GO_INSTALL := ./scripts/go_install.sh
69+
GO_INSTALL_FORK := ./scripts/go_install_fork.sh
6970
OBSERVABILITY_DIR := hack/observability
7071

7172
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
@@ -106,10 +107,11 @@ SETUP_ENVTEST_BIN := setup-envtest
106107
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER))
107108
SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest
108109

109-
CONTROLLER_GEN_VER := v0.16.1
110+
CONTROLLER_GEN_VER := 28f149a996f13a897b7b60ad18f4080b9a183ff9
110111
CONTROLLER_GEN_BIN := controller-gen
111112
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER))
112113
CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen
114+
CONTROLLER_GEN_PKG_REPLACE := sigs.k8s.io/controller-tools=github.com/chrischdi/controller-tools
113115

114116
GOTESTSUM_VER := v1.11.0
115117
GOTESTSUM_BIN := gotestsum
@@ -1426,7 +1428,7 @@ $(GOVULNCHECK_BIN): $(GOVULNCHECK) ## Build a local copy of govulncheck.
14261428
$(IMPORT_BOSS_BIN): $(IMPORT_BOSS)
14271429

14281430
$(CONTROLLER_GEN): # Build controller-gen from tools folder.
1429-
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(CONTROLLER_GEN_PKG) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER)
1431+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL_FORK) $(CONTROLLER_GEN_PKG) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER) $(CONTROLLER_GEN_PKG_REPLACE)
14301432

14311433
## We are forcing a rebuilt of conversion-gen via PHONY so that we're always using an up-to-date version.
14321434
## We can't use a versioned name for the binary, because that would be reflected in generated files.

scripts/go_install_fork.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2021 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
if [ -z "${1}" ]; then
21+
echo "must provide module as first parameter"
22+
exit 1
23+
fi
24+
25+
if [ -z "${2}" ]; then
26+
echo "must provide binary name as second parameter"
27+
exit 1
28+
fi
29+
30+
if [ -z "${3}" ]; then
31+
echo "must provide version as third parameter"
32+
exit 1
33+
fi
34+
35+
if [ -z "${4}" ]; then
36+
echo "must provide the replace parameter as third parameter"
37+
exit 1
38+
fi
39+
40+
if [ -z "${GOBIN}" ]; then
41+
echo "GOBIN is not set. Must set GOBIN to install the bin in a specified directory."
42+
exit 1
43+
fi
44+
45+
rm -f "${GOBIN}/${2}"* || true
46+
47+
export GOWORK="off"
48+
49+
ORIGINAL_WORKDIR="$(pwd)"
50+
TMP_MODULE_DIR="${2}.tmp"
51+
52+
# Create TMP_MODULE_DIR to create a go module for building the binary.
53+
# This is required because CAPI's hack/tools is not compatible to `go install`.
54+
rm -r "${TMP_MODULE_DIR}" || true
55+
mkdir -p "${TMP_MODULE_DIR}"
56+
cd "${TMP_MODULE_DIR}"
57+
58+
# Initialize a go module and place a tools.go file for building the binary.
59+
go mod init "tools"
60+
61+
# Set a replace from the original module to the fork
62+
go mod edit -replace "${4}@${3}"
63+
64+
# Create go file which imports the required package and resolve dependencies.
65+
cat << EOF > tools.go
66+
//go:build tools
67+
// +build tools
68+
package tools
69+
70+
import (
71+
_ "${1}"
72+
)
73+
EOF
74+
75+
go mod tidy
76+
77+
# Build the binary.
78+
go build -tags=tools -o "${GOBIN}/${2}-${3}" "${1}"
79+
80+
# Get back to the original directory and cleanup the temporary directory.
81+
cd "${ORIGINAL_WORKDIR}"
82+
rm -r "${TMP_MODULE_DIR}"
83+
84+
# Link the unversioned name to the versioned binary.
85+
ln -sf "${GOBIN}/${2}-${3}" "${GOBIN}/${2}"

0 commit comments

Comments
 (0)