Skip to content

Commit 843d231

Browse files
committed
*: add errorlog to file
1 parent 459b3d3 commit 843d231

File tree

10 files changed

+130
-1
lines changed

10 files changed

+130
-1
lines changed

api/v1alpha1/mysqlcluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ type PodPolicy struct {
290290
// +optional
291291
// +kubebuilder:default:=false
292292
AuditLogTail bool `json:"auditLogTail,omitempty"`
293+
294+
// ErrorLogTail represents if tail the mysql error log.
295+
// +optional
296+
// +kubebuilder:default:=false
297+
ErrorLogTail bool `json:"errorLogTail,omitempty"`
293298
}
294299

295300
// Persistence is the desired spec for storing mysql data. Only one of its

api/v1beta1/mysqlcluster_conversion.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ func Convert_v1alpha1_MysqlClusterSpec_To_v1beta1_MysqlClusterSpec(in *v1alpha1.
7979
out.Backup.Image = in.PodPolicy.SidecarImage
8080
out.Backup.Resources = in.PodPolicy.ExtraResources
8181
out.Log.SlowLogTail = in.PodPolicy.SlowLogTail
82+
out.Log.AuditLogTail = in.PodPolicy.AuditLogTail
83+
out.Log.ErrorLogTail = in.PodPolicy.ErrorLogTail
8284
out.Tolerations = in.PodPolicy.Tolerations
8385
out.PriorityClassName = in.PodPolicy.PriorityClassName
8486
out.Log.BusyboxImage = in.PodPolicy.BusyboxImage
@@ -137,13 +139,15 @@ func Convert_v1beta1_MysqlClusterSpec_To_v1alpha1_MysqlClusterSpec(in *MysqlClus
137139
out.Persistence.Size = FormatQuantity(in.Storage.Resources.Requests[corev1.ResourceStorage])
138140
out.Persistence.AccessModes = in.Storage.AccessModes
139141
out.XenonOpts = v1alpha1.XenonOpts(in.Xenon)
140-
// //TODO in.Backup
142+
141143
out.PodPolicy.ExtraResources = in.Backup.Resources
142144
out.PodPolicy.SidecarImage = in.Backup.Image
143145
out.MetricsOpts.Image = in.Monitoring.Exporter.Image
144146
out.MetricsOpts.Resources = in.Monitoring.Exporter.Resources
145147
out.MysqlOpts.Image = in.Image
146148
out.PodPolicy.SlowLogTail = in.Log.SlowLogTail
149+
out.PodPolicy.AuditLogTail = in.Log.AuditLogTail
150+
out.PodPolicy.ErrorLogTail = in.Log.ErrorLogTail
147151
out.PodPolicy.BusyboxImage = in.Log.BusyboxImage
148152
out.MetricsOpts.Enabled = in.Monitoring.Exporter.Enabled
149153
out.PodPolicy.ImagePullPolicy = in.ImagePullPolicy

api/v1beta1/mysqlcluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,11 @@ type LogOpts struct {
459459
// +kubebuilder:default:=false
460460
AuditLogTail bool `json:"auditLogTail,omitempty"`
461461

462+
// ErrorLogTail represents if tail the mysql error log.
463+
// +optional
464+
// +kubebuilder:default:=false
465+
ErrorLogTail bool `json:"errorLogTail,omitempty"`
466+
462467
//Log container resources of a MySQL container.
463468
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
464469
}

charts/mysql-operator/templates/mysql.radondb.com_mysqlclusters.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,10 @@ spec:
12071207
default: busybox:1.32
12081208
description: The busybox image.
12091209
type: string
1210+
errorLogTail:
1211+
default: false
1212+
description: ErrorLogTail represents if tail the mysql error log.
1213+
type: boolean
12101214
extraResources:
12111215
default:
12121216
requests:
@@ -3529,6 +3533,10 @@ spec:
35293533
default: false
35303534
description: AuditLogTail represents if tail the mysql audit log.
35313535
type: boolean
3536+
errorLogTail:
3537+
default: false
3538+
description: ErrorLogTail represents if tail the mysql error log.
3539+
type: boolean
35323540
image:
35333541
default: busybox:1.32
35343542
description: To specify the image that will be used for log container.

config/crd/bases/mysql.radondb.com_mysqlclusters.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,10 @@ spec:
11891189
default: busybox:1.32
11901190
description: The busybox image.
11911191
type: string
1192+
errorLogTail:
1193+
default: false
1194+
description: ErrorLogTail represents if tail the mysql error log.
1195+
type: boolean
11921196
extraResources:
11931197
default:
11941198
requests:
@@ -3511,6 +3515,10 @@ spec:
35113515
default: false
35123516
description: AuditLogTail represents if tail the mysql audit log.
35133517
type: boolean
3518+
errorLogTail:
3519+
default: false
3520+
description: ErrorLogTail represents if tail the mysql error log.
3521+
type: boolean
35143522
image:
35153523
default: busybox:1.32
35163524
description: To specify the image that will be used for log container.

mysqlcluster/container/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func EnsureContainer(name string, c *mysqlcluster.MysqlCluster) corev1.Container
7878
ctr = &slowLog{c, name}
7979
case utils.ContainerAuditLogName:
8080
ctr = &auditLog{c, name}
81+
case utils.ContainerErrorLogName:
82+
ctr = &errorLog{c, name}
8183
case utils.ContainerBackupName:
8284
ctr = &backupSidecar{c, name}
8385
}

mysqlcluster/container/errorlog.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Copyright 2021 RadonDB.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package container
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
22+
"github.com/radondb/radondb-mysql-kubernetes/mysqlcluster"
23+
"github.com/radondb/radondb-mysql-kubernetes/utils"
24+
)
25+
26+
// errorLog used for auditlog container.
27+
type errorLog struct {
28+
*mysqlcluster.MysqlCluster
29+
30+
// The name of the auditlog container.
31+
name string
32+
}
33+
34+
// getName get the container name.
35+
func (c *errorLog) getName() string {
36+
return c.name
37+
}
38+
39+
// getImage get the container image.
40+
func (c *errorLog) getImage() string {
41+
return c.Spec.PodPolicy.BusyboxImage
42+
}
43+
44+
// getCommand get the container command.
45+
func (c *errorLog) getCommand() []string {
46+
logsName := "/mysql-error.log"
47+
return []string{"sh", "-c", "while true; do if [ -f " + utils.LogsVolumeMountPath + logsName + " ] ; then break; fi;sleep 1; done; " +
48+
"tail -f " + utils.LogsVolumeMountPath + logsName}
49+
}
50+
51+
// getEnvVars get the container env.
52+
func (c *errorLog) getEnvVars() []corev1.EnvVar {
53+
return nil
54+
}
55+
56+
// getLifecycle get the container lifecycle.
57+
func (c *errorLog) getLifecycle() *corev1.Lifecycle {
58+
return nil
59+
}
60+
61+
// getResources get the container resources.
62+
func (c *errorLog) getResources() corev1.ResourceRequirements {
63+
return c.Spec.PodPolicy.ExtraResources
64+
}
65+
66+
// getPorts get the container ports.
67+
func (c *errorLog) getPorts() []corev1.ContainerPort {
68+
return nil
69+
}
70+
71+
// getLivenessProbe get the container livenessProbe.
72+
func (c *errorLog) getLivenessProbe() *corev1.Probe {
73+
return nil
74+
}
75+
76+
// getReadinessProbe get the container readinessProbe.
77+
func (c *errorLog) getReadinessProbe() *corev1.Probe {
78+
return nil
79+
}
80+
81+
// getVolumeMounts get the container volumeMounts.
82+
func (c *errorLog) getVolumeMounts() []corev1.VolumeMount {
83+
return []corev1.VolumeMount{
84+
{
85+
Name: utils.LogsVolumeName,
86+
MountPath: utils.LogsVolumeMountPath,
87+
},
88+
}
89+
}

