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: enabling deleted grafana datasources to be recreated #96

Merged
merged 1 commit into from
Dec 17, 2021

Conversation

prashbnair
Copy link

No description provided.

@prashbnair prashbnair requested a review from a team December 10, 2021 13:40
Copy link
Contributor

@fpetkovski fpetkovski left a comment

Choose a reason for hiding this comment

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

Looks good, just left a few small nits.

pkg/controllers/monitoring-stack/controller.go Outdated Show resolved Hide resolved
@fpetkovski
Copy link
Contributor

@sthaha do you think we want an e2e test here?

@sthaha
Copy link
Collaborator

sthaha commented Dec 13, 2021

@sthaha do you think we want an e2e test here?

I agree, we should test if operator restores datasource if it is modified or deleted. I suspect that given then current code that it might crash if the datasource is deleted.
@prashbnair have you tested this?

@prashbnair
Copy link
Author

I agree, we should test if operator restores datasource if it is modified or deleted. I suspect that given then current code that it might crash if the datasource is deleted.

Yes this has been tested.

@prashbnair
Copy link
Author

I think should take the opportunity to fix this name collision as well.

Can we do this in a separate PR?

pkg/controllers/monitoring-stack/controller.go Outdated Show resolved Hide resolved
pkg/controllers/monitoring-stack/controller.go Outdated Show resolved Hide resolved
@sthaha
Copy link
Collaborator

sthaha commented Dec 14, 2021

Can we do this in a separate PR?

Sure thing :-)

@sthaha
Copy link
Collaborator

sthaha commented Dec 14, 2021

@prashbnair , Could you please also ensure that deletion a namespace that contains monitoring-stacks also cleans up their associated grafana-datasources ?

@sthaha
Copy link
Collaborator

sthaha commented Dec 14, 2021

As discussed, it would be nice to have all reconciliation issues sorted in a single or multiple PRs

@prashbnair
Copy link
Author

@sthaha I will address the clean up of grafana data sources when the monitoring stack or namespace is deleted as a separate PR.


if err != nil {
log.V(3).Info("grafana data source CRD is not defined")
return err
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should follow same the implementation in @fpetkovski 's PR ... https://github.com/rhobs/monitoring-stack-operator/pull/103/files#diff-606d75b2cccce3c13550d55e0c1b27bb1c1fad0431b4f16d466e41dd4e0c801dR355

I.E. function should return requeue (bool) and error

func setWatch() (requeue bool, err error){

  if err = listDataSources(); err != nil 
    return true, nil 
  }
  err = setWatch()
  return false, err
}

So that the caller (Reconcile func) can ...

if requeue, err := r.setGrafanaDatasourceWatch(); requeue || err != nil {
   if err {
     return ctrl.Result{}, err
  }
  return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
}

Copy link
Author

Choose a reason for hiding this comment

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

All the patchers in this reconcile function return an error , I have followed the same model.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This part is different from the rest of the patchers. This isn't a patcher to start with :-)

More importantly ...
We need the ability to requeue without error if GrafanaDataSource CRD is not created and to log real errors when setting up a watch fails.


f.K8sClient.Delete(context.Background(), &grafanaDS)

f.GetResourceWithRetry(t, datasourceName, "monitoring-stack-operator", &grafanaDS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should make use of AssertResourceEventuallyExists here as well

@prashbnair prashbnair force-pushed the grafana-ds branch 2 times, most recently from 2e1e30c to e094bcb Compare December 16, 2021 11:02
assert.NilError(t, err, "failed to create a monitoring stack")

grafanaDS := grafanav1alpha1.GrafanaDataSource{}

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: do we need a blank line?

sthaha
sthaha previously approved these changes Dec 17, 2021
Copy link
Collaborator

@sthaha sthaha left a comment

Choose a reason for hiding this comment

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

Good stuff @prashbnair

You may want to consider incorporating the nits

Comment on lines 152 to 155
if err != nil {
return ctrl.Result{}, err
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

this isn't needed now

@@ -82,7 +82,7 @@ func (f *Framework) AssertResourceEventuallyExists(name, namespace string, resou
}
return false, nil
}); err == wait.ErrWaitTimeout {
t.Fatal(fmt.Errorf("statefulset %s/%s was never created", namespace, name))
t.Fatal(fmt.Errorf("resource %s/%s was never created", namespace, name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

good catch!

sthaha
sthaha previously approved these changes Dec 17, 2021
Copy link
Collaborator

@sthaha sthaha left a comment

Choose a reason for hiding this comment

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

🎉

Prior to this fix, grafana datasources which were deleted were not
being recreated.
@prashbnair prashbnair merged commit 2c71d1d into rhobs:main Dec 17, 2021
@prashbnair prashbnair deleted the grafana-ds branch December 17, 2021 07:03
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 this pull request may close these issues.

None yet

3 participants