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

Feature Implementation of Automatic forward port of asset versions, i.e: make auto-forward-port #138

Merged
merged 22 commits into from
Jul 5, 2024

Conversation

nicholasSUSE
Copy link
Collaborator

@nicholasSUSE nicholasSUSE commented Jun 27, 2024

Problem

Forward porting each asset version individually is an effortful manual work and prone to human error.

For each asset version, this was the manual process:

  1. Check if the asset version is not present at the production branch and present at development branch.

  2. Open a new local branch

  3. Clean release.yaml

  4. Add and commit.

  5. execute make forward-port

  6. Add and commit.

  7. Repeat it for every asset version and it's dependencies

  8. Push to a forked repository.

  9. Open a Pull Request to the target production branch.

  10. Review and approve PR.

  11. Monitor git-mirror.

Solution

Implement automation to reduce the amount of manual work and human intervention.
This solution automates the above mentioned steps: (1 -> 8)

Results

These are the automated pushes generated by this automation:

rancher/charts#4137
rancher/charts#4138
rancher/charts#4139
rancher/charts#4140
rancher/charts#4141
rancher/charts#4142
rancher/charts#4143
rancher/charts#4144
rancher/charts#4145
rancher/charts#4146
rancher/charts#4147
rancher/charts#4148
rancher/charts#4149
rancher/charts#4150
rancher/charts#4151
rancher/charts#4152
rancher/charts#4153
rancher/charts#4154
rancher/charts#4155
rancher/charts#4156
rancher/charts#4157
rancher/charts#4158
rancher/charts#4159
rancher/charts#4160

Returning *Status to be used by another package.
Updating references to version.rules.go at:
- status.go
- logs.go
- versions.rules_test.go
Removing old git.go inside pkg/lifecycle
… and releasing charts.

Created data structures and method for initializing dependencies.
receiving the status object from CheckLifecycleStatusAndSave(), parse the assetsToBeForwardPorted map,
into a slice of bash script commands.
Sort it alphabetically and by version.
…harts into PRs to be pushed later.

Rules:
- rancher-istio = 1 chart
- rancher-eks-operator + rancher-eks-operator-crd = 1 chart
- fleet + fleet-crd + fleet-agent = 1 chart
1 chart = 1 branch = 1 PR

checkChartCommonPrefixes is a more complex set of rules,
but basically it helps enforce the ones mentioned above, however
removing "rancher-" prefix which is very common among many charts,
but it does not mean that they are the same.
These are the core rules of this feature.
Steps of the manual process implemented by this automation:
1. Create a new branch from production branch
2. Clean release.yaml file
3. Add and commit
4. execute bash script: "make forward-port CHART=<chart> VERSION=<version> BRANCH=<dev branch> UPSTREAM=<remote_name>
5. Add and commit

6. Repeat it to all assets versions that belong to the same chart.

7. Push to forked repository

This code is not yet implementing the push to a forked repository, it will be implemented in the next commit.
@nicholasSUSE nicholasSUSE requested a review from a team as a code owner June 27, 2024 01:18
@recena
Copy link
Contributor

recena commented Jun 27, 2024

@nicholasSUSE You can use the DRAFT feature instead of [wip] prefix.

@@ -146,5 +146,5 @@ func (vr *VersionRules) CheckChartVersionToRelease(chartVersion string) (bool, e
logrus.Errorf("failed to check version to release for chartVersion:%s with error:%v", chartVersion, err)
return false, err
}
return chartVersionInt == (vr.maxVersion - 1), nil
return chartVersionInt == (vr.MaxVersion - 1), nil

Choose a reason for hiding this comment

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

The parenthesis aren't necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree it is not necessary.

I intentionally wrote this way for easier reading.
Can we keep this one?

pkg/auto/auto.go Outdated

