Skip to content

Commit

Permalink
use reader instead of client
Browse files Browse the repository at this point in the history
Signed-off-by: Raghavendra Talur <[email protected]>
  • Loading branch information
raghavendra-talur committed Jan 9, 2025
1 parent 90e62e2 commit dd64684
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 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.Client, reader 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 All @@ -50,7 +50,7 @@ func EvaluateCheckHook(k8sClient client.Client, hook *kubeobjects.HookSpec, log
case <-ctx.Done():
return false, fmt.Errorf("timeout waiting for resource %s to be ready: %w", hook.NameSelector, ctx.Err())
case <-ticker.C:
objs, err := getResourcesList(k8sClient, hook)
objs, err := getResourcesList(k8sClient, reader, hook)
if err != nil {
return false, err // Some other error occurred, return it
}
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.Client, reader client.Reader, hook *kubeobjects.HookSpec) ([]client.Object, error) {
resourceList := make([]client.Object, 0)

var objList client.ObjectList
Expand All @@ -108,7 +108,7 @@ func getResourcesList(k8sClient client.Client, hook *kubeobjects.HookSpec) ([]cl
}

if hook.NameSelector != "" {
objsUsingNameSelector, err := getResourcesUsingNameSelector(k8sClient, hook, objList)
objsUsingNameSelector, err := getResourcesUsingNameSelector(k8sClient, reader, hook, objList)
if err != nil {
return resourceList, err
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func getResourcesUsingLabelSelector(c client.Client, hook *kubeobjects.HookSpec,
return getObjectsBasedOnType(objList), nil
}

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

err = c.List(context.Background(), objList, listOps)
// err = c.List(context.Background(), objList, listOps)
err = reader.List(context.Background(), objList, listOps)
if err != nil {
return filteredObjs, err
return filteredObjs, fmt.Errorf("error during 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.Client, v.reconciler.APIReader, &hook, log1)

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

0 comments on commit dd64684

Please sign in to comment.