-
Notifications
You must be signed in to change notification settings - Fork 127
internal/profile: export profile loading function #2916
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
0e30fc2
to
be5209a
Compare
internal/profile/config.go
Outdated
) | ||
|
||
const currentVersion = 1 | ||
const CurrentVersion = 1 |
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.
Is this going to be used out of 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.
Yes
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.
Could you give more deatils about how this is going to be used out of the package?
internal/profile/migrations.go
Outdated
) | ||
|
||
func (p *Profile) migrate(version uint) error { | ||
func (p *Profile) Migrate(version uint) 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.
At the moment migration is part of the profile loading process, it shouldn't be needed out of the package. Do you have a use case for this?
If this is intended to load from a directory with the migrations included, maybe we could keep loadProfile
private, and create a method LoadProfileFrom
, that does the same as LoadProfile
, including the migrations. So callers don't need to care about migrations.
Something like this:
func LoadProfile(profileName string) (*Profile, error) {
loc, err := locations.NewLocationManager()
if err != nil {
return nil, fmt.Errorf("error finding stack dir location: %w", err)
}
return LoadProfileFrom(profileName, loc.ProfileDir())
}
func LoadProfileFrom(profileName, profilesDir string) (*Profile, error) {
profile, err := loadProfile(profilesDir, profileName)
if err != nil {
return nil, err
}
err = profile.migrate(currentVersion)
if err != nil {
return nil, fmt.Errorf("error migrating profile to version %v: %w", currentVersion, err)
}
return profile, 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.
Given the choice of reduced code duplication/increased code complixity, and reduced exported functions in an internal package, I chose the latter.
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.
It is not so much about functions exported or code duplication, but about responsibilities.
As the package is defined now the responsibility of migrating profiles clearly belongs to the profile
package.
If we expose different methods for load and migration of profiles, this responsibility is diluted.
Also, exposing two different "LoadProfile" methods that do different things is prone to errors (LoadProfile
would run migrations, but LoadProfileFrom
wouldn't).
The changes that are in this are the minimal set that I need to be able to implement a testscript hook for bringing up/taking down a stack. |
I understand how loading specific profiles may be needed, but running migrations from different places looks error-prone. Why is this needed? |
I don't specifically need the migration method, but this is the minimal change to get the behaviour that is needed given the way that testing is done here. Ideally, I'd not do it, but the proposal above it more complicated for IMO limited benefit. |
I think I am missing what is the needed behavior. Other packages can already load profiles with |
I this is insisted, I will do this, but I disagree. Specifically, "having to use the migration functionality out of the profile package" is not part of the required behaviour, though I can see test situations where it may be, and in that case, it would then have to be exported. I do not see the benefit from hiding functionality in a package that is internal, and I am seeing significant composability friction because of the level of non-exported labels in these packages. |
I am sorry for the disagreement, but I would greatly prefer to avoid exposing migration functionality if not needed, yes. Also, if we expose two methods for loading profiles, I would prefer both to be consistent regarding migrations (or any other thing that they do).
One of the advantages of keeping separated responsibilities is that other packages shouldn't need to care about this functionality, including its testing. If we happen to find a situation where we would benefit from exposing this functionality out of this package I would be happy to do it. Till then I would prefer to keep it separated. |
…ons" This reverts commit be5209a.
3e0a6e5
to
6325ab8
Compare
⏳ Build in-progress, with failures
Failed CI StepsHistory
cc @efd6 |
6325ab8
to
d45bb61
Compare
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.
LGTM!
For #2868
Please take a look.