@@ -26,7 +26,6 @@ import (
26
26
"github.com/go-logr/logr"
27
27
"google.golang.org/grpc/codes"
28
28
"google.golang.org/grpc/status"
29
- "k8s.io/apimachinery/pkg/util/wait"
30
29
"k8s.io/mount-utils"
31
30
32
31
"github.com/cert-manager/csi-lib/manager"
@@ -48,8 +47,8 @@ type nodeServer struct {
48
47
func (ns * nodeServer ) NodePublishVolume (ctx context.Context , req * csi.NodePublishVolumeRequest ) (* csi.NodePublishVolumeResponse , error ) {
49
48
meta := metadata .FromNodePublishVolumeRequest (req )
50
49
log := loggerForMetadata (ns .log , meta )
51
- ctx , _ = context .WithTimeout (ctx , time .Second * 30 )
52
-
50
+ ctx , cancel : = context .WithTimeout (ctx , time .Second * 60 )
51
+ defer cancel ()
53
52
// clean up after ourselves if provisioning fails.
54
53
// this is required because if publishing never succeeds, unpublish is not
55
54
// called which leaves files around (and we may continue to renew if so).
@@ -69,6 +68,14 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
69
68
return nil , status .Error (codes .InvalidArgument , "pod.spec.volumes[].csi.readOnly must be set to 'true'" )
70
69
}
71
70
71
+ // If continueOnNotReady is enabled, set the NextIssuanceTime in the metadata file to epoch.
72
+ // This allows the manager to start management for the volume again on restart if the first
73
+ // issuance did not successfully complete.
74
+ if meta .NextIssuanceTime == nil && ns .continueOnNotReady {
75
+ epoch := time.Time {}
76
+ meta .NextIssuanceTime = & epoch
77
+ }
78
+
72
79
if registered , err := ns .store .RegisterMetadata (meta ); err != nil {
73
80
return nil , err
74
81
} else {
@@ -79,32 +86,31 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
79
86
}
80
87
}
81
88
82
- if err := ns .manager .ManageVolume (req .GetVolumeId ()); err != nil {
83
- return nil , err
84
- }
85
-
86
- log .Info ("Volume registered for management" )
87
-
88
- // Only wait for the volume to be ready if it is in a state of 'ready to request'
89
- // already. This allows implementors to defer actually requesting certificates
90
- // until later in the pod lifecycle (e.g. after CNI has run & an IP address has been
91
- // allocated, if a user wants to embed pod IPs into their requests).
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
- }
96
- if isReadyToRequest || ! ns .continueOnNotReady {
97
- log .Info ("Waiting for certificate to be issued..." )
98
- if err := wait .PollUntil (time .Second , func () (done bool , err error ) {
99
- return ns .manager .IsVolumeReady (req .GetVolumeId ()), nil
100
- }, ctx .Done ()); err != nil {
101
- return nil , err
89
+ if ! ns .manager .IsVolumeReady (req .GetVolumeId ()) {
90
+ // Only wait for the volume to be ready if it is in a state of 'ready to request'
91
+ // already. This allows implementors to defer actually requesting certificates
92
+ // until later in the pod lifecycle (e.g. after CNI has run & an IP address has been
93
+ // allocated, if a user wants to embed pod IPs into their requests).
94
+ isReadyToRequest , reason := ns .manager .IsVolumeReadyToRequest (req .GetVolumeId ())
95
+ if isReadyToRequest {
96
+ log .V (4 ).Info ("Waiting for certificate to be issued..." )
97
+ if _ , err := ns .manager .ManageVolumeImmediate (ctx , req .GetVolumeId ()); err != nil {
98
+ return nil , err
99
+ }
100
+ log .Info ("Volume registered for management" )
101
+ } else {
102
+ if ns .continueOnNotReady {
103
+ log .V (4 ).Info ("Skipping waiting for certificate to be issued" )
104
+ ns .manager .ManageVolume (req .GetVolumeId ())
105
+ log .V (4 ).Info ("Volume registered for management" )
106
+ } else {
107
+ log .Info ("Unable to request a certificate right now, will be retried" , "reason" , reason )
108
+ return nil , fmt .Errorf ("volume is not yet ready to be setup, will be retried: %s" , reason )
109
+ }
102
110
}
103
- } else {
104
- log .Info ("Skipping waiting for certificate to be issued" )
105
111
}
106
112
107
- log .Info ("Volume ready for mounting " )
113
+ log .Info ("Ensuring data directory for volume is mounted into pod... " )
108
114
notMnt , err := mount .IsNotMountPoint (ns .mounter , req .GetTargetPath ())
109
115
switch {
110
116
case os .IsNotExist (err ):
@@ -118,11 +124,12 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
118
124
119
125
if ! notMnt {
120
126
// Nothing more to do if the targetPath is already a bind mount
127
+ log .Info ("Volume already mounted to pod, nothing to do" )
121
128
success = true
122
129
return & csi.NodePublishVolumeResponse {}, nil
123
130
}
124
131
125
- log .Info ("Bind mounting data directory to the targetPath " )
132
+ log .Info ("Bind mounting data directory to the pod's mount namespace " )
126
133
// bind mount the targetPath to the data directory
127
134
if err := ns .mounter .Mount (ns .store .PathForVolume (req .GetVolumeId ()), req .GetTargetPath (), "" , []string {"bind" , "ro" }); err != nil {
128
135
return nil , err
0 commit comments