Skip to content

Commit 1885342

Browse files
committed
address review feedback
Signed-off-by: James Munnelly <[email protected]>
1 parent 6b92c3b commit 1885342

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

manager/manager.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ func NewManager(opts Options) (*Manager, error) {
206206
// added the entry to the map instead, and only purged items from the map that are older that N duration (TBD).
207207
janitorLogger := opts.Log.WithName("pending_request_janitor")
208208
go wait.Until(func() {
209+
requestToPrivateKeyLock.Lock()
210+
defer requestToPrivateKeyLock.Unlock()
209211
reqs, err := lister.List(labels.Everything())
210212
if err != nil {
211213
janitorLogger.Error(err, "failed listing existing requests")
@@ -217,8 +219,6 @@ func NewManager(opts Options) (*Manager, error) {
217219
existsMap[req.UID] = struct{}{}
218220
}
219221

220-
requestToPrivateKeyLock.Lock()
221-
defer requestToPrivateKeyLock.Unlock()
222222
for uid := range requestToPrivateKeyMap {
223223
if _, ok := existsMap[uid]; !ok {
224224
// purge the item from the map as it does not exist in the apiserver
@@ -231,9 +231,11 @@ func NewManager(opts Options) (*Manager, error) {
231231
informerFactory.WaitForCacheSync(stopCh)
232232

233233
m := &Manager{
234-
client: opts.Client,
235-
clientForMetadata: opts.ClientForMetadata,
236-
lister: lister,
234+
client: opts.Client,
235+
clientForMetadata: opts.ClientForMetadata,
236+
lister: lister,
237+
// we pass a pointer to the mutex as the janitor routine above also uses this lock,
238+
// so we want to avoid making a copy of it
237239
requestToPrivateKeyLock: &requestToPrivateKeyLock,
238240
requestToPrivateKeyMap: requestToPrivateKeyMap,
239241
metadataReader: opts.MetadataReader,

test/integration/resume_request_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"crypto"
2222
"crypto/x509"
23-
"os"
2423
"reflect"
2524
"testing"
2625
"time"
@@ -38,7 +37,14 @@ import (
3837
testutil "github.com/cert-manager/csi-lib/test/util"
3938
)
4039

41-
func testResumesExistingRequest(t *testing.T, issueBeforeCall bool) {
40+
type WhenToCallIssue bool
41+
42+
const (
43+
CallIssueDuringPublish = false
44+
CallIssueBetweenPublish = true
45+
)
46+
47+
func testResumesExistingRequest(t *testing.T, issueBeforeCall WhenToCallIssue) {
4248
store := storage.NewMemoryFS()
4349
ns := "certificaterequest-namespace"
4450
clock := fakeclock.NewFakeClock(time.Now())
@@ -66,13 +72,9 @@ func testResumesExistingRequest(t *testing.T, issueBeforeCall bool) {
6672
return store.WriteMetadata(meta.VolumeID, meta)
6773
},
6874
})
69-
defer stop()
75+
t.Cleanup(stop)
7076

71-
tmpDir, err := os.MkdirTemp("", "*")
72-
if err != nil {
73-
t.Fatal(err)
74-
}
75-
defer os.RemoveAll(tmpDir)
77+
tmpDir := t.TempDir()
7678

7779
// create a root, non-expiring context
7880
ctx := context.Background()
@@ -91,8 +93,8 @@ func testResumesExistingRequest(t *testing.T, issueBeforeCall bool) {
9193

9294
// create a context that expires in 2s (enough time for at least a single call of `issue`)
9395
twoSecondCtx, cancel := context.WithTimeout(ctx, time.Second*2)
94-
defer cancel()
95-
_, err = cl.NodePublishVolume(twoSecondCtx, nodePublishVolumeRequest)
96+
t.Cleanup(cancel)
97+
_, err := cl.NodePublishVolume(twoSecondCtx, nodePublishVolumeRequest)
9698
// assert that an error has been returned - we don't mind what kind of error, as due to the async nature of
9799
// de-registering metadata from the metadata store upon failures, there is a slim chance that a metadata read error
98100
// can be returned instead of a deadline exceeded error.
@@ -155,11 +157,11 @@ func testResumesExistingRequest(t *testing.T, issueBeforeCall bool) {
155157
}
156158

157159
func TestResumesExistingRequest_IssuedBetweenPublishCalls(t *testing.T) {
158-
testResumesExistingRequest(t, true)
160+
testResumesExistingRequest(t, CallIssueBetweenPublish)
159161
}
160162

161163
func TestResumesExistingRequest_IssuedDuringPublishCall(t *testing.T) {
162-
testResumesExistingRequest(t, false)
164+
testResumesExistingRequest(t, CallIssueDuringPublish)
163165
}
164166

165167
// ensureOneRequestExists will fail the test if more than a single CertificateRequest exists.

0 commit comments

Comments
 (0)