Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows allows-access-logs to set 'access_log on' #12081

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/ingress/annotations/log/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var logAnnotations = parser.Annotation{
Group: "log",
Annotations: parser.AnnotationFields{
enableAccessLogAnnotation: {
Validator: parser.ValidateBool,
Validator: parser.ValidateOptions([]string{"true", "false", "default"}, true, true),
Scope: parser.AnnotationScopeLocation,
Risk: parser.AnnotationRiskLow,
Documentation: `This configuration setting allows you to control if this location should generate an access_log`,
Expand All @@ -53,8 +53,8 @@ type log struct {

// Config contains the configuration to be used in the Ingress
type Config struct {
Access bool `json:"accessLog"`
Rewrite bool `json:"rewriteLog"`
Access string `json:"accessLog"`
Rewrite bool `json:"rewriteLog"`
}

// Equal tests for equality between two Config types
Expand Down Expand Up @@ -84,9 +84,9 @@ func (l log) Parse(ing *networking.Ingress) (interface{}, error) {
var err error
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 {
config.Access = true
config.Access = "default"
}

config.Rewrite, err = parser.GetBoolAnnotation(enableRewriteLogAnnotation, ing, l.annotationConfig.Annotations)
Expand Down
4 changes: 3 additions & 1 deletion rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,9 @@ stream {

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;
{{ end }}

Expand Down
Loading