Skip to content

Commit 2ac80c9

Browse files
committed
fix template
1 parent 0499b02 commit 2ac80c9

File tree

8 files changed

+32
-149
lines changed

8 files changed

+32
-149
lines changed

apis/v1alpha2/nginxproxy_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ type LogFormat struct {
369369
Format *string `json:"format,omitempty"`
370370
}
371371

372-
// AccessLog defines the configuration for an NGINX access log. For now only path dev/stdout is used.
372+
// AccessLog defines the configuration for an NGINX access log. For now only path /dev/stdout is used.
373373
type AccessLog struct {
374374
Path *string `json:"path,omitempty"`
375375
Format *string `json:"format,omitempty"`

internal/controller/nginx/config/base_http_config_template.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@ server {
4848
}
4949
}
5050
51-
{{- /* Define custom log format */ -}}
52-
{{- if .LogFormat }}
53-
{{- if .LogFormat.Name }}
51+
{{- /* Define custom log format */ -}}
52+
{{- if .LogFormat }}
53+
{{- if .LogFormat.Name }}
5454
log_format {{ .LogFormat.Name }} '{{ .LogFormat.Format }}';
55-
{{- end }}
5655
{{- end }}
56+
{{- end }}
5757
58-
{{- /* Access log directives for AccessLog. If path is "off" we disable logging. If Format set, use dev/stdout with that format. Otherwise use the given path. */ -}}
59-
{{- if .AccessLog }}
60-
{{- if eq .AccessLog.Path "off" }}
61-
access_log off;
62-
{{- else }}
63-
{{- if .AccessLog.Format }}
64-
access_log dev/stdout {{ .AccessLog.Format }};
65-
{{- end }}
66-
{{- end }}
58+
{{- /* Access log directives for AccessLog. If path is "off" we disable logging. If Format set, use /dev/stdout with that format. Otherwise use the given path. */ -}}
59+
{{- if .AccessLog }}
60+
{{- if eq .AccessLog.Path "off" }}
61+
access_log off;
62+
{{- else }}
63+
{{- if .AccessLog.Format }}
64+
access_log /dev/stdout {{ .AccessLog.Format }};
65+
{{- end }}
6766
{{- end }}
67+
{{- end }}
6868
6969
{{ range $i := .Includes -}}
7070
include {{ $i.Name }};

