Skip to content
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

Controller-gen randomly fails for filenames from mktemp #5271

Closed
tsaarni opened this issue Apr 11, 2023 · 2 comments
Closed

Controller-gen randomly fails for filenames from mktemp #5271

tsaarni opened this issue Apr 11, 2023 · 2 comments
Labels
contribfest Issue to be worked on during ContribFest @ KubeCon EU 2023. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.

Comments

@tsaarni
Copy link
Member

tsaarni commented Apr 11, 2023

What steps did you take and what happened:

Compiling Contour sometimes fails when running make generate. The error can look something like this

Error: unable to parse option "object:headerFile=/var/folders/3f/08k867j16n1c0wvrxzp19b_m0000gn/T/tmp.gbjZOJRW": [invalid digit '8' in octal literal (at <input>:1:28)] 

This error was from MacOS and /var/folders/zz/xyz base path is coming from _CS_DARWIN_USER_TEMP_DIR (link). Depending on users (bad) luck, it might be interpreted as invalid digit like 08 (link) in this example and the generation will fail. When this happens, it is 100% reproducible since user's temp base dir does not change between executions.

Another example is from Linux. mktemp will sometimes generate filename that is interpreted as hexadecimal floating point numbers (link). It will happen very rarely, and the chances are that next run it will not fail. Error might look like following:

Error: unable to parse option "object:headerFile=/tmp/tmp.4pQcvCfLNX": ['p' exponent requires hexadecimal mantissa (at <input>:1:20) exponent has no digits (at <input>:1:20)]

What did you expect to happen:

Compiling should not fail.

Anything else you would like to add:

There is a limitation in controller-tools that causes the filename to be interpreted as digit kubernetes-sigs/controller-tools#734

During Contour build we are running controller-gen for a filename that is created by mktemp - which can generate files that look like invalid digits

readonly HEADER=$(mktemp)
boilerplate > "${HEADER}"
exec go run sigs.k8s.io/controller-tools/cmd/controller-gen \
object \
"object:headerFile=${HEADER}" \
"paths=${PATHS}"

There was previous attempt #5119 fixing similar problem.

It would be great if build did not depend on mktemp for filenames that are sent to controller-tools. The same issue applies both hack/generate-crd-deepcopy.sh and hack/generate-crd-yaml.sh

@tsaarni tsaarni added kind/bug Categorizes issue or PR as related to a bug. contribfest Issue to be worked on during ContribFest @ KubeCon EU 2023. labels Apr 11, 2023
@skriss skriss added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Apr 27, 2023
@christianang
Copy link
Contributor

Took a look at this issue. Looks like controller-gen has fixed it in: kubernetes-sigs/controller-tools#802.

I validated this by doing the following:

echo "// foo" > /tmp/tmp.4pQcvCfLNX

# Doesn't work because this release doesn't contain the commit
go run sigs.k8s.io/controller-tools/cmd/[email protected] object:headerFile=/tmp/tmp.4pQcvCfLNX paths=./apis/...

# Works because it contains the fix
go run sigs.k8s.io/controller-tools/cmd/[email protected] object:headerFile=/tmp/tmp.4pQcvCfLNX paths=./apis/...

Since contour is using the latest controller-gen when you run make generate, I think this issue can be closed.

@sunjayBhatia
Copy link
Member

Nice! thanks for validating that, closing accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribfest Issue to be worked on during ContribFest @ KubeCon EU 2023. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

4 participants