mirror of
https://github.com/wahyd4/cert-manager.git
synced 2026-08-09 05:06:38 +10:00
Ensures conversion code temp workaround works for Go 1.17
Also refactor Signed-off-by: irbekrm <irbekrm@gmail.com>
This commit is contained in:
@@ -164,6 +164,10 @@ sh_binary(
|
||||
"@io_k8s_code_generator//cmd/informer-gen",
|
||||
"@io_k8s_code_generator//cmd/lister-gen",
|
||||
],
|
||||
deps = [
|
||||
":utils",
|
||||
"@bazel_tools//tools/bash/runfiles",
|
||||
],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
@@ -273,3 +277,8 @@ filegroup(
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
sh_library(
|
||||
name = "utils",
|
||||
srcs = ["utils.sh"],
|
||||
)
|
||||
|
||||
+29
-26
@@ -14,10 +14,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel
|
||||
echo "Updating generated clients..." >&2
|
||||
elif ! command -v bazel &>/dev/null; then
|
||||
@@ -31,8 +27,27 @@ else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# This has been copied from https://github.com/bazelbuild/bazel/blob/master/tools/bash/runfiles/runfiles.bash
|
||||
# It exports rlocation function that can be used to access other bash scripts in this codebase.
|
||||
# set -e pipefail needs to happen after sourcing runfiles.bash, see https://github.com/bazelbuild/bazel/blob/master/tools/bash/runfiles/runfiles.bash#L21
|
||||
|
||||
# --- begin runfiles.bash initialization v2 ---
|
||||
# Copy-pasted from the Bazel Bash runfiles library v2.
|
||||
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
||||
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
||||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
|
||||
source "$0.runfiles/$f" 2>/dev/null || \
|
||||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
|
||||
# --- end runfiles.bash initialization v2 ---
|
||||
|
||||
|
||||
module_name="github.com/jetstack/cert-manager"
|
||||
|
||||
# Access to util functions
|
||||
source "$(rlocation com_github_jetstack_cert_manager/hack/utils.sh)"
|
||||
|
||||
# Generate deepcopy functions for all internal and external APIs
|
||||
deepcopy_inputs=(
|
||||
pkg/apis/certmanager/v1alpha2 \
|
||||
@@ -244,29 +259,23 @@ gen-defaulters() {
|
||||
done
|
||||
}
|
||||
|
||||
# TODO: fix the workarounds in this function, files that start with "// +build !ignore_autogenerated"
|
||||
# are ignored by the conversion-gen tool, causing an incorrect 'zz_generated.conversion.go' to be generated.
|
||||
# This bug should get resolved in https://github.com/kubernetes/kubernetes/issues/101567
|
||||
# TODO: fix the workarounds in this function, files that start with "// +build
|
||||
# !ignore_autogenerated" and "//go:build !ignore_autogenerated" are ignored by the
|
||||
# conversion-gen tool, causing an incorrect 'zz_generated.conversion.go' to be
|
||||
# generated. This bug should get resolved in
|
||||
# https://github.com/kubernetes/kubernetes/issues/101567
|
||||
gen-conversions() {
|
||||
clean pkg/internal/apis 'zz_generated.conversion.go'
|
||||
clean pkg/webhook/handlers/testdata/apis 'zz_generated.conversion.go'
|
||||
echo "Generating conversion functions..." >&2
|
||||
|
||||
global_sed_args=('-i')
|
||||
# Possible TODO: Do people build cert-manager on non MacOS / Linux?
|
||||
if [[ $(uname) == 'Darwin' ]]; then
|
||||
global_sed_args+=('')
|
||||
fi
|
||||
|
||||
# meta api
|
||||
"$conversiongen" --go-header-file hack/boilerplate/boilerplate.generatego.txt \
|
||||
--input-dirs github.com/jetstack/cert-manager/pkg/internal/apis/meta/v1 \
|
||||
-O zz_generated.conversion
|
||||
|
||||
# Workaround (see: https://github.com/kubernetes/kubernetes/issues/101567)
|
||||
sed_args=("${global_sed_args[@]}")
|
||||
sed_args+=('s/\+build \!ignore_autogenerated/TEMP_REPLACE_IGNORE_AUTOGENERATED/g' "pkg/internal/apis/meta/v1/zz_generated.conversion.go")
|
||||
sed "${sed_args[@]}"
|
||||
# Workaround (see: https://github.com/kubernetes/kubernetes/issues/101567).
|
||||
remove_go_autogen_tags "pkg/internal/apis/meta/v1/zz_generated.conversion.go"
|
||||
|
||||
# acme and certmanager apis
|
||||
for v in v1alpha2 v1alpha3 v1beta1 v1
|
||||
@@ -277,9 +286,7 @@ gen-conversions() {
|
||||
--extra-dirs github.com/jetstack/cert-manager/pkg/internal/apis/meta/v1
|
||||
|
||||
# Workaround (see: https://github.com/kubernetes/kubernetes/issues/101567)
|
||||
sed_args=("${global_sed_args[@]}")
|
||||
sed_args+=('s/\+build \!ignore_autogenerated/TEMP_REPLACE_IGNORE_AUTOGENERATED/g' "pkg/internal/apis/acme/$v/zz_generated.conversion.go")
|
||||
sed "${sed_args[@]}"
|
||||
remove_go_autogen_tags "pkg/internal/apis/acme/$v/zz_generated.conversion.go"
|
||||
|
||||
"$conversiongen" --go-header-file hack/boilerplate/boilerplate.generatego.txt \
|
||||
--input-dirs "github.com/jetstack/cert-manager/pkg/internal/apis/certmanager/$v" \
|
||||
@@ -287,9 +294,7 @@ gen-conversions() {
|
||||
--extra-dirs "github.com/jetstack/cert-manager/pkg/internal/apis/meta/v1,github.com/jetstack/cert-manager/pkg/internal/apis/acme/$v"
|
||||
|
||||
# Workaround (see: https://github.com/kubernetes/kubernetes/issues/101567)
|
||||
sed_args=("${global_sed_args[@]}")
|
||||
sed_args+=('s/\+build \!ignore_autogenerated/TEMP_REPLACE_IGNORE_AUTOGENERATED/g' "pkg/internal/apis/certmanager/$v/zz_generated.conversion.go")
|
||||
sed "${sed_args[@]}"
|
||||
remove_go_autogen_tags "pkg/internal/apis/certmanager/$v/zz_generated.conversion.go"
|
||||
done
|
||||
|
||||
# test apis
|
||||
@@ -300,9 +305,7 @@ gen-conversions() {
|
||||
# copy into source folder
|
||||
for dir in "${conversion_inputs[@]}"; do
|
||||
# Workaround (see: https://github.com/kubernetes/kubernetes/issues/101567)
|
||||
sed_args=("${global_sed_args[@]}")
|
||||
sed_args+=('s/TEMP_REPLACE_IGNORE_AUTOGENERATED/\+build \!ignore_autogenerated/g' "$dir/zz_generated.conversion.go")
|
||||
sed "${sed_args[@]}"
|
||||
replace_go_autogen_tags "$dir/zz_generated.conversion.go"
|
||||
copyfiles "$dir" "zz_generated.conversion.go"
|
||||
done
|
||||
}
|
||||
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2021 The cert-manager 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.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
REPLACE_NEW=TEMP_REPLACE_IGNORE_AUTOGENERATED_NEW_SYNTAX
|
||||
REPLACE_OLD=TEMP_REPLACE_IGNORE_AUTOGENERATED_OLD_SYNTAX
|
||||
|
||||
remove_go_autogen_tags() {
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: hack::lib::remove_go_autogen_tags <file>"
|
||||
exit 1
|
||||
fi
|
||||
local file="$1"
|
||||
|
||||
local sed_args
|
||||
if [[ $(uname) == 'Darwin' ]]; then
|
||||
sed_args=''
|
||||
elif [[ $(uname) == 'Linux' ]]; then
|
||||
sed_args+=('-i')
|
||||
else
|
||||
echo "Unsupported OS: $(uname), please raise an issue if you would like it to be supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Currently (Go 1.17) both // +build and //go: build lines are added to files.
|
||||
# This code should keep working with a new version of Go that only adds //go: build lines.
|
||||
# https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md
|
||||
sed "${sed_args}" -e "s/\+build \!ignore_autogenerated/$REPLACE_OLD/" "${file}" \
|
||||
-e "s/go\:build\ \!ignore_autogenerated/$REPLACE_NEW/" "${file}"
|
||||
}
|
||||
|
||||
replace_go_autogen_tags() {
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: hack::lib::remove_go_autogen_tags <file>"
|
||||
exit 1
|
||||
fi
|
||||
local file="$1"
|
||||
|
||||
local sed_args
|
||||
if [[ $(uname) == 'Darwin' ]]; then
|
||||
sed_args=''
|
||||
elif [[ $(uname) == 'Linux' ]]; then
|
||||
sed_args='-i'
|
||||
else
|
||||
echo "Unsupported OS: $(uname), please raise an issue if you would like it to be supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Currently (Go 1.17) both // +build and //go: build lines are added to
|
||||
# files.
|
||||
# This code should keep working with a new version of Go that only adds //go: build lines.
|
||||
# See https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md
|
||||
sed "${sed_args}" -e "s/$REPLACE_NEW/go\:build\ \!ignore_autogenerated/" "${file}" \
|
||||
-e "s/$REPLACE_OLD/\+build \!ignore_autogenerated/" "${file}"
|
||||
}
|
||||
Reference in New Issue
Block a user