Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic on NullPointer #458

Closed
tomassatka opened this issue Oct 31, 2024 · 1 comment · Fixed by #459
Closed

Panic on NullPointer #458

tomassatka opened this issue Oct 31, 2024 · 1 comment · Fixed by #459

Comments

@tomassatka
Copy link
Contributor

When running in container as cronjob i found following issue:

func (w *worker) listResources(ctx context.Context, res *types.GroupResource, hasMorePages string) string {
	w.currentPage = res.Pages + 1
	w.prog.NewSearchBar(progress.Step{WorkerID: w.id, CurrentKind: w.currentKind, PageSize: w.config.QueryPageSize, CurrentPage: w.currentPage})
	start := time.Now()
	ul, err := w.list(ctx, res.APIGroup, res.APIVersion, res.APIResource.Kind, hasMorePages)

	if w.prog != nil {
		w.prog.IncrementResourceBarBy(w.id, 1)
	}

	res.QueryDuration += time.Since(start)
	w.queryFinished = true
	start = time.Now()

	if err != nil {
		w.stats.Errors++
		if errors.IsNotFound(err) {
			res.Error = "Not Found"
		} else if errors.IsMethodNotSupported(err) {
			res.Error = "Not Allowed"
		} else {
			res.Error = "Error:" + err.Error()
		}
	} else {
		w.prog.NewExportBar(progress.Step{WorkerID: w.id, CurrentKind: w.currentKind, PageSize: w.config.QueryPageSize, CurrentPage: w.currentPage, Total: len(ul.Items)})
		if w.config.AsLists {
			res.ExportedInstances += w.exportLists(res, ul)
		} else {
			res.ExportedInstances += w.exportSingleResources(res, ul)
		}
	}
	res.ExportDuration += time.Since(start)

	res.Instances += len(ul.Items)
	res.Pages++

	return ul.GetContinue()
}

if ul, err := w.list(ctx, res.APIGroup, res.APIVersion, res.APIResource.Kind, hasMorePages) returns an error so ul is null later on is and IF that increments the counter for errors but it continues till res.Instances += len(ul.Items) and since ul is in this case null it panics.

User cant see why it exits. In my case it was the issue that i used rolebinding instead of clusterrolebinding for service account. However simple return fix the behavior

@bakito
Copy link
Owner

bakito commented Oct 31, 2024

@tomassatka thank you for the detailed description and the provided fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants