Skip to content

K8SPG-951: [WIP] add spec.issuerConf#1684

Draft
mayankshah1607 wants to merge 2 commits into
mainfrom
K8SPG-951-issuer-conf
Draft

K8SPG-951: [WIP] add spec.issuerConf#1684
mayankshah1607 wants to merge 2 commits into
mainfrom
K8SPG-951-issuer-conf

Conversation

@mayankshah1607

Copy link
Copy Markdown
Member

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?

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 PG 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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds spec.tls.issuerConf to the PostgresCluster API to support multiple cert-manager issuer modes (managed namespaced Issuer, managed cluster-scoped ClusterIssuer, and external/third-party issuers), and updates reconciliation logic so leaf certificates can reference the resolved issuerRef. The PR also adjusts controller-runtime client caching to allow direct API-server Get on ClusterIssuers without requiring cluster-wide list/watch RBAC, and adds tests covering the new behaviors.

Changes:

  • Introduce spec.tls.issuerConf (CRD + Go types + deepcopy) to configure issuer references.
  • Implement issuer-mode resolution and apply logic for Issuer/ClusterIssuer/external issuers, plus CA handling fallbacks for external issuers.
  • Disable controller-runtime cache for cert-manager.io/v1 ClusterIssuer and add/extend unit tests.

Reviewed changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pkg/apis/upstream.pgv2.percona.com/v1beta1/zz_generated.deepcopy.go Deepcopy updates for the new TLSSpec.IssuerConf field.
pkg/apis/upstream.pgv2.percona.com/v1beta1/postgrescluster_types.go Adds TLSSpec.IssuerConf to the API type.
percona/runtime/runtime.go Disables informer cache for ClusterIssuer via ClientCacheOptions() and applies it to managers.
percona/runtime/runtime_test.go Adds tests around cache options / manager creation.
percona/certmanager/certmanager.go Implements issuer modes, issuerRef resolution, and managed/external behaviors across Apply* methods.
percona/certmanager/certmanager_test.go Adds/extends tests for issuer modes, namespace resolution, drift updates, and external issuer behavior.
internal/naming/names.go Adds naming helpers for cluster-scoped CA issuer/secret.
internal/naming/names_test.go Tests for the new naming helpers.
internal/controller/postgrescluster/pki.go Makes PKI reconciliation issuer-mode aware, including managed-cluster secret locations and external mode handling.
internal/controller/postgrescluster/pki_test.go Adds issuer-mode awareness tests (with envtest/fake-client workarounds).
internal/controller/postgrescluster/pgbackrest.go Adds CA selection helper for pgBackRest when using external issuers (no operator root CA).
internal/controller/postgrescluster/pgbackrest_test.go Unit tests for pgBackRestCACert.
internal/controller/postgrescluster/instance.go Adds CA selection helper for instance cert embedding when using external issuers.
internal/controller/postgrescluster/instance_test.go Unit tests for instanceCACert.
internal/controller/postgrescluster/controller.go Ensures cert-manager watch registration logic runs even when rootCA is nil (external mode).
deploy/cw-bundle.yaml CRD schema update for spec.tls.issuerConf.
deploy/crd.yaml CRD schema update for spec.tls.issuerConf.
deploy/bundle.yaml CRD schema update for spec.tls.issuerConf.
config/crd/bases/upstream.pgv2.percona.com_postgresclusters.yaml Base CRD schema update for spec.tls.issuerConf.
config/crd/bases/pgv2.percona.com_perconapgclusters.yaml Base CRD schema update for spec.tls.issuerConf.
build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml Generated CRD schema update for spec.tls.issuerConf.
Files not reviewed (1)
  • pkg/apis/upstream.pgv2.percona.com/v1beta1/zz_generated.deepcopy.go: Generated file

Comment on lines +234 to +237
if mode == IssuerModeManagedCluster {
caSecretName := naming.ClusterCACertSecret(cluster, CertManagerNamespace()).Name
meta := metav1.ObjectMeta{Name: issuerRef(cluster, mode).Name}

Comment on lines +111 to +116
case v1.ClusterIssuerKind:
existing := &v1.ClusterIssuer{}
err := cl.Get(ctx, types.NamespacedName{Name: ic.Name}, existing)
switch {
case err == nil, k8serrors.IsNotFound(err):
return IssuerModeManagedCluster, nil
Comment on lines +145 to +146
case IssuerModeManagedCluster:
return cmmeta.IssuerReference{Name: issuerConf(cluster).Name, Kind: v1.ClusterIssuerKind}
Comment on lines +147 to +152
default:
name := naming.TLSIssuer(cluster).Name
if ic := issuerConf(cluster); ic != nil && ic.Name != "" {
name = ic.Name
}
return cmmeta.IssuerReference{Name: name, Kind: v1.IssuerKind}
Comment on lines +16 to +26
func TestCreateRuntimeManagerDisablesClusterIssuerCache(t *testing.T) {
t.Setenv("WATCH_NAMESPACE", "")

scheme := runtime.NewScheme()
_ = cmv1.AddToScheme(scheme)

opts := manager.Options{Scheme: scheme}
mgr, err := CreateRuntimeManager(&rest.Config{Host: "https://127.0.0.1:1"}, feature.NewGate(), opts)
require.NoError(t, err)
require.NotNil(t, mgr)
}
Comment on lines +234 to +236
// K8SPG-951
// +optional
IssuerConf *cmmeta.IssuerReference `json:"issuerConf,omitempty"`
@JNKPercona

Copy link
Copy Markdown
Collaborator
Test Name Result Time
backup-enable-disable failure 00:06:33
builtin-extensions failure 00:06:01
cert-manager-tls failure 00:06:54
custom-envs failure 00:05:34
custom-tls failure 00:05:23
database-init-sql failure 00:06:40
demand-backup failure 00:18:50
demand-backup-offline-snapshot failure 00:03:31
dynamic-configuration failure 00:03:24
finalizers failure 00:14:18
init-deploy failure 00:03:22
huge-pages failure 00:03:24
major-upgrade-14-to-15 failure 00:03:36
major-upgrade-15-to-16 failure 00:03:28
major-upgrade-16-to-17 failure 00:03:28
major-upgrade-17-to-18 failure 00:03:36
ldap failure 00:03:26
ldap-tls failure 00:05:28
monitoring failure 00:03:30
monitoring-pmm3 failure 00:03:23
one-pod failure 00:03:26
operator-self-healing failure 00:03:31
pitr failure 00:10:22
scaling failure 00:03:32
scheduled-backup failure 00:03:26
self-healing failure 00:03:30
sidecars failure 00:05:28
standby-pgbackrest failure 00:09:50
standby-streaming failure 00:03:32
start-from-backup failure 00:03:25
tablespaces failure 00:16:43
telemetry-transfer failure 00:05:39
upgrade-consistency failure 00:06:16
upgrade-minor failure 00:12:48
users failure 00:03:25
migration-from-crunchy-standby failure 00:17:31
migration-from-crunchy-pv failure 00:14:59
migration-from-crunchy-backup-restore failure 00:07:59
Summary Value
Tests Run 38/38
Job Duration 02:59:28
Total Test Time 04:09:29

commit: 187c2f8
image: perconalab/percona-postgresql-operator:PR-1684-187c2f8a6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants