Skip to content

Commit a501482

Browse files
New logging configuration (#113)
* Do not add logtostderr if omitted * Add log configuration * Bump chart version * Add log config as secret, use log-config-file * Remove templated yaml from repo, add values examples * Fix template extension * Add gitignore for goland, tests for new configuration api: enable, override, disable + use --logtostderr * Enable Parallel() tests back
1 parent de5eb20 commit a501482

File tree

7 files changed

+146
-3
lines changed

7 files changed

+146
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

cockroachdb/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
name: cockroachdb
33
home: https://www.cockroachlabs.com
4-
version: 6.1.1
4+
version: 6.1.2
55
appVersion: 21.1.7
66
description: CockroachDB is a scalable, survivable, strongly-consistent SQL database.
77
icon: https://raw.githubusercontent.com/cockroachdb/cockroach/master/docs/media/cockroach_db.png

cockroachdb/templated.yaml

-22.1 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- if .Values.conf.log.enabled }}
2+
kind: Secret
3+
apiVersion: v1
4+
metadata:
5+
name: {{ template "cockroachdb.fullname" . }}-log-config
6+
namespace: {{ .Release.Namespace | quote }}
7+
labels:
8+
helm.sh/chart: {{ template "cockroachdb.chart" . }}
9+
app.kubernetes.io/name: {{ template "cockroachdb.name" . }}
10+
app.kubernetes.io/instance: {{ .Release.Name | quote }}
11+
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
12+
{{- with .Values.labels }}
13+
{{- toYaml . | nindent 4 }}
14+
{{- end }}
15+
type: Opaque
16+
stringData:
17+
log-config.yaml: |
18+
{{- toYaml .Values.conf.log.config | nindent 4 }}
19+
{{- end }}

cockroachdb/templates/statefulset.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ spec:
184184
{{- end }}
185185
{{- end }}
186186
--advertise-host=$(hostname).${STATEFULSET_FQDN}
187-
--logtostderr={{ .Values.conf.logtostderr }}
188187
{{- if .Values.tls.enabled }}
189188
--certs-dir=/cockroach/cockroach-certs/
190189
{{- else }}
@@ -212,6 +211,11 @@ spec:
212211
{{- if .Values.conf.store.enabled }}
213212
--store={{ template "cockroachdb.conf.store" . }}
214213
{{- end }}
214+
{{- if .Values.conf.log.enabled }}
215+
--log-config-file=/cockroach/log-config/log-config.yaml
216+
{{- else }}
217+
--logtostderr={{ .Values.conf.logtostderr }}
218+
{{- end }}
215219
{{- range .Values.statefulset.args }}
216220
{{ . }}
217221
{{- end }}
@@ -248,6 +252,11 @@ spec:
248252
mountPath: {{ printf "/etc/cockroach/secrets/%s" . | quote }}
249253
readOnly: true
250254
{{- end }}
255+
{{- if .Values.conf.log.enabled }}
256+
- name: log-config
257+
mountPath: /cockroach/log-config
258+
readOnly: true
259+
{{- end }}
251260
livenessProbe:
252261
{{- if .Values.statefulset.customLivenessProbe }}
253262
{{ toYaml .Values.statefulset.customLivenessProbe | nindent 12 }}
@@ -325,6 +334,11 @@ spec:
325334
secret:
326335
secretName: {{ . | quote }}
327336
{{- end }}
337+
{{- if .Values.conf.log.enabled }}
338+
- name: log-config
339+
secret:
340+
secretName: {{ template "cockroachdb.fullname" . }}-log-config
341+
{{- end }}
328342
{{- if .Values.storage.persistentVolume.enabled }}
329343
volumeClaimTemplates:
330344
- metadata:

cockroachdb/values.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@ conf:
5959
# new Pods.
6060
join: []
6161

