Skip to content

Commit 4ec29c9

Browse files
committed
Add reason text to ReadyToRequest function
Signed-off-by: James Munnelly <[email protected]>
1 parent 16fe316 commit 4ec29c9

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

driver/nodeserver.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,19 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
8989
// already. This allows implementors to defer actually requesting certificates
9090
// until later in the pod lifecycle (e.g. after CNI has run & an IP address has been
9191
// allocated, if a user wants to embed pod IPs into their requests).
92-
isReadyToRequest := ns.manager.IsVolumeReadyToRequest(req.GetVolumeId())
92+
isReadyToRequest, reason := ns.manager.IsVolumeReadyToRequest(req.GetVolumeId())
93+
if !isReadyToRequest {
94+
log.Info("Unable to request a certificate right now, will be retried", "reason", reason)
95+
}
9396
if isReadyToRequest || !ns.continueOnNotReady {
97+
log.Info("Waiting for certificate to be issued...")
9498
if err := wait.PollUntil(time.Second, func() (done bool, err error) {
9599
return ns.manager.IsVolumeReady(req.GetVolumeId()), nil
96100
}, ctx.Done()); err != nil {
97101
return nil, err
98102
}
103+
} else {
104+
log.Info("Skipping waiting for certificate to be issued")
99105
}
100106

101107
log.Info("Volume ready for mounting")

manager/interfaces.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ type ClientForMetadataFunc func(meta metadata.Metadata) (cmclient.Interface, err
9595
// This can be used to 'defer' fetching until later pod initialization events have
9696
// happened (e.g. CNI has allocated an IP if you want to embed a pod IP into the certificate
9797
// request resources).
98-
type ReadyToRequestFunc func(meta metadata.Metadata) bool
98+
type ReadyToRequestFunc func(meta metadata.Metadata) (bool, string)
9999

100-
func AlwaysReadyToRequest(_ metadata.Metadata) bool {
101-
return true
100+
func AlwaysReadyToRequest(_ metadata.Metadata) (bool, string) {
101+
return true, ""
102102
}

manager/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ func (m *Manager) issue(volumeID string) error {
258258
}
259259
log.V(2).Info("Read metadata", "metadata", meta)
260260

261-
if !m.readyToRequest(meta) {
262-
return fmt.Errorf("driver is not ready to request a certificate for this volume")
261+
if ready, reason := m.readyToRequest(meta); !ready {
262+
return fmt.Errorf("driver is not ready to request a certificate for this volume: %v", reason)
263263
}
264264

265265
key, err := m.generatePrivateKey(meta)
@@ -536,11 +536,11 @@ func (m *Manager) UnmanageVolume(volumeID string) {
536536
}
537537
}
538538

539-
func (m *Manager) IsVolumeReadyToRequest(volumeID string) bool {
539+
func (m *Manager) IsVolumeReadyToRequest(volumeID string) (bool, string) {
540540
meta, err := m.metadataReader.ReadMetadata(volumeID)
541541
if err != nil {
542542
m.log.Error(err, "failed to read metadata", "volume_id", volumeID)
543-
return false
543+
return false, ""
544544
}
545545

546546
return m.readyToRequest(meta)

test/integration/ready_to_request_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
testutil "github.com/cert-manager/csi-lib/test/util"
4040
)
4141

42-
func TestCompletesIfNotReadyToRequest(t *testing.T) {
42+
func Test_CompletesIfNotReadyToRequest_ContinueOnNotReadyEnabled(t *testing.T) {
4343
store := storage.NewMemoryFS()
4444
clock := fakeclock.NewFakeClock(time.Now())
4545

@@ -48,13 +48,13 @@ func TestCompletesIfNotReadyToRequest(t *testing.T) {
4848
Store: store,
4949
Clock: clock,
5050
ContinueOnNotReady: true,
51-
ReadyToRequest: func(meta metadata.Metadata) bool {
51+
ReadyToRequest: func(meta metadata.Metadata) (bool, string) {
5252
if calls < 1 {
5353
calls++
54-
return false
54+
return false, "calls < 1"
5555
}
5656
// only indicate we are ready after issuance has been attempted 1 time
57-
return calls == 1
57+
return calls == 1, "calls == 1"
5858
},
5959
GeneratePrivateKey: func(meta metadata.Metadata) (crypto.PrivateKey, error) {
6060
return nil, nil
@@ -133,8 +133,8 @@ func TestFailsIfNotReadyToRequest_ContinueOnNotReadyDisabled(t *testing.T) {
133133
Store: store,
134134
Clock: clock,
135135
ContinueOnNotReady: false,
136-
ReadyToRequest: func(meta metadata.Metadata) bool {
137-
return false
136+
ReadyToRequest: func(meta metadata.Metadata) (bool, string) {
137+
return false, "never ready"
138138
},
139139
GeneratePrivateKey: func(meta metadata.Metadata) (crypto.PrivateKey, error) {
140140
return nil, nil

0 commit comments

Comments
 (0)