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

fix(GrafanaDatasource): don't treat missing datasource as an error when deleting datasource #1879

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

lexhuismans
Copy link
Contributor

@lexhuismans lexhuismans commented Feb 28, 2025

A similar PR as for the issue regarding grafanafolder controller #1516 but for the grafanadatasource controller.

This solves two problems

Datasource removed from Grafana instance but not yet from Grafana CRD

Looks like when we retrieve the ID or try to the delete the resource and we receive an error we only return the exception on NotFound. While we should proceed on NotFound (to delete the resource from the Grafana CRD) and return on any other exception.

This will happen when a datasource is for example manually deleted using the the UI. And will loop forever. Reconciler error

Datasource removed from Grafana CRD when client throws an error

The other side of this is that when an error occurs that is anything but NotFound: if errors.As(err, &notFound) > False > remove datasource the datasource is removed from the Grafana CRD status anyway.

Code

Bug

... 
if errors.As(err, &notFound) {
	return ctrl.Result{}, err
}
...
grafana.Status.Dashboards = grafana.Status.Dashboards.Remove(namespace, name)

// won't remove datasource from Grafana CRD when already removed, e.g. through UI
// will remove datasource from Grafana CRD status list when different error occurs (e.g. Grafana unavailable)

Feature

...
if !errors.As(err, &notFound) {
	return ctrl.Result{}, err
}
...
grafana.Status.Dashboards = grafana.Status.Dashboards.Remove(namespace, name)

// will remove datasource from Grafana CRD when already removed, e.g. through UI
// won't remove datasource from Grafana CRD status list when different error occurs (e.g. Grafana unavailable)

@CLAassistant
Copy link

CLAassistant commented Feb 28, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the bugfix this PR fixes a bug label Feb 28, 2025
@lexhuismans lexhuismans marked this pull request as ready for review February 28, 2025 14:03
Copy link
Member

@theSuess theSuess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Thanks for the contribution

@theSuess theSuess enabled auto-merge February 28, 2025 14:14
@theSuess theSuess added this pull request to the merge queue Feb 28, 2025
Merged via the queue into grafana:master with commit 9affc62 Feb 28, 2025
15 checks passed
@weisdd weisdd changed the title don't treat missing datasource as an error when deleting datasource fix(GrafanaDatasource): don't treat missing datasource as an error when deleting datasource Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix this PR fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants