Skip to content

init simplification#3385

Merged
kolyshkin merged 2 commits intoopencontainers:mainfrom
kolyshkin:init-logger-setup
Aug 9, 2023
Merged

init simplification#3385
kolyshkin merged 2 commits intoopencontainers:mainfrom
kolyshkin:init-logger-setup

Conversation

@kolyshkin
Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin commented Feb 19, 2022

Based on and currently includes #3375. Draft until that one is merged.
Based on and currently includes #3854. Draft until that one is merged.

This moves logging setup out of func init() and into StartInitialization() (where it should belong);

This concludes the spring cleaning started in #3354 (promise). Loosely based on parts of #3316.

@kolyshkin kolyshkin marked this pull request as draft February 19, 2022 00:38
@kolyshkin kolyshkin mentioned this pull request Feb 19, 2022
7 tasks
@kolyshkin
Copy link
Copy Markdown
Contributor Author

Rebased on top of recently rebased #3375

@kolyshkin kolyshkin marked this pull request as ready for review March 27, 2022 01:40
@kolyshkin
Copy link
Copy Markdown
Contributor Author

Rebased; no longer a draft! Also, this concludes what was started as #3316

@kolyshkin
Copy link
Copy Markdown
Contributor Author

@opencontainers/runc-maintainers PTAL

@kolyshkin kolyshkin added this to the 1.2.0 milestone Apr 9, 2022
@kolyshkin kolyshkin force-pushed the init-logger-setup branch from 3c4e1f6 to 8e195de Compare May 11, 2022 21:33
@kolyshkin
Copy link
Copy Markdown
Contributor Author

Rebased; @opencontainers/runc-maintainers PTAL (this concludes a very long and heavy refactoring, the new code is easier to follow and understand).

@kolyshkin kolyshkin force-pushed the init-logger-setup branch from 8e195de to 6b98a38 Compare May 12, 2022 00:24
@kolyshkin kolyshkin added the kind/refactor refactoring label Jun 6, 2022
@kolyshkin
Copy link
Copy Markdown
Contributor Author

@thaJeztah @AkihiroSuda @cyphar PTAL

@kolyshkin kolyshkin force-pushed the init-logger-setup branch 2 times, most recently from 66de915 to 91d4bb0 Compare July 2, 2022 00:06
@thaJeztah
Copy link
Copy Markdown
Member

The first commit still has this paragraph in the commit message, which no longer appears to be the case;

Remove logrus setup and use from TestMain/init, in preparation for the
next commit.

@kolyshkin
Copy link
Copy Markdown
Contributor Author

The first commit still has this paragraph in the commit message, which no longer appears to be the case;

Remove logrus setup and use from TestMain/init, in preparation for the
next commit.

@thaJeztah why do you think so? The first commit removes the logrus setup from TestMain, and
it also removes logrus use from init() in the same file.

@kolyshkin kolyshkin changed the title Init logger setup Init logging cleanups/refactoring Aug 4, 2022
@kolyshkin kolyshkin requested a review from thaJeztah November 3, 2022 00:47
@kolyshkin kolyshkin dismissed stale reviews from ghost via bcd94e3 March 1, 2023 23:50
@kolyshkin kolyshkin dismissed a stale review via bcd94e3 March 9, 2023 22:46
@AkihiroSuda AkihiroSuda dismissed stale reviews from ghost via bcd94e3 March 10, 2023 00:36
@kolyshkin kolyshkin dismissed stale reviews from ghost via bcd94e3 March 16, 2023 17:35
@AkihiroSuda AkihiroSuda dismissed a stale review via bcd94e3 March 18, 2023 10:15
@kolyshkin kolyshkin dismissed a stale review via bcd94e3 March 20, 2023 21:15
@AkihiroSuda AkihiroSuda dismissed stale reviews from ghost via bcd94e3 March 20, 2023 21:15
@kolyshkin
Copy link
Copy Markdown
Contributor Author

Rebased, reworked to make review easier (please review commit-by-commit).

@kolyshkin
Copy link
Copy Markdown
Contributor Author

Let me simplify this even further.

@kolyshkin
Copy link
Copy Markdown
Contributor Author

