Skip to content

Commit d13fb45

Browse files
authored
Merge pull request #4002 from Shubhranshu153/fix-none-logger
fix: none log driver creating log uri
2 parents 74a5a6a + 3fbb8be commit d13fb45

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

cmd/nerdctl/container/container_logs_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,18 @@ func TestTailFollowRotateLogs(t *testing.T) {
330330
}
331331
assert.Equal(t, true, len(tailLogs) > linesPerFile, logRun.Stderr())
332332
}
333+
func TestNoneLoggerHasNoLogURI(t *testing.T) {
334+
testCase := nerdtest.Setup()
335+
336+
testCase.Setup = func(data test.Data, helpers test.Helpers) {
337+
helpers.Ensure("run", "--name", data.Identifier(), "--log-driver", "none", testutil.CommonImage, "sh", "-euxc", "echo foo")
338+
}
339+
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
340+
helpers.Anyhow("rm", "-f", data.Identifier())
341+
}
342+
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
343+
return helpers.Command("logs", data.Identifier())
344+
}
345+
testCase.Expected = test.Expects(1, nil, nil)
346+
testCase.Run(t)
347+
}

pkg/cioutil/container_io.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func NewContainerIO(namespace string, logURI string, tty bool, stdin io.Reader,
148148
stderrWriters = append(stderrWriters, stderr)
149149
}
150150

151-
if runtime.GOOS != "windows" {
151+
if runtime.GOOS != "windows" && logURI != "" && logURI != "none" {
152152
// starting logging binary logic is from https://github.com/containerd/containerd/blob/194a1fdd2cde35bc019ef138f30485e27fe0913e/cmd/containerd-shim-runc-v2/process/io.go#L247
153153
stdoutr, stdoutw, err := os.Pipe()
154154
if err != nil {

pkg/cmd/container/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ func writeCIDFile(path, id string) error {
885885
// generateLogConfig creates a LogConfig for the current container store
886886
func generateLogConfig(dataStore string, id string, logDriver string, logOpt []string, ns, address string) (logConfig logging.LogConfig, err error) {
887887
var u *url.URL
888-
if u, err = url.Parse(logDriver); err == nil && u.Scheme != "" {
888+
if u, err = url.Parse(logDriver); err == nil && (u.Scheme != "" || logDriver == "none") {
889889
logConfig.LogURI = logDriver
890890
} else {
891891
logConfig.Driver = logDriver

pkg/taskutil/taskutil.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func NewTask(ctx context.Context, client *containerd.Client, container container
121121
}
122122
}
123123
ioCreator = cioutil.NewContainerIO(namespace, logURI, true, in, os.Stdout, os.Stderr)
124-
} else if flagD && logURI != "" {
124+
} else if flagD && logURI != "" && logURI != "none" {
125125
u, err := url.Parse(logURI)
126126
if err != nil {
127127
return nil, err

0 commit comments

Comments
 (0)