Skip to content

Conversation

@nicholasSUSE
Copy link
Collaborator

@nicholasSUSE nicholasSUSE commented May 21, 2024

Context

After discussing we all agreed that we would maintain a newer lifecycle for assets version on charts as 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-scripts to receive the branch version, calculate the rules and automatically remove all assets versions that do not belong to the lifecycle.

@nicholasSUSE nicholasSUSE force-pushed the make-lifecycle-assets branch from e0c9c9b to df8812b Compare May 22, 2024 00:03
@nicholasSUSE nicholasSUSE requested a review from a team May 22, 2024 00:10
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.
@nicholasSUSE nicholasSUSE force-pushed the make-lifecycle-assets branch from 60bddef to afd9d47 Compare May 22, 2024 15:15
@nicholasSUSE nicholasSUSE changed the title Make lifecycle assets {WIP} Make lifecycle assets May 22, 2024
@nicholasSUSE nicholasSUSE marked this pull request as ready for review May 22, 2024 15:32
@nicholasSUSE nicholasSUSE force-pushed the make-lifecycle-assets branch from afd9d47 to e337f5d Compare May 22, 2024 20:21
@nicholasSUSE nicholasSUSE force-pushed the make-lifecycle-assets branch from e337f5d to bac6d4e Compare May 22, 2024 20:46
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"
Copy link
Contributor

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,
Copy link
Contributor

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)
Copy link
Contributor

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.

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 {
Copy link
Contributor

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.

}

// Git tree must be clean before proceeding with removing charts
clean, err := dep.checkIfGitIsCleanWrapper(debug)
Copy link
Contributor

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")
Copy link
Contributor

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.

Copy link
Collaborator Author

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 {
Copy link
Contributor

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


// Assert
if err == nil {
t.Errorf("removeVersionsAssets returned an error: %v", err)
Copy link
Contributor

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


// Assert
if err == nil {
t.Errorf("removeVersionsAssets returned an error: %v", err)
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

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.

2 participants