OK, I wanted to remove logging from the Go part of runc init, but decided to not do it. So, going back to the original plan.

In short, this is a series of small commits that untangle some logic around runc init (mostly the logging part), hopefully making it easier to grok. In the process, I am fixing a very minor and subtle bug of not reporting the unable to convert _LIBCONTAINER_INITPIPE.

if werr := writeSync(pipe, procError); werr != nil {
fmt.Fprintln(os.Stderr, err)
if err := writeSync(pipe, procError); err != nil {
fmt.Fprintln(os.Stderr, retErr)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's interesting that;

  • there's no check for retErr to be nil, so even if there's no retErr, we do a println
  • retErr is only printed if writeSync or utils.WriteJSON fails (is that expected?)
  • The errors from writeSync and utils.WriteJSON are neither returned, nor printed 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh! I guess that's depending on;

	// If init succeeds, it will not return, hence none of the defers will be called.
	return containerInit(it, pipe, consoleSocket, fifofd, logPipeFd, mountFds)

if err := libcontainer.StartInitialization(); err != nil {
// as the error is sent back to the parent there is no need to log
// or write it to stderr because the parent process will handle this
os.Exit(1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like this is the code that was added in the first commit; perhaps it would make sense to move this commit (and the previous one) to the start to the list of commits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So, the first commit ("libct/int: remove logger from init") is a preparation for "init.go: move logger setup to StartInitialization". Logically, they belong together, but since test changes in libct/int are somewhat larger (they also involve a test case), I separate them out for easier review.

Now, the change in the first commit (""libct/int: remove logger from init") brings libcontainer/integration func init() in line with the main runc's func init. Later, we change StartInitialization to return error in some cases, so we remove the os.Exit(1).

All I can do is to rearrange the commits so these two are following each other:

  • libct/int: remove logger from init
  • init.go: move logger setup to StartInitialization

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now, the code added is correct (when it is added), but since "libct/StartInitialization: amend docs, do not error" it needs to be fixed. Thus the two changes. Hope that makes sense.

@kolyshkin
Copy link
Copy Markdown
Contributor Author

It's hard to split changes to separate small commits, as they are all inter-dependent. But I did another try; PTAL.

@kolyshkin
Copy link
Copy Markdown
Contributor Author

kolyshkin commented May 3, 2023

OK, maybe so many commits are way too much to digest. I have separated some prep commits to #3854, and made this one a draft. Once #3854 is merged, there will only be two commits to review here.


// If init succeeds, it will not return, hence none of the defers will be called.
return containerInit(it, pipe, consoleSocket, fifofd, logPipeFd, mountFds)
return containerInit(it, pipe, consoleSocket, fifofd, logFD, mountFds)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, we now use 3 different ways to say "FD", but I'm pretty sure the last one is the best one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I personally prefer Fd. I can write up a PR to unify this.

@kolyshkin
Copy link
Copy Markdown
Contributor Author

@thaJeztah @AkihiroSuda PTAL

@AkihiroSuda
Copy link
Copy Markdown
Member

Needs rebase

Currently, logrus is used from the Go part of runc init, mostly for a
few debug messages (see setns_init_linux.go and standard_init_linux.go),
and a single warning (see rootfs_linux.go).

This means logrus is part of init implementation, and thus, its setup
belongs to StartInitialization().

Move the code there. As a nice side effect, now we don't have to convert
_LIBCONTAINER_LOGPIPE twice.

Note that since this initialization is now also called from libct/int
tests, which do not set _LIBCONTAINER_LOGLEVEL, let's make
_LIBCONTAINER_LOGLEVEL optional.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit does two things:

1. Consolidate StartInitialization calling logic into Init().
2. Fix init error handling logic.

The main issues at hand are:
- the "unable to convert _LIBCONTAINER_INITPIPE" error from
  StartInitialization is never shown;
- errors from WriteSync and WriteJSON are never shown;
- the StartInit calling code is triplicated;
- using panic is questionable.

Generally, our goals are:
 - if there's any error, do our best to show it;
 - but only show each error once;
 - simplify the code, unify init implementations.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
Copy link
Copy Markdown
Contributor Author

Rebased. @lifubang @thaJeztah PTAL

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.

5 participants