-
Notifications
You must be signed in to change notification settings - Fork 37
Make lifecycle assets #132
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
Make lifecycle assets #132
Conversation
…ing to the lifecycle and unit-tests
e0c9c9b to
df8812b
Compare
It will load the filesystem, index.yaml, check necessary paths, parse information from index.yaml file and check git tree. Creating also parser.go which role will be parsing and converting information to a standard that is easier to work and debug. Creating also git.go with a check for the git tree status
…aml, check assets folder versions And later will execute the make remove for each asset version and commit the changes. The checking and populating the map of the assets folder versions are updated on parser.go.
Updating git.go with gitAddAndCommit
60bddef to
afd9d47
Compare
afd9d47 to
e337f5d
Compare
e337f5d to
bac6d4e
Compare
main.go
Outdated
| // DefaultCacheEnvironmentVariable is the default environment variable that indicates that a cache should be used on pulls to remotes | ||
| DefaultCacheEnvironmentVariable = "USE_CACHE" | ||
| // DefaultDebugEnvironeventVariable is the default environment variable that indicates that debug mode should be enabled | ||
| DefaultDebugEnvironeventVariable = "DEBUG" |
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.
DefaultDebugEnvironmentVariable
main.go
Outdated
| Name: "debugFlag", | ||
| Usage: "Enable debug mode", | ||
| Destination: &DebugMode, | ||
| EnvVar: DefaultDebugEnvironeventVariable, |
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.
DefaultDebugEnvironmentVariable
| // Check if the assets folder and Helm index file exists in the repository | ||
| exists, err := filesystem.PathExists(dep.rootFs, path.RepositoryAssetsDir) | ||
| if err != nil || !exists { | ||
| return nil, fmt.Errorf("encountered error while checking if assets folder already exists in repository: %s", err) |
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.
If your condition is an OR, two cases might trigger the conditional.
err might not be null and the folder might not exist. There is no message for that.
pkg/lifecycle/lifecycle.go
Outdated
| return nil, fmt.Errorf("encountered error while checking if assets folder already exists in repository: %s", err) | ||
| } | ||
| exists, err = filesystem.PathExists(dep.rootFs, path.RepositoryHelmIndexFile) | ||
| if err != nil || !exists { |
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.
If your condition is an OR, two cases might trigger the conditional.
err might not be null and the file might not exist. There is no message for that.
pkg/lifecycle/lifecycle.go
Outdated
| } | ||
|
|
||
| // Git tree must be clean before proceeding with removing charts | ||
| clean, err := dep.checkIfGitIsCleanWrapper(debug) |
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.
Move this as the first step of the function. There is no need to run all that code if git is not clean at the beginning. That happens a lot with me while using the build-scripts
|
|
||
| // removeVersionsAssets will iterate through assetsVersionsMap and remove the versions that are not in the lifecycle commiting the changes | ||
| func (ld *Dependencies) removeVersionsAssets(debug bool) (map[string][]Asset, error) { | ||
| logrus.Info("Executing make remove") |
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.
IMO you should always check if git is clean first if your committing something later.
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 have already checked it before on InitDependencies
After that, there is nothing changing the local file system.
| _, err := dep.removeVersionsAssets(false) | ||
|
|
||
| // Assert | ||
| if err == 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.
The error message is not coherent with the conditional.
Conditional says err equals nil
pkg/lifecycle/lifecycle_test.go
Outdated
|
|
||
| // Assert | ||
| if err == nil { | ||
| t.Errorf("removeVersionsAssets returned an error: %v", err) |
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 message is not coherent with the conditional.
Conditional says err equals nil
pkg/lifecycle/lifecycle_test.go
Outdated
|
|
||
| // Assert | ||
| if err == nil { | ||
| t.Errorf("removeVersionsAssets returned an error: %v", err) |
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 message is not coherent with the conditional.
Conditional says err equals 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.
A general comment about test files. IMO you should check the objects being returned with assert in the success cases and the error messages in the failure cases.
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.
What you are suggesting is to use: "github.com/stretchr/testify/assert"
I am using the built-in "testing" package of go without 3rd party software.
The "testing" package does not have an assert method.
I prefer to use "github.com/stretchr/testify/assert" package when testing database and API calls that need to assert
big/complex objects and specific errors.
In this case, I did not want to use it because the objects are simple and most of the errors don't matter as long as they are errors failing on that specific condition.
I am trying not to over-engineer this.
Context
After discussing we all agreed that we would maintain a newer lifecycle for assets version on
chartsas stated in the documentation:New Assets Lifecycle
The new lifecycle will only be applied to prod-v2.9+
Problem
It is a huge number of versions and assets, the work would be manual and prone to human errors.
Solution
Develop a script on
charts-build-scriptsto receive the branch version, calculate the rules and automatically remove all assets versions that do not belong to the lifecycle.