mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #110813 from vpnachev/apiserver/create-dir-for-audit-log-path
Ensure the directory for the file in flag `--audit-log-path` exists
This commit is contained in:
commit
ff20035ef8
@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -525,6 +526,9 @@ func (o *AuditLogOptions) getWriter() (io.Writer, error) {
|
||||
}
|
||||
|
||||
func (o *AuditLogOptions) ensureLogFile() error {
|
||||
if err := os.MkdirAll(filepath.Dir(o.Path), 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
mode := os.FileMode(0600)
|
||||
f, err := os.OpenFile(o.Path, os.O_CREATE|os.O_APPEND|os.O_RDWR, mode)
|
||||
if err != nil {
|
||||
|
@ -69,6 +69,15 @@ func TestAuditValidOptions(t *testing.T) {
|
||||
return o
|
||||
},
|
||||
expected: "ignoreErrors<log>",
|
||||
}, {
|
||||
name: "create audit log path dir",
|
||||
options: func() *AuditOptions {
|
||||
o := NewAuditOptions()
|
||||
o.LogOptions.Path = filepath.Join(tmpDir, "non-existing-dir1", "non-existing-dir2", "audit")
|
||||
o.PolicyFile = policy
|
||||
return o
|
||||
},
|
||||
expected: "ignoreErrors<log>",
|
||||
}, {
|
||||
name: "default log no policy",
|
||||
options: func() *AuditOptions {
|
||||
|
Loading…
Reference in New Issue
Block a user