-
Notifications
You must be signed in to change notification settings - Fork 14
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
PTEUDO1071 - migrate new schemas users when version shape or type changes, delete CR #267
Conversation
…ew-schemas-users-when-version-shape-or-type-changes
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DeleteUser(dbName, username, reassignToUser string) error | |
DeleteUser(ctx context.Context, dbName, username, reassignToUser string) error |
There was a problem hiding this comment.
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.
pkg/roleclaim/dbroleclaim_test.go
Outdated
viperObj.Set("defaultMasterPort", "5432") | ||
viperObj.Set("defaultSslMode", "require") | ||
viperObj.Set("defaultMinStorageGB", "10") | ||
viperObj.Set("defaultSslMode", "disable") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/roleclaim/roleclaim.go
Outdated
if dbClaim.Spec.Host != "" { | ||
return dbClaim.Spec.Host | ||
} | ||
return r.Config.Viper.GetString(fmt.Sprintf("%s::Host", dbcBaseConfig.FragmentKey)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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.