-
Notifications
You must be signed in to change notification settings - Fork 161
K8SPSMDB-1518: allow specifying logrotate configuration #2151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Mayank Shah <mayank.shah@percona.com>
Signed-off-by: Mayank Shah <mayank.shah@percona.com>
There was a problem hiding this comment.
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 🐶
| exec "$@" $fluentbit_opt |
| "fmt" | ||
| "strconv" | ||
|
|
||
| api "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1" |
There was a problem hiding this comment.
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 🐶
| 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" |
There was a problem hiding this comment.
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 🐶
| corev1 "k8s.io/api/core/v1" |
There was a problem hiding this 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
LogRotateSpectype withConfigurationandExtraConfigfields to the API - Refactored logrotate container creation from
pkg/psmdb/logcollector/container.goto new packagepkg/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: |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
deploy/bundle.yaml
Outdated
| properties: | ||
| configuration: | ||
| type: string | ||
| extraConfigs: |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
| properties: | ||
| configuration: | ||
| type: string | ||
| extraConfigs: |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
pkg/apis/psmdb/v1/psmdb_types.go
Outdated
| // AdditionalConfig allows specifying an additional configuration file for logrotate. | ||
| // This should be a reference to a ConfigMap in the same namespace. |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
| 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), |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
| properties: | ||
| configuration: | ||
| type: string | ||
| extraConfigs: |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
deploy/cw-bundle.yaml
Outdated
| properties: | ||
| configuration: | ||
| type: string | ||
| extraConfigs: |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
pkg/apis/psmdb/v1/psmdb_types.go
Outdated
| 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"` |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
|
|
||
| MongodbConfig = "mongodb.conf" | ||
|
|
||
| custonConfigDir = "/opt/percona/logcollector/logrotate/conf.d" |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
| 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, | ||
| }) |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
Signed-off-by: Mayank Shah <mayank.shah@percona.com>
Signed-off-by: Mayank Shah <mayank.shah@percona.com>
There was a problem hiding this 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};" |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
| if cr.Spec.LogCollector.LogRotate.ExtraConfig.Name != "" { | ||
| container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{ | ||
| Name: CustomVolumeName, | ||
| MountPath: custonConfigDir, | ||
| }) |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
| export PATH="$PATH":/opt/fluent-bit/bin | ||
|
|
||
| LOGROTATE_CONF_DIR="" | ||
| if [ -f /opt/percona/logcollector/logrotate/conf.d ]; then |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
| 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), |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
| 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), | ||
| }) | ||
| } |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
commit: 135050b |
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
Needs Doc) and QA (Needs QA)?Tests
compare/*-oc.yml)?Config/Logging/Testability