-
Notifications
You must be signed in to change notification settings - Fork 31
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
Refactoring lifecycle package and dependencies #148
Conversation
pkg/lifecycle/lifecycle.go
Outdated
) | ||
|
||
var ( | ||
errorChartRepository error = errors.New("chart repository is in an inconsistent state") |
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.
You don't have to indicate type here. The compiler will infer it. The name should be errChartRepository
.
pkg/lifecycle/lifecycle.go
Outdated
// Commit after each chart removal. | ||
removedAssetsVersions, err := ld.removeAssetsVersions(debug) | ||
if !exists { | ||
return errorChartRepository |
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 error used only here? If so, you don't need to predeclare it above.
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.
There's a few other places that uses this error, and IMO we should declare every custom error, so when we unit test we have a variable to compare the expected error with the returned one.
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.
The error is used in 3 different places for now.
@briandowns
It is a general one that will be thrown if you have done something really nasty to the charts repository local folder.
That is why I am not doing 3 distinct errors and only a general one.
@rafaelbreno
pkg/lifecycle/parser_test.go
Outdated
if dep.assetsVersionsMap["key1"][0].Version != "0.0.1" || | ||
dep.assetsVersionsMap["key1"][1].Version != "0.1.0" || | ||
dep.assetsVersionsMap["key1"][2].Version != "1.0.0" { | ||
if dep.AssetsVersionsMap["key1"][0].Version != "0.0.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.
We don't need to change this now nor do I know if you even wrote this but for reference, Hungarian notation in Go is a code smell and should be avoided.
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.
Fixed and also implemented assert package for unit-testing, it is easier to read. @briandowns
pkg/lifecycle/version_rules.go
Outdated
|
||
// loadFromJSON will load the version rules from version_rules.json file at charts repository | ||
func loadFromJSON(fs billy.Filesystem) (*VersionRules, error) { | ||
vr := &VersionRules{ |
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.
This should be moved down to where it's used.
minVersionStr := v.Rules[(branchVersionMinorSum(v.BranchVersion, -2))].Min | ||
maxVersionStr := v.Rules[v.BranchVersion].Max | ||
|
||
var err 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.
Error doesn't need and shouldn't be predeclared.
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 this case, I need it. Otherwise, I will get an error saying that the min
and max
variables are declared and not used.
@briandowns
pkg/lifecycle/version_rules.go
Outdated
|
||
// CheckForRCVersion checks if the chart version contains the "-rc" string indicating a release candidate version. | ||
func (v *VersionRules) CheckForRCVersion(chartVersion string) bool { | ||
if strings.Contains(strings.ToLower(chartVersion), "-rc") { |
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.
This can be simplified to:
return strings.Contains(strings.ToLower(chartVersion), "-rc")
29386bf
to
3d2beb5
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!
a2684b8
to
c35c119
Compare
enforce-lifecycle
command, since it was used only once with several limitations due to not all charts following the chart versioning standards.10
...)