Skip to content

K8SPSMDB-1562: fix creation of nonvoting hookscript#2200

Merged
hors merged 3 commits intomainfrom
K8SPSMDB-1531-fix
Jan 16, 2026
Merged

K8SPSMDB-1562: fix creation of nonvoting hookscript#2200
hors merged 3 commits intomainfrom
K8SPSMDB-1531-fix

Conversation

@pooknull
Copy link
Contributor

@pooknull pooknull commented Jan 16, 2026

K8SPSMDB-1531 Powered by Pull Request Badge

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

DESCRIPTION

Problem:
Operator fails to deploy a cluster when .nonVoting.hookscript.script is specified:

ConfigMap "my-psmdb-psmdb-db-rs0-nonVoting-hookscript" is invalid: metadata.name: 
Invalid value: "my-psmdb-psmdb-db-rs0-nonVoting-hookscript": a lowercase RFC 1123 
subdomain must consist of lower case alphanumeric characters, '-' or '.', and must 
start and end with an alphanumeric character (e.g. 'example.com', regex used for 
validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')

Cause:
The HookScriptConfigMapName function generates a hook script name using the component label value. For non-voting pods, this value is nonVoting, which contains an uppercase letter.

Solution:
Force the HookScriptConfigMapName function to return a lowercase name

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 January 16, 2026 09:00
@pull-request-size pull-request-size bot added the size/XS 0-9 lines label Jan 16, 2026
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 fixes an issue with the creation of nonvoting hookscript ConfigMap names by ensuring they are lowercase. The problem likely arises because Kubernetes resource names (including ConfigMaps) must be lowercase, and the ComponentNonVoting constant is "nonVoting" with camelCase, which would produce invalid ConfigMap names when used in the hookscript name.

Changes:

  • Added strings.ToLower() wrapper to HookScriptConfigMapName function to ensure ConfigMap names are always lowercase
Comments suppressed due to low confidence (1)

pkg/naming/naming.go:86

  • The MongosHookScriptConfigMapName and PBMHookScriptConfigMapName functions should also apply strings.ToLower() to ensure consistency with HookScriptConfigMapName and to guarantee Kubernetes-compliant lowercase names in case cr.Name or components contain uppercase characters.
func MongosHookScriptConfigMapName(cr *psmdbv1.PerconaServerMongoDB) string {
	return fmt.Sprintf("%s-%s-hookscript", cr.Name, ComponentMongos)
}

func PBMHookScriptConfigMapName(cr *psmdbv1.PerconaServerMongoDB) string {
	return fmt.Sprintf("%s-pbm-hookscript", cr.Name)
}

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

@pooknull pooknull marked this pull request as ready for review January 16, 2026 09:11
Copilot AI review requested due to automatic review settings January 16, 2026 09:11
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 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

pkg/naming/naming.go:82

  • The MongosHookScriptConfigMapName function should also apply strings.ToLower() for consistency with HookScriptConfigMapName. While ComponentMongos is already lowercase, cr.Name could theoretically contain uppercase characters in edge cases, and applying lowercase conversion would make the function more defensive and consistent with the fix applied to HookScriptConfigMapName.
func MongosHookScriptConfigMapName(cr *psmdbv1.PerconaServerMongoDB) string {
	return fmt.Sprintf("%s-%s-hookscript", cr.Name, ComponentMongos)
}

pkg/naming/naming.go:86

  • The PBMHookScriptConfigMapName function should also apply strings.ToLower() for consistency with HookScriptConfigMapName. While 'pbm' is already lowercase, cr.Name could theoretically contain uppercase characters in edge cases, and applying lowercase conversion would make the function more defensive and consistent with the fix applied to HookScriptConfigMapName.
func PBMHookScriptConfigMapName(cr *psmdbv1.PerconaServerMongoDB) string {
	return fmt.Sprintf("%s-pbm-hookscript", cr.Name)
}

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

func HookScriptConfigMapName(cr *psmdbv1.PerconaServerMongoDB, rs *psmdbv1.ReplsetSpec, component string) string {
if rs == nil {
return fmt.Sprintf("%s-%s-hookscript", cr.Name, component)
return strings.ToLower(fmt.Sprintf("%s-%s-hookscript", cr.Name, component))
Copy link
Contributor

Choose a reason for hiding this comment

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

let's add a unit test for this given that we had an issue:

package naming

import (
	"testing"

	psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
	"github.com/stretchr/testify/assert"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestHookScriptConfigMapName(t *testing.T) {
	tests := map[string]struct {
		cr        *psmdbv1.PerconaServerMongoDB
		rs        *psmdbv1.ReplsetSpec
		component string
		expected  string
	}{
		"rs is nil": {
			cr: &psmdbv1.PerconaServerMongoDB{
				ObjectMeta: metav1.ObjectMeta{
					Name: "my-cluster",
				},
			},
			component: "mongos",
			expected:  "my-cluster-mongos-hookscript",
		},
		"rs is not nil": {
			cr: &psmdbv1.PerconaServerMongoDB{
				ObjectMeta: metav1.ObjectMeta{
					Name: "my-cluster",
				},
			},
			rs: &psmdbv1.ReplsetSpec{
				Name: "rs0",
			},
			component: "mongod",
			expected:  "my-cluster-rs0-mongod-hookscript",
		},
		"mixed case cr name - should be lowercased": {
			cr: &psmdbv1.PerconaServerMongoDB{
				ObjectMeta: metav1.ObjectMeta{
					Name: "My-Cluster",
				},
			},
			rs:        nil,
			component: "MONGOS",
			expected:  "my-cluster-mongos-hookscript",
		},
		"mixed case with rs - should be lowercased": {
			cr: &psmdbv1.PerconaServerMongoDB{
				ObjectMeta: metav1.ObjectMeta{
					Name: "My-Cluster",
				},
			},
			rs: &psmdbv1.ReplsetSpec{
				Name: "RS0",
			},
			component: "NonVoting",
			expected:  "my-cluster-rs0-nonvoting-hookscript",
		},
	}

	for name, tt := range tests {
		t.Run(name, func(t *testing.T) {
			got := HookScriptConfigMapName(tt.cr, tt.rs, tt.component)
			assert.Equal(t, tt.expected, got)
		})
	}
}

@JNKPercona
Copy link
Collaborator

Test Name Result Time
arbiter passed 00:00:00
balancer passed 00:00:00
cross-site-sharded passed 00:00:00
custom-replset-name passed 00:00:00
custom-tls passed 00:00:00
custom-users-roles passed 00:00:00
custom-users-roles-sharded passed 00:00:00
data-at-rest-encryption passed 00:00:00
data-sharded passed 00:00:00
demand-backup passed 00:00:00
demand-backup-eks-credentials-irsa passed 00:00:00
demand-backup-fs passed 00:00:00
demand-backup-if-unhealthy passed 00:00:00
demand-backup-incremental passed 00:47:07
demand-backup-incremental-sharded passed 00:00:00
demand-backup-physical-parallel passed 00:00:00
demand-backup-physical-aws passed 00:00:00
demand-backup-physical-azure passed 00:00:00
demand-backup-physical-gcp-s3 passed 00:00:00
demand-backup-physical-gcp-native passed 00:00:00
demand-backup-physical-minio passed 00:00:00
demand-backup-physical-minio-native passed 00:00:00
demand-backup-physical-sharded-parallel passed 00:00:00
demand-backup-physical-sharded-aws passed 00:00:00
demand-backup-physical-sharded-azure passed 00:00:00
demand-backup-physical-sharded-gcp-native passed 00:00:00
demand-backup-physical-sharded-minio passed 00:00:00
demand-backup-physical-sharded-minio-native passed 00:00:00
demand-backup-sharded passed 00:00:00
disabled-auth passed 00:00:00
expose-sharded passed 00:00:00
finalizer passed 00:00:00
ignore-labels-annotations passed 00:00:00
init-deploy passed 00:00:00
ldap passed 00:00:00
ldap-tls passed 00:00:00
limits passed 00:00:00
liveness passed 00:00:00
mongod-major-upgrade passed 00:00:00
mongod-major-upgrade-sharded passed 00:00:00
monitoring-2-0 passed 00:00:00
monitoring-pmm3 passed 00:00:00
multi-cluster-service passed 00:00:00
multi-storage passed 00:00:00
non-voting-and-hidden passed 00:00:00
one-pod passed 00:00:00
operator-self-healing-chaos passed 00:00:00
pitr passed 00:00:00
pitr-physical passed 00:00:00
pitr-sharded passed 00:00:00
pitr-to-new-cluster passed 00:00:00
pitr-physical-backup-source passed 00:00:00
preinit-updates passed 00:00:00
pvc-resize passed 00:00:00
recover-no-primary passed 00:00:00
replset-overrides passed 00:00:00
replset-remapping passed 00:00:00
replset-remapping-sharded passed 00:00:00
rs-shard-migration passed 00:00:00
scaling passed 00:00:00
scheduled-backup passed 00:00:00
security-context passed 00:00:00
self-healing-chaos passed 00:00:00
service-per-pod passed 00:00:00
serviceless-external-nodes passed 00:00:00
smart-update passed 00:00:00
split-horizon passed 00:00:00
stable-resource-version passed 00:00:00
storage passed 00:00:00
tls-issue-cert-manager passed 00:00:00
unsafe-psa passed 00:00:00
upgrade passed 00:00:00
upgrade-consistency passed 00:00:00
upgrade-consistency-sharded-tls passed 00:00:00
upgrade-sharded passed 00:00:00
upgrade-partial-backup passed 00:00:00
users passed 00:00:00
users-vault passed 00:00:00
version-service passed 00:00:00
Summary Value
Tests Run 79/79
Job Duration 01:11:07
Total Test Time 00:47:07

commit: 9fe54ad
image: perconalab/percona-server-mongodb-operator:PR-2200-9fe54ad7

@hors hors merged commit a19ab94 into main Jan 16, 2026
13 checks passed
@hors hors deleted the K8SPSMDB-1531-fix branch January 16, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS 0-9 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants