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

[mysql_controller] simplify mysql controller with indexer and ListOptions #95

Merged
merged 10 commits into from
Apr 25, 2022

Conversation

nakamasato
Copy link
Owner

@nakamasato nakamasato commented Apr 21, 2022

Changes

  • Use client.MatchingFields

    r.List(ctx, mysqlUserList, client.MatchingFields{"spec.mysqlName": mysql.Name})`
  • Set Index for spec.mysqlName in main.go and mysql_controller_test.go

        cache := mgr.GetCache()
        indexFunc := func(obj client.Object) []string {
      	  return []string{obj.(*mysqlv1alpha1.MySQLUser).Spec.MysqlName}
        }
        if err := cache.IndexField(context.TODO(), &mysqlv1alpha1.MySQLUser{}, "spec.mysqlName", indexFunc); err != nil {
      	  panic(err)
        }
  • Use actions/setup-go@v3 instead of v2 in GitHub Actions

  • Change the install command from go get to go install in Makefile

  • Upgrade kustomize to v4.5.2 to fix (ref: Support go 1.16 module aware install with version kubernetes-sigs/kustomize#3618)

    go: creating new go.mod: module tmp
    Downloading sigs.k8s.io/kustomize/kustomize/v3@v3.8.7
    go: sigs.k8s.io/kustomize/kustomize/v3@v3.8.7 (in sigs.k8s.io/kustomize/kustomize/v3@v3.8.7):
            The go.mod file for the module providing named packages contains one or
            more exclude directives. It must not contain directives that would cause
            it to be interpreted differently than if it were the main module.
    make: *** [kustomize] Error 1
    

Indexing

Indexes may be added to caches using a FieldIndexer. This allows you to easily and efficiently look up objects with certain properties. You can then make use of the index by specifying a field selector on calls to List on the Reader corresponding to the given Cache.

@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #95 (2379e2a) into main (ca00f7d) will decrease coverage by 0.33%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##             main      #95      +/-   ##
==========================================
- Coverage   77.14%   76.81%   -0.34%     
==========================================
  Files           5        5              
  Lines         210      207       -3     
==========================================
- Hits          162      159       -3     
  Misses         31       31              
  Partials       17       17              
Impacted Files Coverage Δ
controllers/mysql_controller.go 77.41% <50.00%> (-2.00%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca00f7d...2379e2a. Read the comment docs.

@nakamasato nakamasato changed the title [mysql_controller] simplify mysql controller [mysql_controller] simplify mysql controller with indexer and ListOptions Apr 25, 2022
@nakamasato nakamasato marked this pull request as ready for review April 25, 2022 11:18
@nakamasato nakamasato merged commit 02c79ca into main Apr 25, 2022
@nakamasato nakamasato deleted the simplify-mysql-controller branch April 25, 2022 11:18
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

1 participant