Skip to content

PTEUDO1071 - migrate new schemas users when version shape or type changes, delete CR #267

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

Conversation

EvertonCalgarotto
Copy link
Contributor

@EvertonCalgarotto EvertonCalgarotto commented Jul 31, 2024

Migrate schemas and users when version, shape or type changes
Delete users when DBRoleClaim is deleted
Create new users and schemas when DBRoleClaim is created.
Ensure passwords are rotated.

@EvertonCalgarotto EvertonCalgarotto marked this pull request as ready for review August 5, 2024 14:37
@EvertonCalgarotto EvertonCalgarotto changed the title PTEUDO1071 - migrate new schemas users when version shape or type changes PTEUDO1071 - migrate new schemas users when version shape or type changes, delete CR Aug 5, 2024
Copy link
Contributor

@drewwells drewwells left a comment

Choose a reason for hiding this comment

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

Made a lot of comments. I think you can do a lot more cleanup around the instance label stuff that is dead code. There's a couple of tests that use it, but no apps on biab clusters actually use those hacks.

@@ -48,7 +48,7 @@ type Exister interface {
}

type Remover interface {
DeleteUser(username, reassignToUser string) error
DeleteUser(dbName, username, reassignToUser string) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
DeleteUser(dbName, username, reassignToUser string) error
DeleteUser(ctx context.Context, dbName, username, reassignToUser string) error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is that? We don't use the context here for anything.

viperObj.Set("defaultMasterPort", "5432")
viperObj.Set("defaultSslMode", "require")
viperObj.Set("defaultMinStorageGB", "10")
viperObj.Set("defaultSslMode", "disable")
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, viper has burned me when calling it inside libraries.
My suggestion in big refactors like this is to move all of the properties to a config object and read it from there. viper shouldn't be called outside of the main func at startup time. If we need some sort of hot reloading, that's different. We can register a method that viper can call to update properties though. It saves us from calling into viper anywhere in the package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When it's in the main code, I agree. These default values should be read when starting the app and kept somewhere in the context, to be reused when needed. But these are tests only, so I wouldn't bother too much about these in here.

if dbClaim.Spec.Host != "" {
return dbClaim.Spec.Host
}
return r.Config.Viper.GetString(fmt.Sprintf("%s::Host", dbcBaseConfig.FragmentKey))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above, we should not rely on viper inside libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alright, I'll think of something to load these values when the app is starting and keep them in the context or somewhere more meaningful then viper itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

put all viper methods in the basefunctions class to keep them centralized and easy to find.

Comment on lines +415 to +434
func (r *DbRoleClaimReconciler) matchInstanceLabel(dbClaim *v1.DatabaseClaim) (string, error) {
settingsMap := r.Config.Viper.AllSettings()

rTree := radix.New()
for k := range settingsMap {
if k != "passwordconfig" {
rTree.Insert(k, true)
}
}

// Find the longest prefix match
m, _, ok := rTree.LongestPrefix(dbClaim.Spec.InstanceLabel)
if !ok {
return "", fmt.Errorf("can't find any instance label matching fragment keys")
}

dbClaim.Status.ActiveDB.MatchedLabel = m

return m, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

2 birds with one stone. If you remove this method, you can also remove the radix package. Modern CRs doesn't rely on this instanceLabel work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will remove it on another task

@EvertonCalgarotto EvertonCalgarotto merged commit a4f0e60 into main Aug 5, 2024
3 checks passed
@EvertonCalgarotto EvertonCalgarotto deleted the PTEUDO-1071-migrate-new-schemas-users-when-version-shape-or-type-changes branch August 5, 2024 21:31
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