Skip to content

Commit 0869112

Browse files
committed
[build][feat] add event handler
1 parent e8c46b1 commit 0869112

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/driver/controller.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,16 @@ func (s *controllerService) CreateVolume(pctx lctx.Context, preq *lcsi.CreateVol
169169
volumeSource := preq.GetVolumeContentSource()
170170
if volumeSource != nil {
171171
if _, ok := volumeSource.GetType().(*lcsi.VolumeContentSource_Snapshot); !ok {
172+
llog.ErrorS(nil, "[ERROR] - CreateVolume: VolumeContentSource not supported", "volumeID", volName)
173+
s.k8sClient.PersistentVolumeClaimEventWarning(pctx, cvr.PvcNamespaceTag, cvr.PvcNameTag,
174+
"CsiVolumeContentSourceNotSupported", "VolumeContentSource_Snapshot not supported")
172175
return nil, ErrVolumeContentSourceNotSupported
173176
}
174177
sourceSnapshot := volumeSource.GetSnapshot()
175178
if sourceSnapshot == nil {
179+
llog.ErrorS(nil, "[ERROR] - CreateVolume: Snapshot is nil within volumeContentSource", "volumeID", volName)
180+
s.k8sClient.PersistentVolumeClaimEventWarning(pctx, cvr.PvcNamespaceTag, cvr.PvcNameTag,
181+
"CsiSnapshotNotFound", "Snapshot is nil within volumeContentSource")
176182
return nil, ErrSnapshotIsNil
177183
}
178184
cvr = cvr.WithSnapshotID(sourceSnapshot.GetSnapshotId())
@@ -181,6 +187,8 @@ func (s *controllerService) CreateVolume(pctx lctx.Context, preq *lcsi.CreateVol
181187
respCtx, err := cvr.ToResponseContext(volCap)
182188
if err != nil {
183189
llog.ErrorS(err, "[ERROR] - CreateVolume: Failed to parse response context", "volumeID", volName)
190+
s.k8sClient.PersistentVolumeClaimEventWarning(pctx, cvr.PvcNamespaceTag, cvr.PvcNameTag,
191+
"CsiCreateVolumeRequestInvalid", err.Error())
184192
return nil, err
185193
}
186194

@@ -194,13 +202,17 @@ func (s *controllerService) CreateVolume(pctx lctx.Context, preq *lcsi.CreateVol
194202
pvc, ierr := s.k8sClient.GetPersistentVolumeClaimByName(pctx, cvr.PvcNamespaceTag, cvr.PvcNameTag)
195203
if ierr != nil {
196204
llog.ErrorS(ierr.GetError(), "[ERROR] - CreateVolume: Failed to get PVC", "pvcName", cvr.PvcNameTag, "pvcNamespace", cvr.PvcNamespaceTag)
205+
s.k8sClient.PersistentVolumeClaimEventWarning(pctx, cvr.PvcNamespaceTag, cvr.PvcNameTag,
206+
"CsiGetPersistentVolumeClaimFailure", ierr.GetMessage())
197207
return nil, ierr.GetError()
198208
}
199209

200210
// Get the StorageClass from the API server
201211
sc, ierr := s.k8sClient.GetStorageClassByName(pctx, pvc.GetStorageClassName())
202212
if ierr != nil {
203213
llog.ErrorS(ierr.GetError(), "[ERROR] - CreateVolume: Failed to get StorageClass", "storageClassName", pvc.GetStorageClassName())
214+
s.k8sClient.PersistentVolumeClaimEventWarning(pctx, cvr.PvcNamespaceTag, cvr.PvcNameTag,
215+
"CsiGetStorageClassFailure", ierr.GetMessage())
204216
return nil, ierr.GetError()
205217
}
206218

@@ -215,11 +227,13 @@ func (s *controllerService) CreateVolume(pctx lctx.Context, preq *lcsi.CreateVol
215227
newVol, sdkErr := s.cloud.EitherCreateResizeVolume(cvr.ToSdkCreateVolumeRequest())
216228
if sdkErr != nil {
217229
llog.ErrorS(sdkErr.GetError(), "[ERROR] - CreateVolume: failed to create volume", sdkErr.GetErrorMessages())
230+
s.k8sClient.PersistentVolumeClaimEventWarning(pctx, cvr.PvcNamespaceTag, cvr.PvcNameTag,
231+
"CsiCreateVolumeFailure", sdkErr.GetMessage())
218232
return nil, sdkErr.GetError()
219233
}
220234

221235
s.k8sClient.PersistentVolumeClaimEventNormal(pctx, cvr.PvcNamespaceTag, cvr.PvcNameTag,
222-
"CsiCreateVolumeSuccess", lfmt.Sprintf("Volume created successfully with ID %s for PVC %s", newVol.Id, newVol.Name))
236+
"CsiCreateVolumeSuccess", lfmt.Sprintf("Volume created successfully with ID %s for PersistentVolume %s", newVol.Id, newVol.Name))
223237
return newCreateVolumeResponse(newVol, cvr, respCtx), nil
224238
}
225239

0 commit comments

Comments
 (0)