crossplane-contrib / provider-sql

An SQL provider for @crossplane
https://crossplane.io
Apache License 2.0
104 stars 59 forks source link

Fix Grant revocation #118

Closed jabbrwcky closed 1 year ago

jabbrwcky commented 1 year ago

If the grant is already gone when the reconciler tries to revoke it, it should mark the resource as successfully removed, not error.

MySQL 8.x+ supports REVOKE %s IF EXISTS ON %s.%s FROM %s@%s IGNORE UNKNOWN USER to avoid an error (which would be a cleaner solution IMO), but this will only be possible when dropping support for earlier versions.

Description of your changes

Checks the actual mysql error code that is returned when the grant revocation SQL errors; if the code states that the grant does not exist, it returns nil for successful removal of the grant.

Basically uses the same code as https://github.com/crossplane-contrib/provider-sql/blob/ed6c55ce4798967e7652a4cce9f844b99ac1bbb7/pkg/controller/mysql/grant/reconciler.go#L227-L231

Fixes #47

I have:

How has this code been tested

Added unit test for this case to grants/reconciler_test.go

chlunde commented 1 year ago

Nice, could you git commit -s? See https://github.com/crossplane-contrib/provider-sql/pull/118/checks?check_run_id=9415901160

Just a heads up: I also think we will need a rebase when https://github.com/crossplane-contrib/provider-sql/pull/105 is merged

jabbrwcky commented 1 year ago

Commit is signed

Duologic commented 1 year ago

Can you fix the lint error?

jabbrwcky commented 1 year ago

Fixed the reported linter issues.

You might consider upgrading golangci-lint (if possible for github-actions?), the output from v 1.50.1 is much more helpful:

pkg/controller/mysql/grant/reconciler.go:333:4: commentFormatting: put a space between `//` and comment text (gocritic)
                        //MySQL automatically deletes related grants if the user has been deleted