Merge pull request #43314 from deads2k/server-08-audit
Automatic merge from submit-queue (batch tested with PRs 43144, 42671, 43226, 43314, 43361) use - to indicate audit log goes to system out When debugging API servers, particularly aggregated API servers, it's really useful to see the audit trail in their normal pod logs. This makes `--audit-log-path=-` direct audit information to stdout. @kubernetes/sig-api-machinery-misc
This commit is contained in:
		| @@ -17,6 +17,8 @@ limitations under the License. | |||||||
| package options | package options | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
|  | 	"os" | ||||||
|  |  | ||||||
| 	"github.com/spf13/pflag" | 	"github.com/spf13/pflag" | ||||||
| 	"gopkg.in/natefinch/lumberjack.v2" | 	"gopkg.in/natefinch/lumberjack.v2" | ||||||
|  |  | ||||||
| @@ -36,7 +38,7 @@ func NewAuditLogOptions() *AuditLogOptions { | |||||||
|  |  | ||||||
| func (o *AuditLogOptions) AddFlags(fs *pflag.FlagSet) { | func (o *AuditLogOptions) AddFlags(fs *pflag.FlagSet) { | ||||||
| 	fs.StringVar(&o.Path, "audit-log-path", o.Path, | 	fs.StringVar(&o.Path, "audit-log-path", o.Path, | ||||||
| 		"If set, all requests coming to the apiserver will be logged to this file.") | 		"If set, all requests coming to the apiserver will be logged to this file.  '-' means standard out.") | ||||||
| 	fs.IntVar(&o.MaxAge, "audit-log-maxage", o.MaxBackups, | 	fs.IntVar(&o.MaxAge, "audit-log-maxage", o.MaxBackups, | ||||||
| 		"The maximum number of days to retain old audit log files based on the timestamp encoded in their filename.") | 		"The maximum number of days to retain old audit log files based on the timestamp encoded in their filename.") | ||||||
| 	fs.IntVar(&o.MaxBackups, "audit-log-maxbackup", o.MaxBackups, | 	fs.IntVar(&o.MaxBackups, "audit-log-maxbackup", o.MaxBackups, | ||||||
| @@ -50,6 +52,11 @@ func (o *AuditLogOptions) ApplyTo(c *server.Config) error { | |||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	if o.Path == "-" { | ||||||
|  | 		c.AuditWriter = os.Stdout | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	c.AuditWriter = &lumberjack.Logger{ | 	c.AuditWriter = &lumberjack.Logger{ | ||||||
| 		Filename:   o.Path, | 		Filename:   o.Path, | ||||||
| 		MaxAge:     o.MaxAge, | 		MaxAge:     o.MaxAge, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Submit Queue
					Kubernetes Submit Queue