Skip to content

Commit 17d9d81

Browse files
Merge pull request #7342 from cert-manager-bot/cherry-pick-7339-to-release-1.16
[release-1.16] BUGFIX: use correct resource namespace for Cluster Issuers
2 parents 67c897d + 1144aab commit 17d9d81

File tree

4 files changed

+151
-29
lines changed

4 files changed

+151
-29
lines changed

pkg/controller/helper.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ func (o IssuerOptions) ResourceNamespace(iss cmapi.GenericIssuer) string {
3131
return ns
3232
}
3333

34+
// ResourceNamespaceRef returns the Kubernetes namespace where resources
35+
// created or read by the referenced issuer are located.
36+
// This function is identical to CanUseAmbientCredentials, but takes a reference to
37+
// the issuer instead of the issuer itself (which means we don't need to fetch the
38+
// issuer from the API server).
39+
func (o IssuerOptions) ResourceNamespaceRef(ref cmmeta.ObjectReference, challengeNamespace string) string {
40+
switch ref.Kind {
41+
case cmapi.ClusterIssuerKind:
42+
return o.ClusterResourceNamespace
43+
case "", cmapi.IssuerKind:
44+
return challengeNamespace
45+
}
46+
return challengeNamespace // Should not be reached
47+
}
48+
3449
// CanUseAmbientCredentials returns whether `iss` will attempt to configure itself
3550
// from ambient credentials (e.g. from a cloud metadata service).
3651
func (o IssuerOptions) CanUseAmbientCredentials(iss cmapi.GenericIssuer) bool {

pkg/controller/test/context_builder.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ const informerResyncPeriod = time.Second
114114
// for any unset fields.
115115
func (b *Builder) Init() {
116116
if b.Context == nil {
117-
b.Context = &controller.Context{
118-
RootContext: context.Background(),
119-
}
117+
b.Context = &controller.Context{}
118+
}
119+
if b.Context.RootContext == nil {
120+
b.Context.RootContext = context.Background()
120121
}
121122
if b.StringGenerator == nil {
122123
b.StringGenerator = rand.String

pkg/issuer/acme/dns/dns.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (s *Solver) solverForChallenge(ctx context.Context, ch *cmacme.Challenge) (
181181
log := logf.FromContext(ctx, "solverForChallenge")
182182
dbg := log.V(logf.DebugLevel)
183183

184-
resourceNamespace := ch.Namespace
184+
resourceNamespace := s.ResourceNamespaceRef(ch.Spec.IssuerRef, ch.Namespace)
185185
canUseAmbientCredentials := s.CanUseAmbientCredentialsFromRef(ch.Spec.IssuerRef)
186186

187187
providerConfig, err := extractChallengeSolverConfig(ch)
@@ -460,7 +460,7 @@ func (s *Solver) prepareChallengeRequest(ctx context.Context, ch *cmacme.Challen
460460
return nil, nil, err
461461
}
462462

463-
resourceNamespace := ch.Namespace
463+
resourceNamespace := s.ResourceNamespaceRef(ch.Spec.IssuerRef, ch.Namespace)
464464
canUseAmbientCredentials := s.CanUseAmbientCredentialsFromRef(ch.Spec.IssuerRef)
465465

466466
// construct a ChallengeRequest which can be passed to DNS solvers.

0 commit comments

Comments
 (0)