Skip to content
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

Merged
merged 16 commits into from
Sep 6, 2024

Conversation

nicholasSUSE
Copy link
Collaborator

@nicholasSUSE nicholasSUSE commented Sep 3, 2024

  • Refactoring the code
  • Removing debug feature
  • Removing enforce-lifecycle command, since it was used only once with several limitations due to not all charts following the chart versioning standards.
  • Improved versioning calculations for version rules to adapt to the new charts versions (i.e: 2.7; 2.8; 2.9; 2.10...)
  • Updating packages
  • Adding new unit-tests

@nicholasSUSE nicholasSUSE requested a review from a team as a code owner September 3, 2024 20:03
)

var (
errorChartRepository error = errors.New("chart repository is in an inconsistent state")

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 Show resolved Hide resolved
// Commit after each chart removal.
removedAssetsVersions, err := ld.removeAssetsVersions(debug)
if !exists {
return errorChartRepository

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.

Copy link
Contributor

@rafaelbreno rafaelbreno Sep 3, 2024

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.

Copy link
Collaborator Author

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

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" ||

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.

Copy link
Collaborator Author

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


// loadFromJSON will load the version rules from version_rules.json file at charts repository
func loadFromJSON(fs billy.Filesystem) (*VersionRules, error) {
vr := &VersionRules{

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

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.

Copy link
Collaborator Author

@nicholasSUSE nicholasSUSE Sep 3, 2024

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


// 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") {

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")

go.mod Show resolved Hide resolved
pkg/lifecycle/version_rules.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rafaelbreno rafaelbreno left a comment

Choose a reason for hiding this comment

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

lgtm!

@nicholasSUSE nicholasSUSE merged commit acbf675 into rancher:master Sep 6, 2024
2 of 3 checks passed
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.

4 participants