10BC0 Merge pull request #7743 from wallrj/rotation-policy-default-always-2 · cert-manager/cert-manager@0b21f63 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b21f63

Browse files
Merge pull request #7743 from wallrj/rotation-policy-default-always-2
Avoid mutating the client-go informer cache
2 parents 5d593a1 + 2d28b29 commit 0b21f63

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

internal/apis/certmanager/v1/defaults.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
2828
return RegisterDefaults(scheme)
2929
}
3030

31-
// SetRuntimeDefaults_Certificate sets the default rotation policy to Always, or
32-
// Never if the DefaultPrivateKeyRotationPolicyAlways feature is disabled.
31+
// SetRuntimeDefaults_Certificate mutates the supplied Certificate object,
32+
// setting defaults for certain missing fields:
33+
// - Sets the default private key rotation policy to:
34+
// - Always, if the DefaultPrivateKeyRotationPolicyAlways feature is enabled
35+
// - Never, if the DefaultPrivateKeyRotationPolicyAlways feature is disabled.
36+
//
37+
// NOTE: Do not supply Certificate objects retrieved from a client-go lister
38+
// because you may corrupt the cache. Do a DeepCopy first. See:
39+
// https://pkg.go.dev/github.com/cert-manager/cert-manager@v1.17.2/pkg/client/listers/certmanager/v1#CertificateNamespaceLister
3340
//
3441
// NOTE: This is deliberately not called `SetObjectDefault_`, because that would
3542
// cause defaultergen to add this to the scheme default, which would be

pkg/controller/certificates/keymanager/keymanager_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ func (c *controller) ProcessItem(ctx context.Context, key types.NamespacedName)
157157

158158
// Apply runtime defaults to apply default values that are governed by
159159
// controller feature gates, such as DefaultPrivateKeyRotationPolicyAlways.
160+
// We deep copy the object to avoid mutating the client-go cache.
161+
crt = crt.DeepCopy()
160162
cminternal.SetRuntimeDefaults_Certificate(crt)
161163

162164
// Discover all 'owned' secrets that have the `next-private-key` label

0 commit comments

Comments
 (0)
0