Define a constant instead of duplicating a literal
"Failed to process delete notification" literal was duplicated
4 times in pkg/virt-controller/watch/migration.go.
Replace this literal with a constant.
Was detected by SonarCloud code scan as a code smell issue.
@@ -48,6 +48,8 @@ import (
"kubevirt.io/kubevirt/pkg/virt-controller/services"
)
+const failedToProcessDeleteNotificationErrMsg = "Failed to process delete notification"
+
type MigrationController struct {
templateService services.TemplateService
clientset kubecli.KubevirtClient
@@ -716,12 +718,12 @@ func (c *MigrationController) deletePod(obj interface{}) {
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
- log.Log.Reason(fmt.Errorf("couldn't get object from tombstone %+v", obj)).Error("Failed to process delete notification")
+ log.Log.Reason(fmt.Errorf("couldn't get object from tombstone %+v", obj)).Error(failedToProcessDeleteNotificationErrMsg)
return
}
pod, ok = tombstone.Obj.(*k8sv1.Pod)
if !ok {
- log.Log.Reason(fmt.Errorf("tombstone contained object that is not a pod %#v", obj)).Error("Failed to process delete notification")
+ log.Log.Reason(fmt.Errorf("tombstone contained object that is not a pod %#v", obj)).Error(failedToProcessDeleteNotificationErrMsg)
return
}
}
@@ -813,12 +815,12 @@ func (c *MigrationController) deleteVMI(obj interface{}) {
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
- log.Log.Reason(fmt.Errorf("couldn't get object from tombstone %+v", obj)).Error("Failed to process delete notification")
+ log.Log.Reason(fmt.Errorf("couldn't get object from tombstone %+v", obj)).Error(failedToProcessDeleteNotificationErrMsg)
return
}
vmi, ok = tombstone.Obj.(*virtv1.VirtualMachineInstance)
if !ok {
- log.Log.Reason(fmt.Errorf("tombstone contained object that is not a vmi %#v", obj)).Error("Failed to process delete notification")
+ log.Log.Reason(fmt.Errorf("tombstone contained object that is not a vmi %#v", obj)).Error(failedToProcessDeleteNotificationErrMsg)
return
}
}