mysqlcluster/mysqlcluster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ func (c *MysqlCluster) EnsureMysqlConf() {
427427
}
428428

429429
}
430+
if c.Spec.PodPolicy.ErrorLogTail {
431+
c.Spec.MysqlOpts.MysqlConf["log-error"] = utils.LogsVolumeMountPath + "/mysql-error.log"
432+
}
430433
}
431434

432435
// sizeToBytes parses a string formatted by ByteSize as bytes.

mysqlcluster/syncer/statefulset.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,11 @@ func (s *StatefulSetSyncer) ensurePodSpec() corev1.PodSpec {
441441
if s.Spec.PodPolicy.AuditLogTail {
442442
containers = append(containers, container.EnsureContainer(utils.ContainerAuditLogName, s.MysqlCluster))
443443
}
444+
if s.Spec.PodPolicy.ErrorLogTail {
445+
// 1.create errorLog
446+
containers = append(containers, container.EnsureContainer(utils.ContainerErrorLogName, s.MysqlCluster))
444447

448+
}
445449
return corev1.PodSpec{
446450
InitContainers: initContainers,
447451
Containers: containers,

utils/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const (
4646
ContainerMetricsName = "metrics"
4747
ContainerSlowLogName = "slowlog"
4848
ContainerAuditLogName = "auditlog"
49+
ContainerErrorLogName = "errorlog"
4950
ContainerBackupName = "backup"
5051
ContainerBackupJobName = "backup-job"
5152

0 commit comments

Comments
 (0)