Skip to content

K8SPSMDB-1413: add ClusterIssuer support#2225

Open
pooknull wants to merge 10 commits intomainfrom
K8SPSMDB-1413
Open

K8SPSMDB-1413: add ClusterIssuer support#2225
pooknull wants to merge 10 commits intomainfrom
K8SPSMDB-1413

Conversation

@pooknull
Copy link
Contributor

@pooknull pooknull commented Feb 2, 2026

Due to the high volume of requests, we're unable to provide free service for this account. To continue using the service, please upgarde to a paid plan.

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

DESCRIPTION

Problem:
The operator fails to deploy the cluster when ClusterIssuer is specified in .spec.tls.issuerConf.kind.

Cause:
The operator does not support ClusterIssuer. It only works with Issuer.

Solution:
To add support for ClusterIssuer, the operator must know the namespace in which cert-manager is deployed. This is usually the cert-manager namespace, but it must be explicitly provided via the CERTMANAGER_NAMESPACE env var in operator.yaml.

The CA certificate must be created in this namespace, because other ClusterIssuer resources expect the CA secret to exist in the cert-manager namespace.

If a user wants to use an existing ClusterIssuer, they should set .spec.tls.issuerConf.kind: ClusterIssuer. When the operator creates resources in the cert-manager namespace, it must not set owner references, as cross-namespace owner references are forbidden in Kubernetes.

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 February 2, 2026 15:27
@pull-request-size pull-request-size bot added the size/XXL 1000+ lines label Feb 2, 2026
@github-actions github-actions bot added the tests label Feb 2, 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 pull request adds support for ClusterIssuer (cluster-scoped cert-manager issuers) in addition to the existing Issuer (namespace-scoped) support for TLS certificate management in the Percona Server MongoDB Operator.

Changes:

  • Introduced new IssuerConfReference type to replace the cert-manager ObjectReference dependency, allowing specification of issuer name, kind, and group
  • Modified cert-manager integration to create both Issuer and ClusterIssuer resources based on configuration
  • Updated CA certificate placement to use cert-manager namespace when using ClusterIssuer (version >= 1.22.0)
  • Added comprehensive E2E tests for ClusterIssuer functionality
  • Updated RBAC permissions to include ClusterIssuer resources
  • Added CERTMANAGER_NAMESPACE environment variable configuration

Reviewed changes

