This commit is contained in:
Giovanni Barbaro 2025-02-17 09:50:31 -08:00 committed by GitHub
commit 5f44ba9fcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View file

@ -32,7 +32,7 @@ var logAnnotations = parser.Annotation{
Group: "log", Group: "log",
Annotations: parser.AnnotationFields{ Annotations: parser.AnnotationFields{
enableAccessLogAnnotation: { enableAccessLogAnnotation: {
Validator: parser.ValidateBool, Validator: parser.ValidateOptions([]string{"true", "false", "default"}, true, true),
Scope: parser.AnnotationScopeLocation, Scope: parser.AnnotationScopeLocation,
Risk: parser.AnnotationRiskLow, Risk: parser.AnnotationRiskLow,
Documentation: `This configuration setting allows you to control if this location should generate an access_log`, Documentation: `This configuration setting allows you to control if this location should generate an access_log`,
@ -53,8 +53,8 @@ type log struct {
// Config contains the configuration to be used in the Ingress // Config contains the configuration to be used in the Ingress
type Config struct { type Config struct {
Access bool `json:"accessLog"` Access string `json:"accessLog"`
Rewrite bool `json:"rewriteLog"` Rewrite bool `json:"rewriteLog"`
} }
// Equal tests for equality between two Config types // Equal tests for equality between two Config types
@ -84,9 +84,9 @@ func (l log) Parse(ing *networking.Ingress) (interface{}, error) {
var err error var err error
config := &Config{} config := &Config{}
config.Access, err = parser.GetBoolAnnotation(enableAccessLogAnnotation, ing, l.annotationConfig.Annotations) config.Access, err = parser.GetStringAnnotation(enableAccessLogAnnotation, ing, l.annotationConfig.Annotations)
if err != nil { if err != nil {
config.Access = true config.Access = "default"
} }
config.Rewrite, err = parser.GetBoolAnnotation(enableRewriteLogAnnotation, ing, l.annotationConfig.Annotations) config.Rewrite, err = parser.GetBoolAnnotation(enableRewriteLogAnnotation, ing, l.annotationConfig.Annotations)

View file

@ -1132,7 +1132,9 @@ stream {
log_by_lua_file /etc/nginx/lua/nginx/ngx_conf_log_block.lua; log_by_lua_file /etc/nginx/lua/nginx/ngx_conf_log_block.lua;
{{ if not $location.Logs.Access }} {{ if $location.Logs.Access == "true" }}
access_log on;
{{ else if $location.Logs.Access == "false" }}
access_log off; access_log off;
{{ end }} {{ end }}