Skip to content

Conversation

@mayankshah1607
Copy link
Member

@mayankshah1607 mayankshah1607 commented Dec 17, 2025

K8SPSMDB-1518 Powered by Pull Request Badge

CHANGE DESCRIPTION

Allows specifying custom configuration for logrotate:

  • override the default logroate conf
  • provide additional logrotate configuration
  • allow specifying logrotate schedule

Examples:

  1. Override the main logrotate configuration:
apiVersion: psmdb.percona.com/v1
kind: PerconaServerMongoDB
metadata:
  name: minimal-cluster
spec:
  logcollector:
    # ...
    logrotate:
      configuration: |
        /data/db/logs/*.log {
           daily
           minsize 10K
           maxsize 20K
           rotate 10
           missingok
           nocompress
           notifempty
           sharedscripts
           postrotate
               mongosh "mongodb://${MONGODB_USER}:${MONGODB_PASSWORD}@${MONGODB_HOST}:${MONGODB_PORT}/admin" \
                       --eval 'db.adminCommand({ logRotate: 1 })'
               find /data/db/logs/ -type f -name 'mongod.log.*' -mtime +7 -delete
               find /data/db/logs/ -type f -name 'mongod.full.log' -mtime +7 -delete
           endscript
        }
  1. Provide additional logrotate config (for example, for rotating auditlogs)
apiVersion: v1
kind: ConfigMap
metadata:
  name: logrotate-custom-conf
data:
  custom.conf: |
    /data/db/audit/*.json {
       minsize 10K
       maxsize 20K
       rotate 10
       missingok
       nocompress
       notifempty
       sharedscripts
       copytruncate
      }
---
apiVersion: psmdb.percona.com/v1
kind: PerconaServerMongoDB
metadata:
  name: minimal-cluster
spec:
  # ...
  replsets:
  - name: rs0
    size: 1
    configuration: |
      auditLog:
        destination: file
        format: JSON
        path: /data/db/audit/audit.json
    volumeSpec:
      persistentVolumeClaim:
        resources:
          requests:
            storage: 3Gi
  logcollector:
    # ...
    logrotate:
      extraConfig:
        name: logrotate-custom-conf
  1. Provide custom schedule
apiVersion: psmdb.percona.com/v1
kind: PerconaServerMongoDB
metadata:
  name: minimal-cluster
spec:
  # ...
  replsets:
  - name: rs0
    size: 1
    configuration: |
      auditLog:
        destination: file
        format: JSON
        path: /data/db/audit/audit.json
    volumeSpec:
      persistentVolumeClaim:
        resources:
          requests:
            storage: 3Gi
  logcollector:
    # ...
    logrotate:
      schedule: "0 0 * * 0"

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?
  • Are OpenShift compare files changed for E2E tests (compare/*-oc.yml)?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported MongoDB version?
  • Does the change support oldest and newest supported Kubernetes version?

Copilot AI review requested due to automatic review settings December 17, 2025 12:21
@pull-request-size pull-request-size bot added the size/L 100-499 lines label Dec 17, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for customizable logrotate configuration in the Percona Server MongoDB Operator. It introduces new API fields to allow users to specify custom logrotate configurations either inline or via external ConfigMaps, and refactors the logrotate container code into a dedicated package for better organization.

Key changes:

  • Added LogRotateSpec type with Configuration and ExtraConfig fields to the API
  • Refactored logrotate container creation from pkg/psmdb/logcollector/container.go to new package pkg/psmdb/logcollector/logrotate
  • Enhanced configuration hash calculation to include logrotate configurations for pod restart triggers

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
pkg/apis/psmdb/v1/psmdb_types.go Adds LogRotateSpec type with configuration fields
pkg/apis/psmdb/v1/zz_generated.deepcopy.go Auto-generated deep copy methods for LogRotateSpec
pkg/psmdb/logcollector/logrotate/container.go New package with logrotate container creation logic and volume mounts
pkg/psmdb/logcollector/container.go Removes logRotationContainer function, delegates to logrotate package
pkg/psmdb/statefulset.go Adds logrotate config params, volumes, and enhanced hash calculation
pkg/controller/perconaservermongodb/statefulset.go Retrieves logrotate configs and passes to statefulset creation
pkg/controller/perconaservermongodb/psmdb_controller.go Adds reconcileLogRotateConfigMaps for managing logrotate ConfigMap
build/logcollector/entrypoint.sh Adds support for custom logrotate config directory in entrypoint script
config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml Updates CRD schema with logRotate fields
deploy/crd.yaml Updates CRD schema with logRotate fields
deploy/bundle.yaml Updates CRD schema with logRotate fields
deploy/cw-bundle.yaml Updates CRD schema with logRotate fields
e2e-tests/version-service/conf/crd.yaml Updates CRD schema with logRotate fields

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Mayank Shah <[email protected]>
Signed-off-by: Mayank Shah <[email protected]>
Copilot AI review requested due to automatic review settings December 17, 2025 12:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Mayank Shah <[email protected]>
Signed-off-by: Mayank Shah <[email protected]>
Signed-off-by: Mayank Shah <[email protected]>
Signed-off-by: Mayank Shah <[email protected]>
Signed-off-by: Mayank Shah <[email protected]>
Copilot AI review requested due to automatic review settings December 22, 2025 10:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1511 to 1512
// ExtraConfig allows specifying logrotate configuration file in addition to the main configuration file.
// This should be a reference to a ConfigMap in the same namespace.
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states that ExtraConfig should reference a ConfigMap in the same namespace, but does not specify the required structure or key names within that ConfigMap. The entrypoint script expects a file named 'custom.conf' (line 15 of build/logcollector/entrypoint.sh), but when a ConfigMap is projected into a volume, each key in the ConfigMap becomes a filename. Users need to know they must create a ConfigMap with a key named 'custom.conf' for this feature to work correctly. Consider adding this requirement to the field documentation.

Suggested change
// ExtraConfig allows specifying logrotate configuration file in addition to the main configuration file.
// This should be a reference to a ConfigMap in the same namespace.
// ExtraConfig allows specifying a logrotate configuration file in addition to the main configuration file.
// This should be a reference to a ConfigMap in the same namespace.
// The referenced ConfigMap must contain a key named "custom.conf"; when the ConfigMap is mounted as a volume,
// that key becomes a file named "custom.conf" that is loaded as the extra logrotate configuration.

Copilot uses AI. Check for mistakes.
Signed-off-by: Mayank Shah <[email protected]>
Signed-off-by: Mayank Shah <[email protected]>
Copilot AI review requested due to automatic review settings December 22, 2025 10:19
@mayankshah1607 mayankshah1607 marked this pull request as ready for review December 22, 2025 10:20
Copilot AI review requested due to automatic review settings December 23, 2025 06:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Mayank Shah <[email protected]>
Signed-off-by: Mayank Shah <[email protected]>
Copilot AI review requested due to automatic review settings December 23, 2025 06:58
Signed-off-by: Mayank Shah <[email protected]>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 47 to 53
name string
cr *api.PerconaServerMongoDB
rsName string
component string
ls map[string]string
crUpdate func(cr *api.PerconaServerMongoDB)
additonalObjs []client.Object
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a spelling error in the variable name: "additonalObjs" should be "additionalObjs" (missing 'i').

Suggested change
name string
cr *api.PerconaServerMongoDB
rsName string
component string
ls map[string]string
crUpdate func(cr *api.PerconaServerMongoDB)
additonalObjs []client.Object
name string
cr *api.PerconaServerMongoDB
rsName string
component string
ls map[string]string
crUpdate func(cr *api.PerconaServerMongoDB)
additionalObjs []client.Object

Copilot uses AI. Check for mistakes.
Schedule: "0 0 */2 * *",
}
},
additonalObjs: []client.Object{
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a spelling error in the variable name: "additonalObjs" should be "additionalObjs" (missing 'i').

Copilot uses AI. Check for mistakes.
})
}

