Skip to content

Commit

Permalink
fix: clickhouse grant deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Jul 4, 2024
1 parent 1d6fa17 commit c1fc48a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [MAJOR.MINOR.PATCH] - YYYY-MM-DD

- Ignore `http.StatusBadRequest` on `ClickhouseGrant` deletion

## v0.22.0 - 2024-07-02

- Ignore `ClickhouseRole` deletion error (missing database)
Expand Down
5 changes: 2 additions & 3 deletions controllers/clickhousegrant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
chUtils "github.com/aiven/aiven-operator/utils/clickhouse"
)

const notFoundRole = "There is no role"

// ClickhouseGrantReconciler reconciles a ClickhouseGrant object
type ClickhouseGrantReconciler struct {
Controller
Expand Down Expand Up @@ -99,7 +97,8 @@ func (h *ClickhouseGrantHandler) delete(ctx context.Context, avn *aiven.Client,
}

_, err = g.Spec.ExecuteStatements(ctx, avnGen, chUtils.REVOKE)
if err == nil || strings.Contains(err.Error(), notFoundRole) {
if isAivenError(err, http.StatusBadRequest) {
// "not found in user directories", "There is no role", etc
return true, nil
}

Expand Down
17 changes: 16 additions & 1 deletion controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func UpdateUserConfiguration(userConfig any) (map[string]any, error) {

// isNotFound works both for old and new client errors
func isNotFound(err error) bool {
return aiven.IsNotFound(err) || avngen.IsNotFound(err)
return isAivenError(err, http.StatusNotFound)
}

// isAlreadyExists works both for old and new client errors
Expand All @@ -271,3 +271,18 @@ func isDeleted(err error) (bool, error) {
}
return err == nil, err
}

// isAivenError returns true if the error comes from the old or new client and has given http code
func isAivenError(err error, code int) bool {
var oldErr aiven.Error
if errors.As(err, &oldErr) {
return oldErr.Status == code
}

var newErr avngen.Error
if errors.As(err, &newErr) {
return newErr.Status == code
}

return false
}

0 comments on commit c1fc48a

Please sign in to comment.