Skip to content

Commit

Permalink
logrotate: add design and api for logrotate
Browse files Browse the repository at this point in the history
design and api for the csi pods logrotate

Signed-off-by: parth-gr <[email protected]>
  • Loading branch information
parth-gr committed Jul 10, 2024
1 parent 2bf6beb commit 75635ad
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 8 deletions.
34 changes: 29 additions & 5 deletions api/v1alpha1/driver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,26 @@ 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
// +optional
LogRotator *LogRotator `json:"logRotator,omitempty"`
}

type LogRotator struct {
// MaxFiles is the number of logrtoate files
// +optional
MaxFiles int `json:"maxFiles,omitempty"`
// MaxLogSize is the maximum size of the log per csi pods.
// +optional
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 directory path for the csi log files
// +optional
LogHostPath string `json:"logHostPath,omitempty"`
}

type SnapshotPolicyType string
Expand Down Expand Up @@ -72,9 +89,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 {
Expand Down Expand Up @@ -108,6 +126,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 {
Expand All @@ -119,6 +138,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 {
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions docs/design/logrotate.md
Original file line number Diff line number Diff line change
@@ -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: "<prefix>.<driver_type>.csi.ceph.com"
namespace: <operator-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
```
15 changes: 12 additions & 3 deletions docs/design/operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -283,6 +289,9 @@ spec:
renewDeadline: 100
retryPeriod: 10
attachRequired: true
logRotator:
cpu: "500m"
memory: "512Mi"
liveness:
metricsPort: 8000
deployCSIAddons: false
Expand Down

0 comments on commit 75635ad

Please sign in to comment.