Skip to content

Commit

Permalink
csi: add log rotation for csi pod containers
Browse files Browse the repository at this point in the history
1) Make the csi container logs persisted in a file

2) Add log roation to rotate the log file

3) Provide api specs to configure the log rotate

closes: #12809

Signed-off-by: parth-gr <partharora1010@gmail.com>
  • Loading branch information
parth-gr committed Jun 11, 2024
1 parent c4e99c1 commit 144aee9
Showing 1 changed file with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,32 @@ spec:
{{ if .ProvisionerPriorityClassName }}
priorityClassName: {{ .ProvisionerPriorityClassName }}
{{ end }}
initContainers:
- name: create-logrotate-config
image: {{ .CSIPluginImage }}
command: ["/bin/sh", "-c"]
args:
- |
echo "Starting init container";
mkdir -p /logrotate-config;
if [ -d /etc/logrotate.d ]; then
cp -v /etc/logrotate.d/* /logrotate-config/ || echo "No files to copy from /etc/logrotate.d";
else
echo "/etc/logrotate.d does not exist";
fi;
echo '/var/lib/cephcsi/log/*.log {
daily
missingok
rotate 7
compress
size 500M
copytruncate
start 1
}' > /logrotate-config/csi;
echo "Init container completed";
volumeMounts:
- name: csi-logs-logrotate
mountPath: /logrotate-config
containers:
- name: csi-provisioner
image: {{ .ProvisionerImage }}
Expand All @@ -38,6 +64,9 @@ spec:
- "--extra-create-metadata=true"
- "--prevent-volume-mode-conversion=true"
- "--feature-gates=HonorPVReclaimPolicy=true"
- "--logtostderr=false"
- "--alsologtostderr=true"
- "--log_file=/var/lib/cephcsi/log/rbdprovisioner.log"
{{- if .EnableCSITopology }}
- "--feature-gates=Topology=true"
{{- end }}
Expand All @@ -48,6 +77,10 @@ spec:
volumeMounts:
- name: socket-dir
mountPath: /csi
- mountPath: /var/lib/cephcsi/log/
name: csi-log
- mountPath: /etc/logrotate.d
name: csi-logs-logrotate
- name: csi-resizer
image: {{ .ResizerImage }}
args:
Expand All @@ -68,6 +101,8 @@ spec:
volumeMounts:
- name: socket-dir
mountPath: /csi
- mountPath: /var/lib/cephcsi/log/
name: csi-log
{{ if .RBDAttachRequired }}
- name: csi-attacher
image: {{ .AttacherImage }}
Expand Down Expand Up @@ -116,7 +151,7 @@ spec:
{{ if .EnableOMAPGenerator }}
- name: csi-omap-generator
image: {{ .CSIPluginImage }}
args :
args:
- "--type=controller"
- "--drivernamespace=$(DRIVER_NAMESPACE)"
- "--v={{ .LogLevel }}"
Expand All @@ -142,7 +177,7 @@ spec:
{{ if .EnableCSIAddonsSideCar }}
- name: csi-addons
image: {{ .CSIAddonsImage }}
args :
args:
- "--node-id=$(NODE_ID)"
- "--v={{ .LogLevel }}"
- "--csi-addons-address=$(CSIADDONS_ENDPOINT)"
Expand Down Expand Up @@ -183,14 +218,17 @@ spec:
{{ end }}
- name: csi-rbdplugin
image: {{ .CSIPluginImage }}
args :
args:
- "--nodeid=$(NODE_ID)"
- "--endpoint=$(CSI_ENDPOINT)"
- "--v={{ .LogLevel }}"
- "--type=rbd"
- "--controllerserver=true"
- "--drivername={{ .DriverNamePrefix }}rbd.csi.ceph.com"
- "--pidlimit=-1"
- "--logtostderr=false"
- "--alsologtostderr=true"
- "--log_file=/var/lib/cephcsi/log/rbdplugin.log"
{{ if .EnableCSIAddonsSideCar }}
- "--csi-addons-endpoint=$(CSIADDONS_ENDPOINT)"
{{ end }}
Expand Down Expand Up @@ -225,6 +263,10 @@ spec:
mountPath: /csi
- mountPath: /dev
name: host-dev
- mountPath: /var/lib/cephcsi/log/
name: csi-log
- mountPath: /etc/logrotate.d
name: csi-logs-logrotate
- mountPath: /sys
name: host-sys
- mountPath: /lib/modules
Expand Down Expand Up @@ -272,6 +314,12 @@ spec:
- name: host-dev
hostPath:
path: /dev
- name: csi-log
hostPath:
path: /var/lib/cephcsi/log/
- name: csi-logs-logrotate
hostPath:
path: /etc/logrotate.d
- name: host-sys
hostPath:
path: /sys
Expand Down

0 comments on commit 144aee9

Please sign in to comment.