mockObjs = append(mockObjs, tt.additonalObjs...)
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a spelling error in the variable name: "additonalObjs" should be "additionalObjs" (missing 'i').

Suggested change
mockObjs = append(mockObjs, tt.additonalObjs...)
mockObjs = append(mockObjs, tt.additionalObjs...)

Copilot uses AI. Check for mistakes.
Signed-off-by: Mayank Shah <[email protected]>
Signed-off-by: Mayank Shah <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings December 23, 2025 07:35
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
egegunes
egegunes previously approved these changes Dec 23, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Mayank Shah <[email protected]>
Copilot AI review requested due to automatic review settings December 24, 2025 09:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@JNKPercona
Copy link
Collaborator

Test Name Result Time
arbiter passed 00:11:33
balancer passed 00:18:29
cross-site-sharded passed 00:18:47
custom-replset-name passed 00:10:12
custom-tls passed 00:14:29
custom-users-roles passed 00:10:59
custom-users-roles-sharded passed 00:12:05
data-at-rest-encryption passed 00:12:57
data-sharded passed 00:23:03
demand-backup passed 00:16:05
demand-backup-eks-credentials-irsa passed 00:00:08
demand-backup-fs passed 00:22:34
demand-backup-if-unhealthy passed 00:08:17
demand-backup-incremental passed 00:43:52
demand-backup-incremental-sharded passed 00:57:37
demand-backup-physical-parallel passed 00:08:12
demand-backup-physical-aws passed 00:12:24
demand-backup-physical-azure passed 00:11:50
demand-backup-physical-gcp-s3 passed 00:11:45
demand-backup-physical-gcp-native passed 00:11:49
demand-backup-physical-minio passed 00:20:19
demand-backup-physical-minio-native passed 00:19:41
demand-backup-physical-sharded-parallel passed 00:10:57
demand-backup-physical-sharded-aws passed 00:18:10
demand-backup-physical-sharded-azure passed 00:18:19
demand-backup-physical-sharded-gcp-native passed 00:18:00
demand-backup-physical-sharded-minio passed 00:17:14
demand-backup-physical-sharded-minio-native passed 00:17:24
demand-backup-sharded passed 00:25:39
expose-sharded passed 00:34:34
finalizer passed 00:10:07
ignore-labels-annotations passed 00:07:56
init-deploy passed 00:13:01
ldap passed 00:09:06
ldap-tls passed 00:13:05
limits passed 00:06:24
liveness passed 00:08:29
mongod-major-upgrade passed 00:11:53
mongod-major-upgrade-sharded passed 00:21:09
monitoring-2-0 passed 00:25:23
monitoring-pmm3 passed 00:29:04
multi-cluster-service passed 00:12:47
multi-storage passed 00:18:53
non-voting-and-hidden passed 00:16:46
one-pod passed 00:07:37
operator-self-healing-chaos passed 00:12:51
pitr passed 00:31:42
pitr-physical passed 01:02:25
pitr-sharded passed 00:23:06
pitr-to-new-cluster passed 00:24:18
pitr-physical-backup-source passed 00:54:12
preinit-updates passed 00:05:43
pvc-resize passed 00:13:35
recover-no-primary passed 00:27:31
replset-overrides passed 00:16:25
replset-remapping passed 00:08:53
replset-remapping-sharded passed 00:17:30
rs-shard-migration passed 00:14:02
scaling passed 00:11:25
scheduled-backup passed 00:18:27
security-context passed 00:07:04
self-healing-chaos passed 00:14:55
service-per-pod passed 00:19:28
serviceless-external-nodes passed 00:07:14
smart-update passed 00:08:30
split-horizon passed 00:07:58
stable-resource-version passed 00:04:52
storage passed 00:07:34
tls-issue-cert-manager passed 00:30:17
upgrade passed 00:09:49
upgrade-consistency passed 00:06:12
upgrade-consistency-sharded-tls passed 00:53:26
upgrade-sharded passed 00:19:52
upgrade-partial-backup failure 00:12:35
users passed 00:17:37
users-vault passed 00:13:42
version-service passed 00:24:51
Summary Value
Tests Run 77/77
Job Duration 04:22:30
Total Test Time 22:37:49

commit: 37812f2
image: perconalab/percona-server-mongodb-operator:PR-2151-37812f21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants