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

Chore(Internal): Add new shared reconciliation functions and migrate GrafanaFolder #1770

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Baarsgaard
Copy link
Contributor

@Baarsgaard Baarsgaard commented Nov 20, 2024

This PR aims to improve how reconciliation functions are written going forward, starting with the folder controller.

The goal is to reduce duplicated code by moving more logic into matching Grafana instances.
This is achieved by namespacing the client to limit the scope of the search when resources do not specify allowCrossNamespaceImport: true

Additional functions have been added for simplifying building conditions when no matching instances are found.

Lastly, it aligns the existing folder reconcile error logging with other resources

@Baarsgaard
Copy link
Contributor Author

Baarsgaard commented Nov 20, 2024

Since the folder E2E test works, this is unlikely to have introduced any regressions.

@Baarsgaard Baarsgaard marked this pull request as ready for review November 20, 2024 20:47
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.

The overall approach looks good, I just have a few comments regarding code style!

api/v1beta1/grafanafolder_types.go Outdated Show resolved Hide resolved
api/common_interfaces.go Outdated Show resolved Hide resolved
api/common_interfaces.go Outdated Show resolved Hide resolved
@Baarsgaard Baarsgaard force-pushed the update_folder_reconciliation branch 2 times, most recently from 3692ecf to b112b69 Compare November 25, 2024 22:38
@Baarsgaard
Copy link
Contributor Author

I've applied your suggestions as well as added some test cases for the new list functions for Grafana instances.

Copy link
Collaborator

@weisdd weisdd left a comment

Choose a reason for hiding this comment

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

Could you rebase your branch? (merged your PR that introduced common fields)

api/v1beta1/grafanafolder_types.go Show resolved Hide resolved
@Baarsgaard Baarsgaard changed the title Refactor: Folder reconciliation with new shared functions Chore(Internal): Add new shared reconciliation functions and migrate GrafanaFolder Nov 27, 2024
@Baarsgaard Baarsgaard force-pushed the update_folder_reconciliation branch 2 times, most recently from ca83723 to 598c1c6 Compare November 27, 2024 11:49
@Baarsgaard
Copy link
Contributor Author

@theSuess @weisdd Should be ready for final review now!

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.

Found one last issue in the logic of fetching instances, from an implementation standpoint this looks great!

@pb82 can you take a look as well as this might resolve some issues you're tackling in #1762?

@@ -39,3 +39,12 @@ type GrafanaCommonSpec struct {
// +optional
AllowCrossNamespaceImport *bool `json:"allowCrossNamespaceImport,omitempty"`
}

// Common Functions that all CRs should implement, excluding Grafana
// +kubebuilder:object:generate=false
Copy link
Member

Choose a reason for hiding this comment

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

Just out of curiosity, what kind of object would kubebuilder generate for an interface?

Copy link
Contributor Author

@Baarsgaard Baarsgaard Nov 27, 2024

Choose a reason for hiding this comment

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

Nothing, it prints an error:

github.com/grafana/grafana-operator/v5/api/v1beta1:-: invalid type: interface{AllowCrossNamespace() bool; MatchLabels() *k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelector; MatchNamespace() string; ResyncPeriodHasElapsed() bool}
Error: not all generators ran successfully
run `controller-gen object:headerFile=hack/boilerplate.go.txt paths=./... -w` to see all available markers, or `controller-gen object:headerFile=hack/boilerplate.go.txt paths=./... -h` for usage
make: *** [Makefile:90: generate] Error 1

Which is the original reason I didn't have it defined under the v1beta1 package.
Untill I found that specific annotation.

Comment on lines 67 to 71
if instanceSelector.MatchLabels == nil {
return []v1beta1.Grafana{}, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

An empty label selector should match all instances, not none. At least this is the behavior right now, and I think there's value in keeping it that way

Copy link
Contributor Author

@Baarsgaard Baarsgaard Nov 27, 2024

Choose a reason for hiding this comment

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

From what I can tell that's not the current behaviour, the existing implementation of GetMatchingInstances(...) exits early.
I left that function alone to not interfere with any other reconciliation loop.
Additionally, instanceSelector is not an optional/nullable field:
image

Copy link
Contributor Author

@Baarsgaard Baarsgaard Nov 27, 2024

Choose a reason for hiding this comment

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

Update: it can be configured with instanceSelector: {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, don't merge this yet, I need to fully understand instanceSelector behaviour before this is ready.

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.

3 participants