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

Refactor controller code #41

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open

Refactor controller code #41

wants to merge 36 commits into from

Conversation

amirbavand
Copy link
Collaborator

@amirbavand amirbavand commented Nov 10, 2024

This PR aims to refactor DynamicReconciler.go
The reason for changing other files is to make the targeted file (DynamicReconciler.go) testable. The other files were mainly changed to do dependency injection for DynamicReconciler.
The main refactoring for other files inside controller package will be done in the future PRs

Copy link
Contributor

github-actions bot commented Nov 15, 2024

⬇️ Go test coverage decreased from 71.2% to 71.0% compared to fe0e695 (1 ignored files)
⚠️ 2 of 12 packages have zero coverage.
  • kumquat
  • kumquat/cmd

Updated Package Coverages:

# Package Name                |  Prior |    New
+ kumquat/internal/controller |  72.6% |  73.3%
+ kumquat/repository          |  91.8% |  92.8%
View coverage for all packages
# Package Name                | Coverage
- kumquat                     |     0.0%
+ kumquat/api/v1beta1         |   100.0%
- kumquat/cmd                 |     0.0%
+ kumquat/internal/controller |    73.3%
+ kumquat/renderer            |   100.0%
+ kumquat/renderer/cue        |    88.4%
+ kumquat/renderer/gotemplate |    95.8%
+ kumquat/renderer/jsonnet    |    87.9%
+ kumquat/repository          |    92.8%
+ kumquat/store               |    75.0%
+ kumquat/template            |    93.9%
+ kumquat/test/utils          |    10.8%

@amirbavand amirbavand marked this pull request as ready for review November 15, 2024 17:45
@amirbavand amirbavand marked this pull request as draft November 16, 2024 18:54
@amirbavand amirbavand removed the request for review from jamesdobson November 16, 2024 18:54
@amirbavand amirbavand removed the request for review from katronquillo November 16, 2024 18:54
@amirbavand amirbavand marked this pull request as ready for review November 17, 2024 16:47
internal/controller/watchmanager.go Outdated Show resolved Hide resolved
internal/controller/watchmanager.go Outdated Show resolved Hide resolved
func (m *MockRepo) DropTable(tableName string) error {
return nil
}
func (m *MockRepo) ExtractTableNamesFromQuery(query string) []string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also leaks the abstraction because it returns table names. Also, we will have to copy it for each implementation of Repository.

What do you think about the following?

We can fix this with a Query interface:

type Query interface {
    SQLQueryString() string
    GetKinds() []string
}

and a concrete implementation SQLQuery. The GetKinds() method can contain the logic for ExtractTableNamesFromQuery().

We can update Repository.Query() to accept a Query as its arguments. The implementation of Query() in SQLiteRepository can call SQLQueryString() to get the string to use.

repository/sqliterepository.go Show resolved Hide resolved
err := repo.DropTable(tableName)
if err != nil {
// if the table does not exist, return nil
if err.Error() == "table does not exist: "+tableName {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you are able to change DropTable to be DeleteAll, then you can eliminate this case: DeleteAll will return success even if there is nothing to delete.

internal/controller/dynamicReconciler.go Outdated Show resolved Hide resolved
internal/controller/dynamicReconciler.go Outdated Show resolved Hide resolved
internal/controller/utils.go Show resolved Hide resolved
internal/controller/dynamicReconciler.go Outdated Show resolved Hide resolved
internal/controller/dynamic_reconciler_test.go Outdated Show resolved Hide resolved
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.

2 participants