Skip to content

Conversation

@pooknull
Copy link
Contributor

@pooknull pooknull commented Dec 19, 2025

K8SPSMDB-1531 Powered by Pull Request Badge

https://perconadev.atlassian.net/browse/K8SPSMDB-1531

DESCRIPTION

This PR adds the following fields to the cr.yaml

  • .spec.replsets[].hookScript
  • .spec.replsets[].hidden.hookScript
  • .spec.replsets[].nonvoting.hookScript
  • .spec.replsets[].arbiter.hookScript
  • .spec.sharding.configsvrReplSet.hookScript
  • .spec.sharding.mongos.hookScript
  • .spec.backup.hookScript

Each hookScript field is a shell script that will be executed from the container entrypoint of the corresponding pods

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 19, 2025 11:24
@pull-request-size pull-request-size bot added the size/XL 500-999 lines label Dec 19, 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 the hookScript functionality to the Percona Server MongoDB Operator, allowing users to define custom scripts that execute during pod initialization. The PR also includes cleanup of version-based conditionals for features from older operator versions.

  • Added hookScript field to the MultiAZ struct in the API, enabling hookscript configuration across different MongoDB components
  • Implemented ConfigMap-based volume mounting for hook scripts with reconciliation logic in the controller
  • Cleaned up version checks by removing conditionals for features already available in supported versions (< 1.16.0)

Reviewed changes

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

Show a summary per file
File Description
pkg/apis/psmdb/v1/psmdb_types.go Added HookScript field to MultiAZ struct
pkg/psmdb/config/const.go Added constants for hookscript volume and mount path
pkg/naming/naming.go Added naming functions for hookscript ConfigMaps
pkg/psmdb/statefulset.go Added hookscript volume mounting logic and removed old version checks
pkg/psmdb/mongos.go Added hookscript support for mongos and removed old version checks
pkg/psmdb/container.go Added hookscript volume mount and removed old version checks
pkg/controller/perconaservermongodb/psmdb_controller.go Refactored ConfigMap reconciliation and added hookscript ConfigMap management
build/ps-entry.sh Added hookscript execution and fixed indentation
deploy/cr.yaml Added example hookscript configuration
deploy/crd.yaml, deploy/bundle.yaml, deploy/cw-bundle.yaml, config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml, e2e-tests/version-service/conf/crd.yaml Updated CRD schemas with hookScript field

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

Copy link
Collaborator

@hors hors left a comment

Choose a reason for hiding this comment

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

I think we need to add it for PBM agent as well

Copilot AI review requested due to automatic review settings December 23, 2025 13:49
@pull-request-size pull-request-size bot added size/XXL 1000+ lines and removed size/XL 500-999 lines labels 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 33 out of 33 changed files in this pull request and generated 12 comments.

Comments suppressed due to low confidence (1)

pkg/controller/perconaservermongodb/psmdb_controller.go:425

  • The reconcileBackups call is now made regardless of whether backups are enabled. This creates redundant logic since reconcileBackups internally checks if backups are enabled (line 41-43) and then calls reconcileBackupTasks. However, reconcileBackupTasks is also called separately at line 420 when cr.Spec.Backup.Enabled is true. This means when backups are enabled, reconcileBackupTasks will be called twice - once inside reconcileBackups and once explicitly here. Consider removing the separate reconcileBackupTasks call at lines 419-425 since it's now handled within reconcileBackups.
	}
	if ikCreated {
		log.Info("Created a new mongo key", "KeyName", cr.Spec.Secrets.GetInternalKey(cr))
	}

	created, err := r.ensureSecurityKey(ctx, cr, cr.Spec.Secrets.EncryptionKey, api.EncryptionKeyName, 32, false)
	if err != nil {
		err = errors.Wrapf(err, "ensure mongo Key %s", cr.Spec.Secrets.EncryptionKey)
		return reconcile.Result{}, err
	}
	if created {

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

@JNKPercona
Copy link
Collaborator

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

commit: 25830b6
image: perconalab/percona-server-mongodb-operator:PR-2155-25830b60

@pooknull pooknull requested a review from hors December 24, 2025 08:35
@pooknull pooknull marked this pull request as ready for review December 24, 2025 08:35
Comment on lines +38 to +40
if err := r.reconcileBackupHookscript(ctx, cr); err != nil {
return errors.Wrap(err, "reconcile backup hookscript")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to do this if backups are disabled?

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