From bc633c6755485e0f7ee0cb4eaf7be76d595de685 Mon Sep 17 00:00:00 2001 From: parth-gr Date: Fri, 5 Jul 2024 19:39:19 +0530 Subject: [PATCH] logrotate: add design and api for logrotate design and api for the csi pods logrotate Signed-off-by: parth-gr --- api/v1alpha1/driver_types.go | 30 +++++++++-- api/v1alpha1/zz_generated.deepcopy.go | 10 ++++ docs/design/logrotate.md | 73 +++++++++++++++++++++++++++ docs/design/operator.md | 15 ++++-- 4 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 docs/design/logrotate.md diff --git a/api/v1alpha1/driver_types.go b/api/v1alpha1/driver_types.go index 7006d7ec..c714be6d 100644 --- a/api/v1alpha1/driver_types.go +++ b/api/v1alpha1/driver_types.go @@ -28,9 +28,22 @@ type LogSpec struct { // Log level for driver pods, // Supported values from 0 to 5. 0 for general useful logs (the default), 5 for trace level verbosity. // Default to 0 - LogLevel int `json:"logLevel,omitempty"` - MaxFiles int `json:"maxFiles,omitempty"` + LogLevel int `json:"logLevel,omitempty"` + // log rotation for csi pods + LogRotator *LogRotator `json:"logRotator,omitempty"` +} + +type LogRotator struct { + // MaxFiles is the number of logrtoate files + MaxFiles int `json:"maxFiles,omitempty"` + // MaxLogSize is the maximum size of the log per csi pods. MaxLogSize resource.Quantity `json:"maxLogSize,omitempty"` + // Periodicity is the periodicity of the log rotation. + // +kubebuilder:validation:Enum=hourly;daily;weekly;monthly;1h + // +optional + Periodicity string `json:"periodicity,omitempty"` + // LogHostPath is the prefix path for the csi log files + LogHostPath string `json:"logHostPath,omitempty"` } type SnapshotPolicyType string @@ -72,9 +85,10 @@ type PodCommonSpec struct { } type PluginResourcesSpec struct { - Registrar *corev1.ResourceRequirements `json:"registrar,omitempty"` - Liveness *corev1.ResourceRequirements `json:"liveness,omitempty"` - Plugin *corev1.ResourceRequirements `json:"plugin,omitempty"` + Registrar *corev1.ResourceRequirements `json:"registrar,omitempty"` + Liveness *corev1.ResourceRequirements `json:"liveness,omitempty"` + Plugin *corev1.ResourceRequirements `json:"plugin,omitempty"` + LogRotator *corev1.ResourceRequirements `json:"logRotator,omitempty"` } type PluginSpec struct { @@ -108,6 +122,7 @@ type ProvisionerResourcesSpec struct { OMapGenerator *corev1.ResourceRequirements `json:"omapGenerator,omitempty"` Liveness *corev1.ResourceRequirements `json:"liveness,omitempty"` Plugin *corev1.ResourceRequirements `json:"plugin,omitempty"` + LogRotator *corev1.ResourceRequirements `json:"logRotator,omitempty"` } type ProvisionerSpec struct { @@ -119,6 +134,11 @@ type ProvisionerSpec struct { // Resource requirements for provisioner's containers Resources ProvisionerResourcesSpec `json:"resources,omitempty"` + + // To enable logrotation for csi pods, + // Some platforms require provisioner pods to run privileged, + // to be able to write to `hostPaths` in OpenShift with SELinux restrictions. + Privileged bool `json:"privileged,omitempty"` } type LivenessSpec struct { diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index a6bda332..b3e91b40 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -363,6 +363,11 @@ func (in *PluginResourcesSpec) DeepCopyInto(out *PluginResourcesSpec) { *out = new(v1.ResourceRequirements) (*in).DeepCopyInto(*out) } + if in.LogRotator != nil { + in, out := &in.LogRotator, &out.LogRotator + *out = new(v1.ResourceRequirements) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PluginResourcesSpec. @@ -493,6 +498,11 @@ func (in *ProvisionerResourcesSpec) DeepCopyInto(out *ProvisionerResourcesSpec) *out = new(v1.ResourceRequirements) (*in).DeepCopyInto(*out) } + if in.LogRotator != nil { + in, out := &in.LogRotator, &out.LogRotator + *out = new(v1.ResourceRequirements) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProvisionerResourcesSpec. diff --git a/docs/design/logrotate.md b/docs/design/logrotate.md new file mode 100644 index 00000000..138ab39a --- /dev/null +++ b/docs/design/logrotate.md @@ -0,0 +1,73 @@ +# Ceph CSI Log Rotate Design Document + +Log Rotate is the ability to rotate the logs by controlling the size of log files. +With csi it will be includes to all the csi pods which includes csi daemons and provisoners. +Using logrotate will create a log file at the hostpath and enable the logrotator sidecar container. +Logrotator sidecar container will make sure that log files are rotated as per the inputs. + +Logroate configuration, + +`CephCSIOperatorConfig CRD`: + +```yaml +kind: CephCSIOperatorConfig +apiVersion: csi.ceph.io/v1alpha1 +…. +spec: + logLevel: 1 + driverSpecDefaults: + log: + logLevel: 5 + logRotator: + # one of: hourly, daily, weekly + Periodicity: daily + # SUFFIX may be 'M' or 'G' + MaxLogSize: 500M + MaxFiles: 5 + logHostPath: /var/lib/log +``` + +Similar settings will be overrided by `CephCSIDriver CRD`: + +```yaml +kind: CephCSIDriver +apiVersion: csi.ceph.io/v1alpha1 +metadata: +name: "..csi.ceph.com" +namespace: +spec: + logLevel: 1 + driverSpecDefaults: + log: + logLevel: 5 + logRotator: + # one of: hourly, daily, weekly + Periodicity: daily + # SUFFIX may be 'M' or 'G' + MaxLogSize: 500M + MaxFiles: 5 + logHostPath: /var/lib/rook +``` + +Logrotator sidecar container cpu and memory usage can configured by, + +`CephCSIOperatorConfig CRD`: +```yaml +spec: + provisioner: + logRotator: + cpu: "500m" + memory: "512Mi" + plugin: + logRotator: + cpu: "500m" + memory: "512Mi" +``` + +For systems where SELinux is enabled (e.g. OpenShift),start plugin-controller as privileged that mount a host path. +`CephCSIOperatorConfig CRD`: +```yaml +spec: + provisioner: + privileged: true +``` \ No newline at end of file diff --git a/docs/design/operator.md b/docs/design/operator.md index 49725a0a..e1c24a1f 100644 --- a/docs/design/operator.md +++ b/docs/design/operator.md @@ -85,10 +85,12 @@ metadata: spec: logLevel: 1 driverSpecDefaults: - logging: + log: logLevel: 5 - maxfiles: 5 - maxLogSize: 10M + Periodicity: daily + MaxLogSize: 500M + MaxFiles: 5 + logHostPath: /var/lib/log clusterName: 5c63ad7e-74fe-4724-a511-4ccdc560da56 enableMetadata: true grpcTimeout: 100 @@ -159,6 +161,7 @@ spec: priorityClassName: system-cluster-critical labels: app: provisioner + privileged: true annotations: k8s.v1.cni.cncf.io/networks: macvlan-conf-1 provisionerReplicas: 2 @@ -272,6 +275,9 @@ spec: app: cephfs-plugin annotations: k8s.v1.cni.cncf.io/networks: macvlan-conf-1 + logRotator: + cpu: "500m" + memory: "512Mi" provisioner: labels: app: ceph-fs-provisioner @@ -283,6 +289,9 @@ spec: renewDeadline: 100 retryPeriod: 10 attachRequired: true + logRotator: + cpu: "500m" + memory: "512Mi" liveness: metricsPort: 8000 deployCSIAddons: false