-
Notifications
You must be signed in to change notification settings - Fork 38.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Code-generator] --extra-peer-dirs
flag is not supported by new kube-codegen.sh
script
#120803
Comments
/cc @thockin |
/sig api-machinery |
/assign @apelisse |
/assign @thockin |
Can you explain why you need this flag? What I found in k/k was that we don't actually need it at all. |
You know what, my memory was faulty. We do use it (until I fix that, which is in a development branch, not merged). But we don't use it in any of the "submodule" configs. |
A lot of the "magic" behind the conversion logic is very brittle. Can you help me understand where / how this impacts you? |
I whipped up a quick patch but have not tested much: diff --git a/staging/src/k8s.io/code-generator/kube_codegen.sh b/staging/src/k8s.io/code-generator/kube_codegen.sh
index 3342b9dcaeb..132dea936ab 100755
--- a/staging/src/k8s.io/code-generator/kube_codegen.sh
+++ b/staging/src/k8s.io/code-generator/kube_codegen.sh
@@ -50,11 +50,16 @@ function kube::codegen::internal::git_grep() {
# --boilerplate <string = path_to_kube_codegen_boilerplate>
# An optional override for the header file to insert into generated files.
#
+# --extra-peer-dir <string>
+# An optional list (this flag may be specified multiple times) of "extra"
+# directories to consider during conversion generation.
+#
function kube::codegen::gen_helpers() {
local in_pkg_root=""
local out_base="" # gengo needs the output dir must be $out_base/$out_pkg_root
local boilerplate="${KUBE_CODEGEN_ROOT}/hack/boilerplate.go.txt"
local v="${KUBE_VERBOSE:-0}"
+ local extra_peers=()
while [ "$#" -gt 0 ]; do
case "$1" in
@@ -70,6 +75,10 @@ function kube::codegen::gen_helpers() {
boilerplate="$2"
shift 2
;;
+ "--extra-peer-dir")
+ extra_peers+=("$2")
+ shift 2
+ ;;
*)
echo "unknown argument: $1" >&2
return 1
@@ -196,16 +205,21 @@ function kube::codegen::gen_helpers() {
":(glob)${root}"/'**/zz_generated.conversion.go' \
| xargs -0 rm -f
- local inputs=()
+ local input_args=()
for arg in "${input_pkgs[@]}"; do
- inputs+=("--input-dirs" "$arg")
+ input_args+=("--input-dirs" "$arg")
+ done
+ local extra_peer_args=()
+ for arg in "${extra_peers[@]}"; do
+ extra_peer_args+=("--extra-peer-dirs" "$arg")
done
"${gobin}/conversion-gen" \
-v "${v}" \
-O zz_generated.conversion \
--go-header-file "${boilerplate}" \
--output-base "${out_base}" \
- "${inputs[@]}"
+ "${extra_peer_args[@]}" \
+ "${input_args[@]}"
fi
}
|
We are using the flag several places in our On removal of the flag, the autoConvert functions in.
Althoug I can see the function
Hence, I think there is a need for the |
I see. The component-base is something I didn't account for. If you apply the above patch, does the new |
Above patch throws an error Instead I followed this approach : diff --git a/staging/src/k8s.io/code-generator/kube_codegen.sh b/staging/src/k8s.io/code-generator/kube_codegen.sh
index 3342b9dcaeb..c7d20da0724 100755
--- a/staging/src/k8s.io/code-generator/kube_codegen.sh
+++ b/staging/src/k8s.io/code-generator/kube_codegen.sh
@@ -53,6 +53,7 @@ function kube::codegen::internal::git_grep() {
function kube::codegen::gen_helpers() {
local in_pkg_root=""
local out_base="" # gengo needs the output dir must be $out_base/$out_pkg_root
+ local extra_peers=""
local boilerplate="${KUBE_CODEGEN_ROOT}/hack/boilerplate.go.txt"
local v="${KUBE_VERBOSE:-0}"
@@ -70,6 +71,10 @@ function kube::codegen::gen_helpers() {
boilerplate="$2"
shift 2
;;
+ "--extra-peer-dirs")
+ extra_peers+="$2"
+ shift 2
+ ;;
*)
echo "unknown argument: $1" >&2
return 1
@@ -205,6 +210,7 @@ function kube::codegen::gen_helpers() {
-O zz_generated.conversion \
--go-header-file "${boilerplate}" \
--output-base "${out_base}" \
+ --extra-peer-dirs "${extra_peers}" \
"${inputs[@]}"
fi
}
|
I'd rather not accumulate into a string - can you tell me what error it throws? Note, mine wants Also - is the argument here a dir (e.g. /home/me/src/foo/bar) or a pkg (e.g. k8s.io/foo/bar) ? I think it's actually a pkg, right? |
You implementation throws error for the cases when we don't specify the
For such cases I am getting following error
|
It seems to be an old-bash problem. Try this one? diff --git a/staging/src/k8s.io/code-generator/kube_codegen.sh b/staging/src/k8s.io/code-generator/kube_codegen.sh
index 3342b9dcaeb..6ded2048368 100755
--- a/staging/src/k8s.io/code-generator/kube_codegen.sh
+++ b/staging/src/k8s.io/code-generator/kube_codegen.sh
@@ -50,11 +50,16 @@ function kube::codegen::internal::git_grep() {
# --boilerplate <string = path_to_kube_codegen_boilerplate>
# An optional override for the header file to insert into generated files.
#
+# --extra-peer-dir <string>
+# An optional list (this flag may be specified multiple times) of "extra"
+# directories to consider during conversion generation.
+#
function kube::codegen::gen_helpers() {
local in_pkg_root=""
local out_base="" # gengo needs the output dir must be $out_base/$out_pkg_root
local boilerplate="${KUBE_CODEGEN_ROOT}/hack/boilerplate.go.txt"
local v="${KUBE_VERBOSE:-0}"
+ local extra_peers=()
while [ "$#" -gt 0 ]; do
case "$1" in
@@ -70,6 +75,10 @@ function kube::codegen::gen_helpers() {
boilerplate="$2"
shift 2
;;
+ "--extra-peer-dir")
+ extra_peers+=("$2")
+ shift 2
+ ;;
*)
echo "unknown argument: $1" >&2
return 1
@@ -128,16 +137,16 @@ function kube::codegen::gen_helpers() {
":(glob)${root}"/'**/zz_generated.deepcopy.go' \
| xargs -0 rm -f
- local inputs=()
+ local input_args=()
for arg in "${input_pkgs[@]}"; do
- inputs+=("--input-dirs" "$arg")
+ input_args+=("--input-dirs" "$arg")
done
"${gobin}/deepcopy-gen" \
-v "${v}" \
-O zz_generated.deepcopy \
--go-header-file "${boilerplate}" \
--output-base "${out_base}" \
- "${inputs[@]}"
+ "${input_args[@]}"
fi
# Defaults
@@ -162,16 +171,16 @@ function kube::codegen::gen_helpers() {
":(glob)${root}"/'**/zz_generated.defaults.go' \
| xargs -0 rm -f
- local inputs=()
+ local input_args=()
for arg in "${input_pkgs[@]}"; do
- inputs+=("--input-dirs" "$arg")
+ input_args+=("--input-dirs" "$arg")
done
"${gobin}/defaulter-gen" \
-v "${v}" \
-O zz_generated.defaults \
--go-header-file "${boilerplate}" \
--output-base "${out_base}" \
- "${inputs[@]}"
+ "${input_args[@]}"
fi
# Conversions
@@ -196,16 +205,21 @@ function kube::codegen::gen_helpers() {
":(glob)${root}"/'**/zz_generated.conversion.go' \
| xargs -0 rm -f
- local inputs=()
+ local input_args=()
for arg in "${input_pkgs[@]}"; do
- inputs+=("--input-dirs" "$arg")
+ input_args+=("--input-dirs" "$arg")
+ done
+ local extra_peer_args=()
+ for arg in "${extra_peers[@]:+"${extra_peers[@]}"}"; do
+ extra_peer_args+=("--extra-peer-dirs" "$arg")
done
"${gobin}/conversion-gen" \
-v "${v}" \
-O zz_generated.conversion \
--go-header-file "${boilerplate}" \
--output-base "${out_base}" \
- "${inputs[@]}"
+ "${extra_peer_args[@]:+"${extra_peer_args[@]}"}" \
+ "${input_args[@]}"
fi
}
|
Yes this is working fine. |
OK. I'll prep a PR soon. |
Thank you |
What would you like to be added?
Earlier it was possible to pass
--extra-peer-dirs
flag toconversion-gen
while callinggenerate-internal-groups.sh
script.Now with the new
kube-codegen.sh
script,conversion-gen
is called underkube::codegen::gen_helpers
which doesnot support any other flags apart from--input-pkg-root
,--output-base
and--boilerplate
.As it can be seen here there is no option to pass flag to conversion-gen
https://github.com/kubernetes/code-generator/blob/e4611069dfb4b0c04c7751afae1b9fef64828964/kube_codegen.sh#L203-L208
Earlier in the
generate-internal-groups.sh
script, it was considering all the inputs passedWhy is this needed?
--extra-peer-dirs
flag is supported byconversion-gen
under the hood, but thekube::codegen::gen_helpers
function inkube-codegen.sh
script is not allowing the flag.The text was updated successfully, but these errors were encountered: