@@ -12,6 +12,7 @@ import (
12
12
13
13
"github.com/go-logr/logr"
14
14
ramen "github.com/ramendr/ramen/api/v1alpha1"
15
+ "github.com/ramendr/ramen/internal/controller/hooks"
15
16
"github.com/ramendr/ramen/internal/controller/kubeobjects"
16
17
"github.com/ramendr/ramen/internal/controller/util"
17
18
Recipe "github.com/ramendr/recipe/api/v1alpha1"
@@ -280,7 +281,15 @@ func (v *VRGInstance) executeCaptureSteps(result *ctrl.Result, pathName, capture
280
281
isEssentialStep := cg .GroupEssential != nil && * cg .GroupEssential
281
282
282
283
if cg .IsHook {
283
- err = v .executeHook (cg .Hook , log1 )
284
+ executor , err1 := hooks .GetHookExecutor (cg .Hook )
285
+ if err1 != nil {
286
+ // continue if hook type is not supported. Supported types are "check" and "exec"
287
+ log1 .Info ("Hook type not supported" , "hook" , cg .Hook )
288
+
289
+ continue
290
+ }
291
+
292
+ err = executor .Execute (v .reconciler .Client , log1 )
284
293
}
285
294
286
295
if ! cg .IsHook {
@@ -325,39 +334,6 @@ func (v *VRGInstance) executeCaptureSteps(result *ctrl.Result, pathName, capture
325
334
return allEssentialStepsFailed , nil
326
335
}
327
336
328
- func (v * VRGInstance ) executeHook (hook kubeobjects.HookSpec , log1 logr.Logger ) error {
329
- if hook .Type == "check" {
330
- hookResult , err := util .EvaluateCheckHook (v .reconciler .APIReader , & hook , log1 )
331
- if err != nil {
332
- log1 .Error (err , "error occurred during check hook " )
333
- } else {
334
- hookName := hook .Name + "/" + hook .Chk .Name
335
- log1 .Info ("Check hook executed successfully" , "check hook is " , hookName , " result is " , hookResult )
336
- }
337
-
338
- if ! hookResult && shouldHookBeFailedOnError (& hook ) {
339
- return fmt .Errorf ("stopping workflow sequence as check hook failed" )
340
- }
341
-
342
- return nil
343
- }
344
-
345
- return nil
346
- }
347
-
348
- func shouldHookBeFailedOnError (hook * kubeobjects.HookSpec ) bool {
349
- // hook.Check.OnError overwrites the feature of hook.OnError -- defaults to fail
350
- if hook .Chk .OnError != "" && hook .Chk .OnError == "continue" {
351
- return false
352
- }
353
-
354
- if hook .OnError != "" && hook .OnError == "continue" {
355
- return false
356
- }
357
-
358
- return true
359
- }
360
-
361
337
func (v * VRGInstance ) kubeObjectsGroupCapture (
362
338
result * ctrl.Result ,
363
339
captureGroup kubeobjects.CaptureSpec ,
@@ -758,6 +734,7 @@ func (v *VRGInstance) kubeObjectsRecoveryStartOrResume(
758
734
return v .kubeObjectsRecoverRequestsDelete (result , v .veleroNamespaceName (), labels )
759
735
}
760
736
737
+ // nolint: gocognit,cyclop
761
738
func (v * VRGInstance ) executeRecoverSteps (result * ctrl.Result , s3StoreAccessor s3StoreAccessor ,
762
739
captureToRecoverFromIdentifier * ramen.KubeObjectsCaptureIdentifier , captureRequests ,
763
740
recoverRequests map [string ]kubeobjects.Request , requests []kubeobjects.Request , log logr.Logger ,
@@ -776,7 +753,15 @@ func (v *VRGInstance) executeRecoverSteps(result *ctrl.Result, s3StoreAccessor s
776
753
isEssentialStep := rg .GroupEssential != nil && * rg .GroupEssential
777
754
778
755
if rg .IsHook {
779
- err = v .executeHook (rg .Hook , log1 )
756
+ executor , err1 := hooks .GetHookExecutor (rg .Hook )
757
+ if err1 != nil {
758
+ // continue if hook type is not supported. Supported types are "check" and "exec"
759
+ log1 .Info ("Hook type not supported" , "hook" , rg .Hook )
760
+
761
+ continue
762
+ }
763
+
764
+ err = executor .Execute (v .reconciler .Client , log1 )
780
765
}
781
766
782
767
if ! rg .IsHook {
0 commit comments