internal/controller/nginx/config/base_http_config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestLoggingSettingsTemplate(t *testing.T) {
2929
accessLog: &dataplane.AccessLog{Path: "/path/to/log.gz", Format: "custom_format"},
3030
expectedOutputs: []string{
3131
`log_format custom_format '$remote_addr - [$time_local] "$request" $status $body_bytes_sent';`,
32-
`access_log dev/stdout custom_format;`,
32+
`access_log /dev/stdout custom_format;`,
3333
},
3434
},
3535
{
@@ -41,7 +41,7 @@ func TestLoggingSettingsTemplate(t *testing.T) {
4141
accessLog: &dataplane.AccessLog{Path: "", Format: ""},
4242
unexpectedOutputs: []string{
4343
`log_format custom_format`,
44-
`access_log dev/stdout`,
44+
`access_log /dev/stdout`,
4545
},
4646
},
4747
{

internal/controller/provisioner/objects_test.go

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,117 +1830,3 @@ func TestBuildNginxResourceObjects_InferenceExtension(t *testing.T) {
18301830
g.Expect(containers[1].Name).To(Equal("endpoint-picker-shim"))
18311831
g.Expect(containers[1].Command).To(Equal(expectedCommands))
18321832
}
1833-
1834-
func TestBuildNginxResourceObjects_NginxProxyConfigWithAccesslog(t *testing.T) {
1835-
t.Parallel()
1836-
g := NewWithT(t)
1837-
1838-
agentTLSSecret := &corev1.Secret{
1839-
ObjectMeta: metav1.ObjectMeta{
1840-
Name: agentTLSTestSecretName,
1841-
Namespace: ngfNamespace,
1842-
},
1843-
Data: map[string][]byte{"tls.crt": []byte("tls")},
1844-
}
1845-
fakeClient := fake.NewFakeClient(agentTLSSecret)
1846-
1847-
provisioner := &NginxProvisioner{
1848-
cfg: Config{
1849-
GatewayPodConfig: &config.GatewayPodConfig{
1850-
Namespace: ngfNamespace,
1851-
Version: "1.0.0",
1852-
},
1853-
AgentTLSSecretName: agentTLSTestSecretName,
1854-
},
1855-
baseLabelSelector: metav1.LabelSelector{
1856-
MatchLabels: map[string]string{
1857-
"app": "nginx",
1858-
},
1859-
},
1860-
k8sClient: fakeClient,
1861-
}
1862-
1863-
gateway := &gatewayv1.Gateway{
1864-
ObjectMeta: metav1.ObjectMeta{
1865-
Name: "gw",
1866-
Namespace: "default",
1867-
},
1868-
Spec: gatewayv1.GatewaySpec{
1869-
Listeners: []gatewayv1.Listener{
1870-
{Name: "port-8443", Port: 8443, Protocol: "tcp"},
1871-
},
1872-
},
1873-
}
1874-
1875-
resourceName := "gw-nginx"
1876-
nProxyCfg := &graph.EffectiveNginxProxy{
1877-
IPFamily: helpers.GetPointer(ngfAPIv1alpha2.IPv4),
1878-
Logging: &ngfAPIv1alpha2.NginxLogging{
1879-
ErrorLevel: helpers.GetPointer(ngfAPIv1alpha2.NginxLogLevelDebug),
1880-
AgentLevel: helpers.GetPointer(ngfAPIv1alpha2.AgentLogLevelDebug),
1881-
LogFormat: &ngfAPIv1alpha2.LogFormat{
1882-
Name: helpers.GetPointer("custom_format"),
1883-
Format: helpers.GetPointer("$remote_addr - [$time_local] \"$request\" $status $body_bytes_sent"),
1884-
},
1885-
AccessLog: &ngfAPIv1alpha2.AccessLog{
1886-
Path: helpers.GetPointer("/var/log/nginx/access.log"),
1887-
Format: helpers.GetPointer("custom_format"),
1888-
},
1889-
},
1890-
Metrics: &ngfAPIv1alpha2.Metrics{
1891-
Port: helpers.GetPointer[int32](8080),
1892-
},
1893-
Kubernetes: &ngfAPIv1alpha2.KubernetesSpec{
1894-
Service: &ngfAPIv1alpha2.ServiceSpec{
1895-
ServiceType: helpers.GetPointer(ngfAPIv1alpha2.ServiceTypeNodePort),
1896-
ExternalTrafficPolicy: helpers.GetPointer(ngfAPIv1alpha2.ExternalTrafficPolicyCluster),
1897-
LoadBalancerIP: helpers.GetPointer("1.2.3.4"),
1898-
LoadBalancerClass: helpers.GetPointer("myLoadBalancerClass"),
1899-
LoadBalancerSourceRanges: []string{"5.6.7.8"},
1900-
},
1901-
Deployment: &ngfAPIv1alpha2.DeploymentSpec{
1902-
Replicas: helpers.GetPointer[int32](3),
1903-
Autoscaling: &ngfAPIv1alpha2.AutoscalingSpec{
1904-
Enable: true,
1905-
MinReplicas: helpers.GetPointer[int32](1),
1906-
MaxReplicas: 5,
1907-
TargetMemoryUtilizationPercentage: helpers.GetPointer[int32](60),
1908-
},
1909-
Pod: ngfAPIv1alpha2.PodSpec{
1910-
TerminationGracePeriodSeconds: helpers.GetPointer[int64](25),
1911-
},
1912-
Container: ngfAPIv1alpha2.ContainerSpec{
1913-
Image: &ngfAPIv1alpha2.Image{
1914-
Repository: helpers.GetPointer("nginx-repo"),
1915-
Tag: helpers.GetPointer("1.1.1"),
1916-
PullPolicy: helpers.GetPointer(ngfAPIv1alpha2.PullAlways),
1917-
},
1918-
Resources: &corev1.ResourceRequirements{
1919-
Limits: corev1.ResourceList{
1920-
corev1.ResourceCPU: resource.Quantity{Format: "100m"},
1921-
},
1922-
},
1923-
ReadinessProbe: &ngfAPIv1alpha2.ReadinessProbeSpec{
1924-
Port: helpers.GetPointer[int32](9091),
1925-
InitialDelaySeconds: helpers.GetPointer[int32](5),
1926-
},
1927-
HostPorts: []ngfAPIv1alpha2.HostPort{{ContainerPort: int32(8443), Port: int32(8443)}},
1928-
},
1929-
},
1930-
},
1931-
}
1932-
1933-
objects, err := provisioner.buildNginxResourceObjects(resourceName, gateway, nProxyCfg)
1934-
g.Expect(err).ToNot(HaveOccurred())
1935-
1936-
g.Expect(objects).To(HaveLen(7))
1937-
1938-
cmObj := objects[1]
1939-
cm, ok := cmObj.(*corev1.ConfigMap)
1940-
g.Expect(ok).To(BeTrue())
1941-
g.Expect(cm.Data).To(HaveKey("main.conf"))
1942-
g.Expect(cm.Data["main.conf"]).To(ContainSubstring("debug"))
1943-
g.Expect(cm.Data["main.conf"]).
1944-
To(ContainSubstring("log_format custom_format '$remote_addr - [$time_local] \"$request\" $status $body_bytes_sent';"))
1945-
g.Expect(cm.Data["main.conf"]).To(ContainSubstring("access_log /var/log/nginx/access.log custom_format;"))
1946-
}

internal/controller/provisioner/templates.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ var (
1010
)
1111

1212
const mainTemplateText = `
13-
error_log stderr {{ .ErrorLevel }};
14-
{{- if .LogFormat }}
15-
log_format {{ .LogFormat.Name }} '{{ .LogFormat.Format }}';
16-
{{- end }}
17-
{{- if .AccessLog }}
18-
access_log {{ .AccessLog.Path }} {{ .AccessLog.Format }};
19-
{{- end }}`
13+
error_log stderr {{ .ErrorLevel }};`
2014

2115
const eventsTemplateText = `
2216
worker_connections {{ .WorkerConnections }};`

internal/controller/state/dataplane/configuration.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,15 +1261,15 @@ func buildLogFormat(srcLogSettings *ngfAPIv1alpha2.NginxLogging) *LogFormat {
12611261

12621262
func buildAccessLog(srcLogSettings *ngfAPIv1alpha2.NginxLogging) *AccessLog {
12631263
var accessLog AccessLog
1264-
// Current API exposes a singular *string AccessLog path (no format yet) – only dev/stdout or "off".
1264+
// Current API exposes a singular *string AccessLog path (no format yet) – only /dev/stdout or "off".
12651265
if srcLogSettings.AccessLog != nil &&
12661266
srcLogSettings.AccessLog.Path != nil &&
12671267
*srcLogSettings.AccessLog.Path != "" {
12681268
if strings.ToLower(*srcLogSettings.AccessLog.Path) == "off" {
12691269
accessLog = AccessLog{Path: "off"}
12701270
} else {
1271-
// only "dev/stdout" is supported for now
1272-
defaultPath := "dev/stdout"
1271+
// only "/dev/stdout" is supported for now
1272+
defaultPath := "/dev/stdout"
12731273
if srcLogSettings.AccessLog.Format != nil &&
12741274
*srcLogSettings.AccessLog.Format != "" {
12751275
accessLog = AccessLog{

internal/controller/state/dataplane/configuration_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4897,7 +4897,7 @@ func TestBuildLogging(t *testing.T) {
48974897
'"$http_referer" "$http_user_agent" '`),
48984898
},
48994899
AccessLog: &ngfAPIv1alpha2.AccessLog{
4900-
Path: helpers.GetPointer("dev/stdout"),
4900+
Path: helpers.GetPointer("/dev/stdout"),
49014901
Format: helpers.GetPointer("custom_format"),
49024902
},
49034903
},
@@ -4912,7 +4912,7 @@ func TestBuildLogging(t *testing.T) {
49124912
'"$http_referer" "$http_user_agent" '`,
49134913
},
49144914
AccessLog: &AccessLog{
4915-
Path: "dev/stdout",
4915+
Path: "/dev/stdout",
49164916
Format: "custom_format",
49174917
},
49184918
},
@@ -4929,7 +4929,7 @@ func TestBuildLogging(t *testing.T) {
49294929
'"$http_referer" "$http_user_agent" '`),
49304930
},
49314931
AccessLog: &ngfAPIv1alpha2.AccessLog{
4932-
Path: helpers.GetPointer("dev/stdout"),
4932+
Path: helpers.GetPointer("/dev/stdout"),
49334933
Format: helpers.GetPointer("custom_format"),
49344934
},
49354935
},
@@ -4960,7 +4960,7 @@ func TestBuildLogging(t *testing.T) {
49604960
},
49614961
},
49624962
{
4963-
msg: "AccessLog path replaced with dev/stdout",
4963+
msg: "AccessLog path replaced with /dev/stdout",
49644964
gw: &graph.Gateway{
49654965
EffectiveNginxProxy: &graph.EffectiveNginxProxy{
49664966
Logging: &ngfAPIv1alpha2.NginxLogging{
@@ -4987,7 +4987,7 @@ func TestBuildLogging(t *testing.T) {
49874987
'"$http_referer" "$http_user_agent" '`,
49884988
},
49894989
AccessLog: &AccessLog{
4990-
Path: "dev/stdout",
4990+
Path: "/dev/stdout",
49914991
Format: "custom_format",
49924992
},
49934993
},

internal/controller/state/dataplane/types.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,11 @@ type Ratio struct {
474474

475475
// Logging defines logging related settings for NGINX.
476476
type Logging struct {
477-
AccessLog *AccessLog
478-
LogFormat *LogFormat
477+
// AccessLog defines the configuration for the NGINX access log. For now only path /dev/stdout is used.
478+
AccessLog *AccessLog
479+
// LogFormat represents a custom log format.
480+
LogFormat *LogFormat
481+
// ErrorLevel defines the error log level.
479482
ErrorLevel string
480483
}
481484

@@ -506,9 +509,9 @@ type LogFormat struct {
506509
Format string
507510
}
508511

509-
// AccessLog defines the configuration for an NGINX access log. For now only path dev/stdout is used.
512+
// AccessLog defines the configuration for an NGINX access log. For now only path /dev/stdout is used.
510513
type AccessLog struct {
511-
// Path is the path of the access log. Currently supported only dev/stdout, or "off" to disable logging.
514+
// Path is the path of the access log. Currently supported only /dev/stdout, or "off" to disable logging.
512515
Path string
513516
// Format is the log_format name
514517
Format string

0 commit comments

Comments
 (0)