Resets secrets lister in RFC2136 conformance tests

The way the tests run (a new kube apiserver with a different client created for the same initialized solver) is not how this solver would actually run

Signed-off-by: irbekrm <irbekrm@gmail.com>
This commit is contained in:
irbekrm 2023-01-18 17:43:34 +00:00
parent 216b60e98b
commit 644a46c8fe
3 changed files with 11 additions and 31 deletions

View File

@ -24,12 +24,10 @@ import (
"time"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"github.com/cert-manager/cert-manager/pkg/acme/webhook"
"github.com/cert-manager/cert-manager/pkg/issuer/acme/dns/rfc2136"
"github.com/cert-manager/cert-manager/test/internal/apiserver"
)
@ -44,9 +42,7 @@ func init() {
type fixture struct {
// testSolver is the actual DNS solver that is under test.
// It is set when calling the NewFixture function.
testSolver webhook.Solver
testSolverType string
testSolver webhook.Solver
resolvedFQDN string
resolvedZone string
allowAmbientCredentials bool
@ -126,27 +122,7 @@ func (f *fixture) setup(t *testing.T) func() {
stopCh := make(chan struct{})
var testSolver webhook.Solver
switch f.testSolverType {
case rfc2136.SolverName:
cl, err := kubernetes.NewForConfig(env.Config)
if err != nil {
t.Errorf("error initializing solver: %#+v", err)
}
// obtain a secret lister and start the informer factory to populate the
// secret cache
factory := informers.NewSharedInformerFactoryWithOptions(cl, time.Minute*5)
secretLister := factory.Core().V1().Secrets().Lister()
factory.Start(stopCh)
factory.WaitForCacheSync(stopCh)
testSolver = rfc2136.New(rfc2136.WithSecretsLister(secretLister))
f.testSolver = testSolver
default:
t.Errorf("unknown solver type: %s", f.testSolverType)
}
testSolver.Initialize(env.Config, stopCh)
f.testSolver.Initialize(env.Config, stopCh)
return func() {
close(stopCh)

View File

@ -23,6 +23,7 @@ import (
"strings"
"time"
"github.com/cert-manager/cert-manager/pkg/acme/webhook"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
)
@ -30,10 +31,13 @@ import (
type Option func(*fixture)
// NewFixture constructs a new *fixture, applying the given Options before
// returning.
func NewFixture(solverType string, opts ...Option) *fixture {
// returning. Solver is an implementation of
// https://github.com/cert-manager/cert-manager/blob/v1.11.0/pkg/acme/webhook/webhook.go#L27-L45
// and could be RFC2136 solver or any of external solvers that run these
// conformance tests.
func NewFixture(solver webhook.Solver, opts ...Option) *fixture {
f := &fixture{
testSolverType: solverType,
testSolver: solver,
}
for _, o := range opts {
o(f)

View File

@ -59,7 +59,7 @@ func TestRunSuiteWithTSIG(t *testing.T) {
TSIGKeyName: rfc2136TestTsigKeyName,
}
fixture := dns.NewFixture(rfc2136.SolverName,
fixture := dns.NewFixture(rfc2136.New(rfc2136.InitializeResetLister()),
dns.SetResolvedZone(rfc2136TestZone),
dns.SetResolvedFQDN(rfc2136TestFqdn),
dns.SetAllowAmbientCredentials(false),
@ -91,7 +91,7 @@ func TestRunSuiteNoTSIG(t *testing.T) {
Nameserver: server.ListenAddr(),
}
fixture := dns.NewFixture(rfc2136.SolverName,
fixture := dns.NewFixture(rfc2136.New(rfc2136.InitializeResetLister()),
dns.SetResolvedZone(rfc2136TestZone),
dns.SetResolvedFQDN(rfc2136TestFqdn),
dns.SetAllowAmbientCredentials(false),