Skip to content

Commit

Permalink
vrg: use reader instead of client for check hooks
Browse files Browse the repository at this point in the history
Co-Authored-by: Annaraya Narasagond <[email protected]>
Signed-off-by: Raghavendra Talur <[email protected]>
  • Loading branch information
raghavendra-talur and asn1809 committed Jan 14, 2025
1 parent 20d6183 commit ecc4af9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions internal/controller/util/json_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
pInterval = 100
)

func EvaluateCheckHook(k8sClient client.Client, hook *kubeobjects.HookSpec, log logr.Logger) (bool, error) {
func EvaluateCheckHook(k8sClient client.Reader, hook *kubeobjects.HookSpec, log logr.Logger) (bool, error) {
if hook.LabelSelector == nil && hook.NameSelector == "" {
return false, fmt.Errorf("either nameSelector or labelSelector should be provided to get resources")
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func EvaluateCheckHookForObjects(objs []client.Object, hook *kubeobjects.HookSpe
return finalRes, err
}

func getResourcesList(k8sClient client.Client, hook *kubeobjects.HookSpec) ([]client.Object, error) {
func getResourcesList(k8sClient client.Reader, hook *kubeobjects.HookSpec) ([]client.Object, error) {
resourceList := make([]client.Object, 0)

var objList client.ObjectList
Expand Down Expand Up @@ -128,14 +128,14 @@ func getResourcesList(k8sClient client.Client, hook *kubeobjects.HookSpec) ([]cl
return resourceList, nil
}

func getResourcesUsingLabelSelector(c client.Client, hook *kubeobjects.HookSpec,
func getResourcesUsingLabelSelector(c client.Reader, hook *kubeobjects.HookSpec,
objList client.ObjectList,
) ([]client.Object, error) {
filteredObjs := make([]client.Object, 0)

selector, err := metav1.LabelSelectorAsSelector(hook.LabelSelector)
if err != nil {
return filteredObjs, fmt.Errorf("error during labelSelector to selector conversion")
return filteredObjs, fmt.Errorf("error converting labelSelector to selector")
}

listOps := &client.ListOptions{
Expand All @@ -145,13 +145,13 @@ func getResourcesUsingLabelSelector(c client.Client, hook *kubeobjects.HookSpec,

err = c.List(context.Background(), objList, listOps)
if err != nil {
return filteredObjs, err
return filteredObjs, fmt.Errorf("error listing resources using labelSelector: %w", err)
}

return getObjectsBasedOnType(objList), nil
}

func getResourcesUsingNameSelector(c client.Client, hook *kubeobjects.HookSpec,
func getResourcesUsingNameSelector(c client.Reader, hook *kubeobjects.HookSpec,
objList client.ObjectList,
) ([]client.Object, error) {
filteredObjs := make([]client.Object, 0)
Expand All @@ -169,7 +169,7 @@ func getResourcesUsingNameSelector(c client.Client, hook *kubeobjects.HookSpec,

err = c.List(context.Background(), objList, listOps)
if err != nil {
return filteredObjs, err
return filteredObjs, fmt.Errorf("error listing resources using nameSelector: %w", err)
}

return getObjectsBasedOnType(objList), nil
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/vrg_kubeobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (v *VRGInstance) kubeObjectsCaptureStartOrResume(

func (v *VRGInstance) executeHook(hook kubeobjects.HookSpec, log1 logr.Logger) error {
if hook.Type == "check" {
hookResult, err := util.EvaluateCheckHook(v.reconciler.Client, &hook, log1)
hookResult, err := util.EvaluateCheckHook(v.reconciler.APIReader, &hook, log1)

if err != nil {
log1.Error(err, "error occurred during check hook ")
Expand Down

0 comments on commit ecc4af9

Please sign in to comment.