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

libct/cg: write unified resources line by line #4186

Merged
merged 1 commit into from
Jun 9, 2024

Conversation

kolyshkin
Copy link
Contributor

It has been pointed out (in #4182) that some controllers can not accept multiple lines of output at once. In particular, io.max can only set one device at a time.

Practically, the only multi-line resource values we can get come from unified.* -- let's write those line by line.

Add a test case.

Reported-by: Tao Shen shentaoskyking@gmail.com

Closes: #4182

@kolyshkin
Copy link
Contributor Author

@smileusd does this fix your issue?

@smileusd
Copy link

smileusd commented Apr 2, 2024

-> @smileusd does this fix your issue?
yes could you merge this

@kolyshkin kolyshkin added this to the 1.2.0 milestone Apr 22, 2024
// is is written line by line.
func WriteFileByLine(dir, file, data string) error {
i := strings.Index(data, "\n")
if i == -1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this special block.
Others LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lifubang theoretically, yes. Practically, I added it here because I was overly cautious to not break anything.

With this block in place, if the input does not contain newlines, we use the very same function as we used before. In other words, unless there's a newline in data, this commit changes nothing (and it is easy to validate).

It is also easier to read this way (when you debug it, and write a single line, which is the most common scenario, you don't have to read through the code below).

@kolyshkin
Copy link
Contributor Author

@AkihiroSuda @thaJeztah PTAL

It has been pointed out that some controllers can not accept multiple
lines of output at once. In particular, io.max can only set one device
at a time.

Practically, the only multi-line resource values we can get come from
unified.* -- let's write those line by line.

Add a test case.

Reported-by: Tao Shen <shentaoskyking@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@AkihiroSuda AkihiroSuda merged commit 30a7d9b into opencontainers:main Jun 9, 2024
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants