Skip to content

Conversation

@mayankshah1607
Copy link
Member

@mayankshah1607 mayankshah1607 commented Dec 17, 2025

K8SPSMDB-1518 Powered by Pull Request Badge

CHANGE DESCRIPTION

Problem:
Short explanation of the problem.

Cause:
Short explanation of the root cause of the issue if applicable.

Solution:
Short explanation of the solution we are providing with this PR.

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?

Signed-off-by: Mayank Shah <mayank.shah@percona.com>
Signed-off-by: Mayank Shah <mayank.shah@percona.com>
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

Choose a reason for hiding this comment

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

[shellcheck (suggestion)] reported by reviewdog 🐶

"fmt"
"strconv"

api "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

[goimports-reviser] reported by reviewdog 🐶

Suggested change
api "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
corev1 "k8s.io/api/core/v1"
api "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"


api "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
"github.com/percona/percona-server-mongodb-operator/pkg/psmdb/config"
corev1 "k8s.io/api/core/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

[goimports-reviser] reported by reviewdog 🐶

Suggested change
corev1 "k8s.io/api/core/v1"

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.

deploy/crd.yaml Outdated
properties:
configuration:
type: string
extraConfigs:
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The field name is "extraConfigs" (plural) but based on the API design and the comment in psmdb_types.go, this should be "extraConfig" (singular) since it references a single ConfigMap, not multiple configs. This inconsistency matches the issue in psmdb_types.go and should be corrected for consistency.

Copilot uses AI. Check for mistakes.
properties:
configuration:
type: string
extraConfigs:
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The field name is "extraConfigs" (plural) but based on the API design and the comment in psmdb_types.go, this should be "extraConfig" (singular) since it references a single ConfigMap, not multiple configs. This inconsistency matches the issue in psmdb_types.go and should be corrected for consistency.

Copilot uses AI. Check for mistakes.
properties:
configuration:
type: string
extraConfigs:
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The field name is "extraConfigs" (plural) but based on the API design and the comment in psmdb_types.go, this should be "extraConfig" (singular) since it references a single ConfigMap, not multiple configs. This inconsistency matches the issue in psmdb_types.go and should be corrected for consistency.

Copilot uses AI. Check for mistakes.
Comment on lines 1511 to 1512
// AdditionalConfig allows specifying an additional configuration file for logrotate.
// This should be a reference to a ConfigMap in the same namespace.
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The comment says "AdditionalConfig" but the field is named "ExtraConfig". The comment should be updated to match the field name for consistency. Additionally, since the field references a single ConfigMap, the comment should clarify this is for "an additional configuration" rather than multiple configs.

Copilot uses AI. Check for mistakes.
if cr.CompareVersion("1.22.0") >= 0 && configs.LogRotateExtraConf.Type.IsUsable() {
volumes = append(volumes, corev1.Volume{
Name: logrotate.CustomVolumeName,
VolumeSource: configs.LogRotateConf.Type.VolumeSource(cr.Spec.LogCollector.LogRotate.ExtraConfig.Name),
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The volume source uses "configs.LogRotateConf.Type.VolumeSource" instead of "configs.LogRotateExtraConf.Type.VolumeSource". This is inconsistent with the check on line 184 which tests "configs.LogRotateExtraConf.Type.IsUsable()". The volume source should use LogRotateExtraConf to match the condition being checked.

Copilot uses AI. Check for mistakes.
properties:
configuration:
type: string
extraConfigs:
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The field name is "extraConfigs" (plural) but based on the API design and the comment in psmdb_types.go, this should be "extraConfig" (singular) since it references a single ConfigMap, not multiple configs. This inconsistency matches the issue in psmdb_types.go and should be corrected for consistency.

Copilot uses AI. Check for mistakes.
properties:
configuration:
type: string
extraConfigs:
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The field name is "extraConfigs" (plural) but based on the API design and the comment in psmdb_types.go, this should be "extraConfig" (singular) since it references a single ConfigMap, not multiple configs. This inconsistency matches the issue in psmdb_types.go and should be corrected for consistency.

Copilot uses AI. Check for mistakes.
Configuration string `json:"configuration,omitempty"`
// AdditionalConfig allows specifying an additional configuration file for logrotate.
// This should be a reference to a ConfigMap in the same namespace.
ExtraConfig corev1.LocalObjectReference `json:"extraConfigs,omitempty"`
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The JSON tag is "extraConfigs" (plural) but the Go field name is "ExtraConfig" (singular). This creates an inconsistency in the API. The JSON tag should be "extraConfig" to match the field name and maintain consistency, or the field should be renamed to ExtraConfigs.

Copilot uses AI. Check for mistakes.

MongodbConfig = "mongodb.conf"

custonConfigDir = "/opt/percona/logcollector/logrotate/conf.d"
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The constant name "custonConfigDir" contains a typo. It should be "customConfigDir" with "custom" spelled correctly.

Copilot uses AI. Check for mistakes.
Comment on lines +100 to +109
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
Name: VolumeName,
MountPath: custonConfigDir,
})
}
if cr.Spec.LogCollector.LogRotate.ExtraConfig.Name != "" {
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
Name: CustomVolumeName,
MountPath: custonConfigDir,
})
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

Both volume mounts for Configuration and ExtraConfig use the same mount path "custonConfigDir". This will cause a conflict because Kubernetes does not allow multiple volumes to be mounted at the same path. These should either use different mount paths, or the volumes should be merged somehow. The second volume mount will likely override the first one, causing the Configuration volume to be inaccessible.

Copilot uses AI. Check for mistakes.
Signed-off-by: Mayank Shah <mayank.shah@percona.com>
Signed-off-by: Mayank Shah <mayank.shah@percona.com>
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.

rm -rf /tmp/passwd
fi
exec go-cron "0 0 * * *" sh -c "logrotate -s /data/db/logs/logrotate.status /opt/percona/logcollector/logrotate/logrotate.conf;"
exec go-cron "0 0 * * *" sh -c "logrotate -s /data/db/logs/logrotate.status /opt/percona/logcollector/logrotate/logrotate.conf ${LOGROTATE_CONF_DIR};"
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The logrotate command is passed a directory path in LOGROTATE_CONF_DIR, but logrotate expects configuration file paths, not directories. This should use a glob pattern like "${LOGROTATE_CONF_DIR}/*" to include all files in the directory, or the directory should be included via an "include" directive in the main configuration file.

Copilot uses AI. Check for mistakes.
Comment on lines +105 to +109
if cr.Spec.LogCollector.LogRotate.ExtraConfig.Name != "" {
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
Name: CustomVolumeName,
MountPath: custonConfigDir,
})
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

Both volume mounts use the same MountPath (custonConfigDir). This will cause a conflict where the second volume mount will override the first. If both configuration sources need to be mounted, they should have different mount paths, or they should be mutually exclusive.

Copilot uses AI. Check for mistakes.
export PATH="$PATH":/opt/fluent-bit/bin

LOGROTATE_CONF_DIR=""
if [ -f /opt/percona/logcollector/logrotate/conf.d ]; then
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The condition uses "-f" flag which checks if the path is a regular file, but the path "/opt/percona/logcollector/logrotate/conf.d" is expected to be a directory. This should use "-d" flag instead to check if it's a directory.

Copilot uses AI. Check for mistakes.
if cr.CompareVersion("1.22.0") >= 0 && configs.LogRotateExtraConf.Type.IsUsable() {
volumes = append(volumes, corev1.Volume{
Name: logrotate.CustomVolumeName,
VolumeSource: configs.LogRotateConf.Type.VolumeSource(cr.Spec.LogCollector.LogRotate.ExtraConfig.Name),
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

Using configs.LogRotateConf.Type.VolumeSource but should use configs.LogRotateExtraConf.Type.VolumeSource instead. The volume is for the extra configuration, not the main logrotate configuration.

Copilot uses AI. Check for mistakes.
Comment on lines +184 to +189
if cr.CompareVersion("1.22.0") >= 0 && configs.LogRotateExtraConf.Type.IsUsable() {
volumes = append(volumes, corev1.Volume{
Name: logrotate.CustomVolumeName,
VolumeSource: configs.LogRotateConf.Type.VolumeSource(cr.Spec.LogCollector.LogRotate.ExtraConfig.Name),
})
}
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

Potential nil pointer dereference. The code accesses cr.Spec.LogCollector.LogRotate.ExtraConfig.Name without checking if cr.Spec.LogCollector or cr.Spec.LogCollector.LogRotate are nil. While configs.LogRotateExtraConf.Type.IsUsable() is checked, this doesn't guarantee that the nested LogCollector fields are non-nil. Add nil checks for cr.Spec.LogCollector and cr.Spec.LogCollector.LogRotate before accessing ExtraConfig.Name.

Copilot uses AI. Check for mistakes.
@JNKPercona
Copy link
Collaborator

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

commit: 135050b
image: perconalab/percona-server-mongodb-operator:PR-2151-135050b2

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.

3 participants