Copilot reviewed 46 out of 46 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
pkg/apis/psmdb/v1/psmdb_types.go Defines new IssuerConfReference type with name, kind, and group fields
pkg/apis/psmdb/v1/psmdb_defaults.go Sets default values for IssuerConf (kind=Issuer, group=cert-manager.io)
pkg/apis/psmdb/v1/zz_generated.deepcopy.go Auto-generated deepcopy methods for IssuerConfReference
pkg/psmdb/tls/certmanager.go Core logic for creating Issuer/ClusterIssuer resources, removed deprecated issuer cleanup
pkg/psmdb/tls/certificate.go Certificate generation with namespace handling for ClusterIssuer CA certs
pkg/psmdb/tls/tls.go Enhanced issuer detection to support ClusterIssuer kind
pkg/psmdb/tls/certmanager_test.go Updated tests to use new IssuerConfReference type
pkg/controller/perconaservermongodb/ssl.go Simplified certificate application logic, removed deprecated code
deploy/rbac.yaml, deploy/cw-rbac.yaml Added ClusterIssuer permissions
deploy/operator.yaml Added CERTMANAGER_NAMESPACE environment variable
deploy/crd.yaml, deploy/cw-bundle.yaml, deploy/bundle.yaml Removed 'required' constraint on issuerConf.name field
deploy/cr.yaml Example configuration with ClusterIssuer
e2e-tests/tls-clusterissue-cert-manager/* New E2E test suite for ClusterIssuer functionality
e2e-tests/run-*.csv Added new test to test suites
e2e-tests/functions Added cleanup of ClusterIssuer/Certificate resources before cert-manager deployment
config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml CRD update for issuerConf changes
Comments suppressed due to low confidence (2)

pkg/psmdb/tls/tls.go:62

  • When fetching a ClusterIssuer, the code uses types.NamespacedName with secret.Namespace. ClusterIssuers are cluster-scoped resources and don't have a namespace. The Get call should use types.NamespacedName{Name: issuerName} without specifying a Namespace for ClusterIssuer resources. This will cause the Get operation to fail for ClusterIssuer.
    pkg/psmdb/tls/certmanager_test.go:93
  • The unit tests do not cover the ClusterIssuer scenario at all. They only test regular Issuer functionality. Tests should be added for: 1) Creating a ClusterIssuer (verifying no namespace is set), 2) Creating certificates with ClusterIssuer references, 3) CA certificate creation in the cert-manager namespace when using ClusterIssuer, 4) Verifying the issuer names include namespace suffix when using ClusterIssuer.

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

Copy link
Contributor

@gkech gkech left a comment

Choose a reason for hiding this comment

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

leaving some initial comments while continuing the review

fi
}

# TODO: The problem is about using ClusterIssuer.
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 this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return c.cr.Name + "-ca-cert"
}

func (c *caCert) Namespace() string {
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 have a unit test for this function. Mainly because the logic with the if-clause and the default behaviour have some interest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

labels = nil
}

issuerKind := cm.IssuerKind
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 have also a unit test for object. Since I guess we will have to create a pkg/psmdb/tls/certificate_test.go file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

func certManagerNamespace() string {
ns := os.Getenv("CERTMANAGER_NAMESPACE")
if ns == "" {
return "cert-manager"
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the namespace that is always the default for cert-manager when you dont specify it in its deployment? Because on our e2e test we have a command to create the namespace when deploying cert manager

kubectl_bin create namespace cert-manager || :

But i'm not sure if this should be our default one.

Copy link
Contributor

Choose a reason for hiding this comment

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

cert-manager docs use this namespace too:

  1. https://cert-manager.io/docs/installation/kubectl/
  2. https://cert-manager.io/docs/installation/helm/
  3. cert-manager's official cli cmctl also uses cert-manager as default namespace: https://github.com/cert-manager/cmctl/blob/b57ea82800da4e655c1a54fdf8c0f3714746bdfe/pkg/install/helm/settings.go#L33

if we need a default, imo this is the proper one

Copilot AI review requested due to automatic review settings February 4, 2026 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 46 out of 46 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (1)

pkg/psmdb/tls/certmanager_test.go:73

  • Missing unit test coverage for ClusterIssuer functionality. The test file has been modified but no new tests have been added to cover the ClusterIssuer code path. Given that this PR adds support for ClusterIssuer (a major new feature), unit tests should be added to verify that ClusterIssuer objects are created correctly, have the correct namespace handling (empty namespace for cluster-scoped resources), and that issuer names are correctly namespaced.

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

@hors hors marked this pull request as ready for review February 9, 2026 09:16
@egegunes egegunes added this to the v1.23.0 milestone Feb 10, 2026
deploy/cr.yaml Outdated
Comment on lines 31 to 33
issuerConf:
name: special-selfsigned-issuer
kind: ClusterIssuer
Copy link
Contributor

Choose a reason for hiding this comment

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

please revert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rs-shard-migration
scaling
split-horizon
tls-clusterissue-cert-manager
Copy link
Contributor

Choose a reason for hiding this comment

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

please fix the typo in the name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

func certManagerNamespace() string {
ns := os.Getenv("CERTMANAGER_NAMESPACE")
if ns == "" {
return "cert-manager"
Copy link
Contributor

Choose a reason for hiding this comment

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

cert-manager docs use this namespace too:

  1. https://cert-manager.io/docs/installation/kubectl/
  2. https://cert-manager.io/docs/installation/helm/
  3. cert-manager's official cli cmctl also uses cert-manager as default namespace: https://github.com/cert-manager/cmctl/blob/b57ea82800da4e655c1a54fdf8c0f3714746bdfe/pkg/install/helm/settings.go#L33

if we need a default, imo this is the proper one

Copilot AI review requested due to automatic review settings February 10, 2026 11:20
@pooknull pooknull requested review from egegunes and gkech February 10, 2026 11:24
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 46 out of 46 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (2)

pkg/psmdb/tls/tls.go:62

  • When the secret was issued by a ClusterIssuer, this Get call uses secret.Namespace, but ClusterIssuer is cluster-scoped and must be fetched with an empty namespace. As written, the lookup will always fail (NotFound), causing the secret to be treated as user-created even when it isn’t.
    pkg/psmdb/tls/tls.go:71
  • isCertManagerSecretCreatedByUser determines operator-ownership by checking whether the Issuer/ClusterIssuer is controlled by the CR. For ClusterIssuer this will never be true (cluster-scoped resources can’t be owned by a namespaced CR), so cert-manager-managed secrets will be misclassified as user-created and the operator may stop reconciling TLS/internal TLS secrets. Consider instead checking whether the referenced Certificate (via cert-manager.io/certificate-name annotation) is controlled by the CR.

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

commit: 9afc535
image: perconalab/percona-server-mongodb-operator:PR-2225-9afc535d

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.

4 participants