// createForwardPortCommands will create the forward port script commands for each asset and version,
// and return a sorted slice of commands
func (fp *ForwardPort) createForwardPortCommands(chart string) ([]Command, error) {

Choose a reason for hiding this comment

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

Prefer using a single character for method receivers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing also for forward.port.go

pkg/auto/auto.go Outdated

upstreamRemote, ok := fp.git.Remotes["https://github.com/rancher/charts"]
if !ok {
logrus.Error("upstream remote not found; you need to have the upstream remote configured in your git repository (https://github.com/rancher/charts)")

Choose a reason for hiding this comment

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

This should be made into a value that can be printed here and returned below rather than being repeated.

var errUpstreamNotFound = errors.New("upstream remote not found; you need to have the upstream remote configured in your git repository (https://github.com/rancher/charts)")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing

pkg/auto/auto.go Outdated
func checkIfChartChanged(lastChart, currentChart string) bool {
// Check if the current chart is different from the last chart
sameCharts := (lastChart == currentChart)
if sameCharts {

Choose a reason for hiding this comment

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

This can be simplified: Remove line 113 and add the conditional check to line 114.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing

pkg/auto/auto.go Outdated
}

// Check for special edge cases
edgeCase := checkEdgeCasesIfChartChanged(lastChart, currentChart)

Choose a reason for hiding this comment

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

I think this can also be simplified as:

return !checkEdgeCasesIfChartChanged(lastChart, currentChart)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing

pkg/auto/auto.go Outdated
return true
}
if equalCounter == 1 && strings.HasPrefix("rancher-", lastParts[0]) &&
minLength < 3 {

Choose a reason for hiding this comment

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

Move tyhis up a line. Go doesn't care at all about line length, per Rob Pike.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing

pkg/auto/auto.go Outdated
return err
}
// create new branch and checkout
err = fp.git.CreateAndCheckoutBranch(branch)

Choose a reason for hiding this comment

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

Suggested change
err = fp.git.CreateAndCheckoutBranch(branch)
return fp.git.CreateAndCheckoutBranch(branch)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing

pkg/auto/auto.go Outdated
}

// File exists, open it with O_TRUNC to erase its content
file, err := os.OpenFile("release.yaml", os.O_WRONLY|os.O_TRUNC, 0644)

Choose a reason for hiding this comment

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

Suggested change
file, err := os.OpenFile("release.yaml", os.O_WRONLY|os.O_TRUNC, 0644)
if err := os.Truncate("release.yaml, 0); err != nil {
return err
}

The defer can be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wooow, did not know that.
Fixing.

@@ -0,0 +1,161 @@
package auto

Choose a reason for hiding this comment

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

This file isn't named according to Go standards. Replace the first . with an _. And do this for any other file names similarly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing.

main.go Outdated
@@ -43,6 +44,8 @@ const (
DefaultDebugEnvironmentVariable = "DEBUG"
// DefaultBranchVersionEnvironmentVariable is the default environment variable that indicates the branch version to compare against
DefaultBranchVersionEnvironmentVariable = "BRANCH_VERSION"
// DefaultForkEnvironmentVariable is the default environment variable that indicates the fork URL
Copy link

@briandowns briandowns Jul 2, 2024

Choose a reason for hiding this comment

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

None of these need to be exported since they can't be imported from main. Same for the new variable below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing

main.go Outdated
func autoForwardPort(c *cli.Context) {

if ForkURL == "" {
logrus.Fatalf("FORK environment variable must be set to run auto-forward-port")

Choose a reason for hiding this comment

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

Suggested change
logrus.Fatalf("FORK environment variable must be set to run auto-forward-port")
logrus.Fatal("FORK environment variable must be set to run auto-forward-port")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing

main.go Show resolved Hide resolved
@nicholasSUSE nicholasSUSE requested a review from briandowns July 3, 2024 20:22
@@ -71,6 +74,8 @@ var (
CacheMode = false

Choose a reason for hiding this comment

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

In another pr this should be updated to match the ones above using the 0 value declaration rather than this declaration to false. The 0 value for bools is false but moreover like code should be consistent. Which means the new variable below should be defined as type string since the 0 value for string is "".

Choose a reason for hiding this comment

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

Will also need to be unexported.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I created this issue so we don't lose track of this technical debt.
See if you agree please.

rancher/ecm-distro-tools#438

func prepareReleaseYaml() error {
// Check if the file exists
_, err := os.Stat("release.yaml")
if os.IsNotExist(err) {

Choose a reason for hiding this comment

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

The nil check on err should always be done first and if it's not nil, then inside that scope further error checking/handling should occur.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing

return false // Remote URL is empty
}
urlPart1, urlPart2 := extractCommonParts(upstreamURL, remoteURL)
return (urlPart1 == "https://github.com" && urlPart2 == repo)

Choose a reason for hiding this comment

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

Suggested change
return (urlPart1 == "https://github.com" && urlPart2 == repo)
return urlPart1 == "https://github.com" && urlPart2 == repo

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing

@nicholasSUSE nicholasSUSE requested a review from briandowns July 3, 2024 23:54
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.

3 participants