Skip to content

feat: implment persistent logging for containers running in foreground#2683

Merged
AkihiroSuda merged 1 commit into
containerd:mainfrom
vsiravar:vsiravar/update-container-io
Dec 19, 2023
Merged

feat: implment persistent logging for containers running in foreground#2683
AkihiroSuda merged 1 commit into
containerd:mainfrom
vsiravar:vsiravar/update-container-io

Conversation

@vsiravar
Copy link
Copy Markdown
Contributor

@vsiravar vsiravar commented Dec 5, 2023

Fixes: #1657

TODO:
- Refactoring taskutil and container_io to use custom cio.Creator for all flags(-d,-t,-i,-a). This would unblock attach for -d.
[X] Changes for windows.
[X] Adding integration tests

Comment thread go.mod Outdated
github.com/fahedouch/go-logrotate v0.2.0
github.com/fatih/color v1.16.0
github.com/fluent/fluent-logger-golang v1.9.0
github.com/hashicorp/go-multierror v1.1.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.

runtimeOpts = nil
}
} else {
// runtimeStr is a runc binary
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.

Was this line removed by an accident?

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.

Yes, fixed it in the last commit.

Comment thread pkg/ioutil/container_io.go Outdated
func NewContainerIO(namespace string, logURI string, tty bool, stdin io.Reader, stdout, stderr io.Writer) cio.Creator {
return func(id string) (cio.IO, error) {

// is from https://github.com/containerd/containerd/blob/main/cmd/containerd-shim-runc-v2/process/io.go#L247
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.

Please use a permanent link that contains a tag or a commit hash

Comment thread pkg/ioutil/container_io.go Outdated
cmd.ExtraFiles = append(cmd.ExtraFiles, sr, serrr, w)

if err := cmd.Start(); err != nil {
return nil, fmt.Errorf("failed to start binary process: %w", err)
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.

The error string should contain cmd.Args

Comment thread pkg/ioutil/container_io.go Outdated
limitations under the License.
*/

package ioutil
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.

The package name can be confused with the deprecated io/ioutil

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.

Maybe “cioutil”?

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.

Yes makes sense, I missed the io/ioutil package. Changed it to cioutil in last commit.

Comment thread pkg/ioutil/container_io.go Outdated
cmd := process.NewBinaryCmd(uri, id, namespace)
cmd.ExtraFiles = append(cmd.ExtraFiles, sr, serrr, w)

if err := cmd.Start(); err != nil {
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.

The pipes should be cleaned up on an error

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.

Updated with closer to close pipes and stop logger process on errors.

@vsiravar vsiravar changed the title feat: implment container IO for run without -d [Draft] feat: implment container IO for run without -d Dec 5, 2023
@vsiravar vsiravar force-pushed the vsiravar/update-container-io branch 7 times, most recently from 3aa3276 to 76bf40d Compare December 13, 2023 03:33
Signed-off-by: Vishwas Siravara <siravara@amazon.com>
@vsiravar vsiravar force-pushed the vsiravar/update-container-io branch from 3bf4c8d to 990d7ec Compare December 13, 2023 21:42
@vsiravar vsiravar changed the title [Draft] feat: implment container IO for run without -d feat: implment persistent logginf for containers running in foreground Dec 13, 2023
@vsiravar vsiravar marked this pull request as ready for review December 13, 2023 22:29
@vsiravar vsiravar requested a review from AkihiroSuda December 13, 2023 22:29
@vsiravar vsiravar changed the title feat: implment persistent logginf for containers running in foreground feat: implment persistent logging for containers running in foreground Dec 13, 2023
@vsiravar
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing the PR. I have addressed the initial feedback, refactored NewContainerIO and added integration tests to validate logs for containers started in the foreground. @AkihiroSuda PTAL when you get a chance.

@AkihiroSuda AkihiroSuda added this to the v1.7.3 (tentative) milestone Dec 15, 2023
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda
Copy link
Copy Markdown
Member

Comment thread pkg/cioutil/container_io.go
@AkihiroSuda AkihiroSuda mentioned this pull request Jan 2, 2024
@AkihiroSuda AkihiroSuda modified the milestones: v2.0.0, v1.7.3 Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support nerdctl logs for the containers running without -d

2 participants