62-
# Logs at or above this threshold to STDERR.
62+
# New logging configuration.
63+
log:
64+
enabled: false
65+
# https://www.cockroachlabs.com/docs/v21.1/configure-logs
66+
config: {}
67+
# file-defaults:
68+
# dir: /custom/dir/path/
69+
# fluent-defaults:
70+
# format: json-fluent
71+
# sinks:
72+
# stderr:
73+
# channels: [DEV]
74+
75+
# Logs at or above this threshold to STDERR. Ignored when "log" is enabled
6376
logtostderr: INFO
6477

6578
# Maximum storage capacity available to store temporary disk-based data for

tests/template/cockroachdb_helm_template_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,99 @@ func TestSelfSignerHelmValidation(t *testing.T) {
500500
})
501501
}
502502
}
503+
504+
// TestHelmLogConfigFileStatefulSet contains the tests around the new logging configuration
505+
func TestHelmLogConfigFileStatefulSet(t *testing.T) {
506+
t.Parallel()
507+
508+
var statefulset appsv1.StatefulSet
509+
var secret corev1.Secret
510+
// Path to the helm chart we will test
511+
helmChartPath, err := filepath.Abs("../../cockroachdb")
512+
require.NoError(t, err)
513+
514+
testCases := []struct {
515+
name string
516+
values map[string]string
517+
expect struct {
518+
statefulsetArgument string
519+
logConfig string
520+
secretExists bool
521+
}
522+
}{
523+
{
524+
"New logging configuration enabled",
525+
map[string]string{"conf.log.enabled": "true"},
526+
struct {
527+
statefulsetArgument string
528+
logConfig string
529+
secretExists bool
530+
} {
531+
"--log-config-file=/cockroach/log-config/log-config.yaml",
532+
"{}",
533+
true,
534+
},
535+
},
536+
{
537+
"New logging configuration overridden",
538+
map[string]string{
539+
"conf.log.enabled": "true",
540+
"conf.log.config": "file-defaults:\ndir: /custom/dir/path/",
541+
},
542+
struct {
543+
statefulsetArgument string
544+
logConfig string
545+
secretExists bool
546+
} {
547+
"--log-config-file=/cockroach/log-config/log-config.yaml",
548+
"file-defaults:\n dir: /custom/dir/path/",
549+
true,
550+
},
551+
},
552+
{
553+
"New logging configuration disabled",
554+
map[string]string{
555+
"conf.log.enabled": "false",
556+
"conf.logtostderr": "INFO",
557+
},
558+
struct {
559+
statefulsetArgument string
560+
logConfig string
561+
secretExists bool
562+
} {
563+
"--logtostderr=INFO",
564+
"",
565+
false,
566+
},
567+
},
568+
}
569+
570+
for _, testCase := range testCases {
571+
// Here, we capture the range variable and force it into the scope of this block. If we don't do this, when the
572+
// subtest switches contexts (because of t.Parallel), the testCase value will have been updated by the for loop
573+
// and will be the next testCase!
574+
testCase := testCase
575+
t.Run(testCase.name, func(subT *testing.T) {
576+
subT.Parallel()
577+
578+
// Now we try rendering the template, but verify we get an error
579+
options := &helm.Options{
580+
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
581+
SetValues: testCase.values,
582+
}
583+
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/statefulset.yaml"})
584+
585+
helm.UnmarshalK8SYaml(t, output, &statefulset)
586+
require.Contains(t, statefulset.Spec.Template.Spec.Containers[0].Args[2], testCase.expect.statefulsetArgument)
587+
588+
output, err = helm.RenderTemplateE(t, options, helmChartPath, releaseName, []string{"templates/secret.logconfig.yaml"})
589+
590+
require.Equal(subT, testCase.expect.secretExists, err == nil)
591+
592+
if testCase.expect.secretExists {
593+
helm.UnmarshalK8SYaml(t, output, &secret)
594+
require.Contains(subT, secret.StringData["log-config.yaml"], testCase.expect.logConfig)
595+
}
596+
})
597+
}
598+
}

0 commit comments

Comments
 (0)